Add more things for file handling
This commit is contained in:
parent
c813c4784a
commit
1fcf47bffc
14 changed files with 284 additions and 59 deletions
|
@ -3,11 +3,11 @@ package media
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
"net/rpc"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/config"
|
||||
)
|
||||
|
@ -21,6 +21,8 @@ var (
|
|||
ErrNoBucketAccess = errors.New("can't access configured bucket")
|
||||
)
|
||||
|
||||
var GlobalServer *Server
|
||||
|
||||
func NewServer() (*Server, error) {
|
||||
client, err := minio.New(config.GlobalConfig.S3.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(
|
||||
|
@ -51,6 +53,9 @@ func NewServer() (*Server, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if config.GlobalConfig.Transcoder.IgnoreTranscoder {
|
||||
return &Server{client: client, transcoderClient: nil}, nil
|
||||
}
|
||||
transcoderClient, err := rpc.DialHTTP("tcp", config.GlobalConfig.Transcoder.Address())
|
||||
if err != nil {
|
||||
log.Warn().Err(err).
|
||||
|
@ -60,22 +65,3 @@ func NewServer() (*Server, error) {
|
|||
}
|
||||
return &Server{client: client, transcoderClient: transcoderClient}, nil
|
||||
}
|
||||
|
||||
// UsernameFilename converts a userId and filename into a proper filepath for s3.
|
||||
// Reason for this is that the userId for external users is a valid url which needs to be encoded
|
||||
func UsernameFilename(userId, filename string) string {
|
||||
return userId + "//" + filename
|
||||
}
|
||||
|
||||
func (s *Server) HasFileScoped(userId, filename string) (bool, error) {
|
||||
info, err := s.client.StatObject(
|
||||
context.Background(),
|
||||
config.GlobalConfig.S3.BucketName,
|
||||
UsernameFilename(userId, filename),
|
||||
minio.GetObjectOptions{},
|
||||
)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return info.IsDeleteMarker, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue