mirror of
https://github.com/get-drexa/drive.git
synced 2025-11-30 21:41:39 +00:00
fix: upload url generation
This commit is contained in:
@@ -16,8 +16,7 @@ type FSStore struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FSStoreConfig struct {
|
type FSStoreConfig struct {
|
||||||
Root string
|
Root string
|
||||||
UploadURL string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFSStore(config FSStoreConfig) *FSStore {
|
func NewFSStore(config FSStoreConfig) *FSStore {
|
||||||
@@ -28,10 +27,6 @@ func (s *FSStore) Initialize(ctx context.Context) error {
|
|||||||
return os.MkdirAll(s.config.Root, 0755)
|
return os.MkdirAll(s.config.Root, 0755)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FSStore) GenerateUploadURL(ctx context.Context, key Key, opts UploadURLOptions) (string, error) {
|
|
||||||
return s.config.UploadURL, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *FSStore) Put(ctx context.Context, key Key, reader io.Reader) error {
|
func (s *FSStore) Put(ctx context.Context, key Key, reader io.Reader) error {
|
||||||
path := filepath.Join(s.config.Root, string(key))
|
path := filepath.Join(s.config.Root, string(key))
|
||||||
|
|
||||||
@@ -149,3 +144,11 @@ func (s *FSStore) Move(ctx context.Context, srcKey, dstKey Key) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *FSStore) SupportsDirectUpload() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FSStore) GenerateUploadURL(ctx context.Context, key Key, opts UploadURLOptions) (string, error) {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ type UpdateOptions struct {
|
|||||||
|
|
||||||
type Store interface {
|
type Store interface {
|
||||||
Initialize(ctx context.Context) error
|
Initialize(ctx context.Context) error
|
||||||
GenerateUploadURL(ctx context.Context, key Key, opts UploadURLOptions) (string, error)
|
|
||||||
Put(ctx context.Context, key Key, reader io.Reader) error
|
Put(ctx context.Context, key Key, reader io.Reader) error
|
||||||
Update(ctx context.Context, key Key, opts UpdateOptions) error
|
Update(ctx context.Context, key Key, opts UpdateOptions) error
|
||||||
Delete(ctx context.Context, key Key) error
|
Delete(ctx context.Context, key Key) error
|
||||||
@@ -25,4 +24,10 @@ type Store interface {
|
|||||||
Read(ctx context.Context, key Key) (io.ReadCloser, error)
|
Read(ctx context.Context, key Key) (io.ReadCloser, error)
|
||||||
ReadRange(ctx context.Context, key Key, offset, length int64) (io.ReadCloser, error)
|
ReadRange(ctx context.Context, key Key, offset, length int64) (io.ReadCloser, error)
|
||||||
ReadSize(ctx context.Context, key Key) (int64, error)
|
ReadSize(ctx context.Context, key Key) (int64, error)
|
||||||
|
|
||||||
|
// SupportsDirectUpload returns true if the store allows files to be uploaded directly to the blob store.
|
||||||
|
SupportsDirectUpload() bool
|
||||||
|
|
||||||
|
// GenerateUploadURL generates a URL that can be used to upload a file directly to the blob store. If unsupported, returns an empty string with no error.
|
||||||
|
GenerateUploadURL(ctx context.Context, key Key, opts UploadURLOptions) (string, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,12 +58,17 @@ func (s *Service) CreateUpload(ctx context.Context, db bun.IDB, accountID uuid.U
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadURL, err := s.blobStore.GenerateUploadURL(ctx, node.BlobKey, blob.UploadURLOptions{
|
var uploadURL string
|
||||||
Duration: 1 * time.Hour,
|
if s.blobStore.SupportsDirectUpload() {
|
||||||
})
|
uploadURL, err = s.blobStore.GenerateUploadURL(ctx, node.BlobKey, blob.UploadURLOptions{
|
||||||
if err != nil {
|
Duration: 1 * time.Hour,
|
||||||
_ = s.vfs.PermanentlyDeleteNode(ctx, db, node)
|
})
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
_ = s.vfs.PermanentlyDeleteNode(ctx, db, node)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uploadURL = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
upload := &Upload{
|
upload := &Upload{
|
||||||
|
|||||||
Reference in New Issue
Block a user