Skip to content

Commit

Permalink
Add mimeTypeFromDestination to server config (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed May 19, 2024
1 parent 3d9cf40 commit 53cac41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/ffmpeg/scyllaridae.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mimeTypeFromDestination: true
allowedMimeTypes:
- "audio/*"
- "video/*"
Expand Down
16 changes: 13 additions & 3 deletions internal/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ type ServerConfig struct {
//
// required: false
CmdByMimeType map[string]Command `yaml:"cmdByMimeType"`

// Commands and arguments ran by MIME type based on the destination file format
//
// required: false
MimeTypeFromDestination bool `yaml:"mimeTypeFromDestination,omitempty"`
}

// Command describes the command and arguments to execute for a specific MIME type.
Expand Down Expand Up @@ -116,11 +121,16 @@ func ReadConfig(yp string) (*ServerConfig, error) {
}

func BuildExecCommand(message api.Payload, c *ServerConfig) (*exec.Cmd, error) {
if message.Attachment.Content.SourceMimeType != "" && !IsAllowedMimeType(message.Attachment.Content.SourceMimeType, c.AllowedMimeTypes) {
return nil, fmt.Errorf("undefined sourceMimeType: %s", message.Attachment.Content.SourceMimeType)
mimeType := message.Attachment.Content.SourceMimeType
if c.MimeTypeFromDestination {
mimeType = message.Attachment.Content.DestinationMimeType
}

if mimeType != "" && !IsAllowedMimeType(mimeType, c.AllowedMimeTypes) {
return nil, fmt.Errorf("undefined mimeType to build command: %s", mimeType)
}

cmdConfig, exists := c.CmdByMimeType[message.Attachment.Content.SourceMimeType]
cmdConfig, exists := c.CmdByMimeType[mimeType]
if !exists {
cmdConfig = c.CmdByMimeType["default"]
}
Expand Down

0 comments on commit 53cac41

Please sign in to comment.