linstrom/media/transcoder.go
mstar c813c4784a
All checks were successful
/ docker (push) Successful in 1m54s
Add media upload functionality
2025-06-17 16:48:24 +02:00

40 lines
1.1 KiB
Go

package media
import (
"git.mstar.dev/mstar/linstrom/config"
"github.com/rs/zerolog/log"
)
// 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) 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)
}
return s.addFileAsIs(filename, userId, reply.Filename, &reply.Mimetype)
}