58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package media
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"io"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/minio/minio-go/v7"
|
|
|
|
"git.mstar.dev/mstar/linstrom/config"
|
|
"git.mstar.dev/mstar/linstrom/shared"
|
|
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
|
)
|
|
|
|
func (s *Server) AddFile(fileReader io.Reader, filename, userId string) error {
|
|
transcoderInDir := config.GlobalConfig.Transcoder.InDir()
|
|
filePath := path.Join(transcoderInDir, filename)
|
|
file, err := os.Create(filePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, err = io.Copy(file, fileReader); err != nil {
|
|
_ = file.Close()
|
|
return err
|
|
}
|
|
_ = file.Close()
|
|
if s.transcoderClient == nil {
|
|
return s.addFileAsIs(filename, userId, filePath)
|
|
} 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(
|
|
context.TODO(),
|
|
config.GlobalConfig.S3.BucketName,
|
|
UsernameFilename(userId, filename),
|
|
filepath,
|
|
minio.PutObjectOptions{},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fileMetadata := models.MediaMetadata{
|
|
ID: shared.NewId(),
|
|
OwnedById: sql.NullString{Valid: true, String: userId},
|
|
Remote: false,
|
|
// Location: string, // TODO: Figure this out
|
|
}
|
|
panic("not implemented")
|
|
}
|