All checks were successful
/ docker (push) Successful in 1m56s
Also added two fields to roles model, but haven't ran the various generators yet
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package translators
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"git.mstar.dev/mstar/linstrom/config"
|
|
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
|
)
|
|
|
|
type Media struct {
|
|
Type string `json:"type"`
|
|
Url string `json:"url"`
|
|
MediaType string `json:"mediaType"`
|
|
Name string `json:"name"`
|
|
Summary string `json:"summary"`
|
|
Sensitive bool `json:"sensitive"`
|
|
}
|
|
|
|
func MediaFromStorage(ctx context.Context, id string) (*Media, error) {
|
|
metadata, err := dbgen.MediaMetadata.Where(dbgen.MediaMetadata.ID.Eq(id), dbgen.MediaMetadata.Remote.Is(false)).
|
|
First()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
data := Media{
|
|
MediaType: metadata.Type,
|
|
Url: config.GlobalConfig.General.GetFullPublicUrl() + "/media/" + id,
|
|
Name: metadata.AltText,
|
|
Summary: metadata.AltText,
|
|
Sensitive: metadata.Blurred,
|
|
}
|
|
switch strings.SplitN(metadata.Type, "/", 2)[0] {
|
|
case "audio":
|
|
data.Type = "Audio"
|
|
case "application":
|
|
data.Type = "Document"
|
|
case "image":
|
|
data.Type = "Image"
|
|
case "video":
|
|
data.Type = "Video"
|
|
case "text":
|
|
data.Type = "Document"
|
|
case "font":
|
|
data.Type = "Document"
|
|
default:
|
|
data.Type = "Document"
|
|
}
|
|
return &data, nil
|
|
}
|