Add media upload functionality
All checks were successful
/ docker (push) Successful in 1m54s

This commit is contained in:
Melody Becker 2025-06-17 16:48:24 +02:00
parent 67be27aebe
commit c813c4784a
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
5 changed files with 145 additions and 12 deletions

View file

@ -1 +1,40 @@
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)
}