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) }