45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package media
|
|
|
|
import (
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"git.mstar.dev/mstar/linstrom/config"
|
|
)
|
|
|
|
// WARN: These types need to always be in sync with linstrom-transcoder/transcode/transcoder.go
|
|
// TODO: Maybe move to a separate repo outside of linstrom-transcoder
|
|
|
|
type TranscodeArgs struct {
|
|
Secret string
|
|
Filename string
|
|
}
|
|
|
|
type TranscodeReply struct {
|
|
Error error
|
|
Mimetype string
|
|
ThumbnailFilename *string
|
|
Filename string
|
|
}
|
|
|
|
// addFileWithTranscoder will try to transcode the given file using the helper application.
|
|
// If the transcode fails, it uploads the file as is
|
|
func (s *Server) addFileWithTranscoder(
|
|
filename, userId, filepath string,
|
|
blurred bool,
|
|
altText string,
|
|
) (string, error) {
|
|
args := TranscodeArgs{
|
|
Secret: config.GlobalConfig.Transcoder.Secret,
|
|
Filename: filepath,
|
|
}
|
|
reply := TranscodeReply{}
|
|
err := s.transcoderClient.Call("Transcoder.Transcode", &args, &reply)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if reply.Error != nil {
|
|
log.Warn().Err(reply.Error).Msg("Transcoder failed, uploading raw file")
|
|
return s.addFileAsIs(filename, userId, filepath, nil, blurred, altText)
|
|
}
|
|
return s.addFileAsIs(filename, userId, reply.Filename, &reply.Mimetype, blurred, altText)
|
|
}
|