mirror of https://github.com/Xhofe/alist
feat(s3): create placeholder file for mkdir
parent
83c377270e
commit
49fc475f9f
|
@ -1,6 +1,7 @@
|
||||||
package s3
|
package s3
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
|
@ -9,6 +10,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/service/s3"
|
"github.com/aws/aws-sdk-go/service/s3"
|
||||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"io/ioutil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
@ -78,6 +80,7 @@ func (driver S3) Items() []base.Item {
|
||||||
Label: "placeholder filename",
|
Label: "placeholder filename",
|
||||||
Type: base.TypeString,
|
Type: base.TypeString,
|
||||||
Description: "default empty string",
|
Description: "default empty string",
|
||||||
|
Default: defaultPlaceholderName,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "bool_1",
|
Name: "bool_1",
|
||||||
|
@ -213,8 +216,19 @@ func (driver S3) Preview(path string, account *model.Account) (interface{}, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver S3) MakeDir(path string, account *model.Account) error {
|
func (driver S3) MakeDir(path string, account *model.Account) error {
|
||||||
// not support, default as success
|
// not support, generate a placeholder file
|
||||||
return nil
|
_, err := driver.File(path, account)
|
||||||
|
// exist
|
||||||
|
if err != base.ErrPathNotFound {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return driver.Upload(&model.FileStream{
|
||||||
|
File: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||||
|
Size: 0,
|
||||||
|
ParentPath: path,
|
||||||
|
Name: getPlaceholderName(account.Zone),
|
||||||
|
MIMEType: "application/octet-stream",
|
||||||
|
}, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver S3) Move(src string, dst string, account *model.Account) error {
|
func (driver S3) Move(src string, dst string, account *model.Account) error {
|
||||||
|
@ -277,6 +291,7 @@ func (driver S3) Upload(file *model.FileStream, account *model.Account) error {
|
||||||
}
|
}
|
||||||
uploader := s3manager.NewUploader(s)
|
uploader := s3manager.NewUploader(s)
|
||||||
key := driver.GetKey(utils.Join(file.ParentPath, file.GetFileName()), account, false)
|
key := driver.GetKey(utils.Join(file.ParentPath, file.GetFileName()), account, false)
|
||||||
|
log.Debugln("key:", key)
|
||||||
input := &s3manager.UploadInput{
|
input := &s3manager.UploadInput{
|
||||||
Bucket: &account.Bucket,
|
Bucket: &account.Bucket,
|
||||||
Key: &key,
|
Key: &key,
|
||||||
|
|
|
@ -88,7 +88,7 @@ func (driver S3) List(prefix string, account *model.Account) ([]model.File, erro
|
||||||
}
|
}
|
||||||
for _, object := range listObjectsResult.Contents {
|
for _, object := range listObjectsResult.Contents {
|
||||||
name := utils.Base(*object.Key)
|
name := utils.Base(*object.Key)
|
||||||
if name == account.Zone {
|
if name == getPlaceholderName(account.Zone) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
file := model.File{
|
file := model.File{
|
||||||
|
@ -152,7 +152,7 @@ func (driver S3) ListV2(prefix string, account *model.Account) ([]model.File, er
|
||||||
}
|
}
|
||||||
for _, object := range listObjectsResult.Contents {
|
for _, object := range listObjectsResult.Contents {
|
||||||
name := utils.Base(*object.Key)
|
name := utils.Base(*object.Key)
|
||||||
if name == account.Zone {
|
if name == getPlaceholderName(account.Zone) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
file := model.File{
|
file := model.File{
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package s3
|
||||||
|
|
||||||
|
var defaultPlaceholderName = ".placeholder"
|
||||||
|
|
||||||
|
func getPlaceholderName(placeholder string) string {
|
||||||
|
if placeholder == "" {
|
||||||
|
return defaultPlaceholderName
|
||||||
|
}
|
||||||
|
return placeholder
|
||||||
|
}
|
Loading…
Reference in New Issue