This commit is contained in:
parent
67be27aebe
commit
c813c4784a
5 changed files with 145 additions and 12 deletions
|
@ -3,6 +3,9 @@ package media
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"git.mstar.dev/mstar/goutils/other"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -27,18 +30,23 @@ func (s *Server) AddFile(fileReader io.Reader, filename, userId string) error {
|
|||
}
|
||||
_ = file.Close()
|
||||
if s.transcoderClient == nil {
|
||||
return s.addFileAsIs(filename, userId, filePath)
|
||||
return s.addFileAsIs(filename, userId, filePath, nil)
|
||||
} else {
|
||||
return s.addFileWithTranscoder(filename, userId, filePath)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) addFileWithTranscoder(filename, userId, filepath string) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (s *Server) addFileAsIs(filename, userId, filepath string) error {
|
||||
_, err := s.client.FPutObject(
|
||||
// adFileAsIs uploads the given file. If mtype (short for mimetype, shortened because of module naming conflict)
|
||||
// is not nil, use that as the file's mimetype. Otherwise, the mimetype will be detected manually
|
||||
func (s *Server) addFileAsIs(filename, userId, filepath string, mtype *string) error {
|
||||
if mtype == nil {
|
||||
mType, err := mimetype.DetectFile(filepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mtype = other.IntoPointer(mType.String())
|
||||
}
|
||||
s3Result, err := s.client.FPutObject(
|
||||
context.TODO(),
|
||||
config.GlobalConfig.S3.BucketName,
|
||||
UsernameFilename(userId, filename),
|
||||
|
@ -52,7 +60,15 @@ func (s *Server) addFileAsIs(filename, userId, filepath string) error {
|
|||
ID: shared.NewId(),
|
||||
OwnedById: sql.NullString{Valid: true, String: userId},
|
||||
Remote: false,
|
||||
// Location: string, // TODO: Figure this out
|
||||
Location: s3Result.Location,
|
||||
Type: *mtype,
|
||||
Name: UsernameFilename(userId, filename),
|
||||
AltText: "",
|
||||
Blurred: false,
|
||||
}
|
||||
panic("not implemented")
|
||||
err = dbgen.MediaMetadata.Create(&fileMetadata)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue