Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/openlist/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func (d *OpenList) ArchiveDecompress(ctx context.Context, srcObj, dstDir model.O
Name: []string{name},
PutIntoNewDir: args.PutIntoNewDir,
SrcDir: dir,
Overwrite: args.Overwrite,
})
})
return err
Expand Down
1 change: 1 addition & 0 deletions drivers/openlist/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,5 @@ type DecompressReq struct {
Name []string `json:"name"`
PutIntoNewDir bool `json:"put_into_new_dir"`
SrcDir string `json:"src_dir"`
Overwrite bool `json:"overwrite"`
}
1 change: 1 addition & 0 deletions drivers/url_tree/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var config = driver.Config{
LocalSort: true,
NoCache: true,
CheckStatus: true,
OnlyIndices: true,
}

func init() {
Expand Down
2 changes: 2 additions & 0 deletions internal/driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Config struct {
// - LinkCacheNone: no extra info added to cache key (default)
// - flags (OR-able) can add more attributes to cache key (IP, UA, ...)
LinkCacheMode `json:"-"`
// if the driver only store indices of files (e.g. UrlTree)
OnlyIndices bool `json:"only_indices"`
}
type LinkCacheMode int8

Expand Down
9 changes: 9 additions & 0 deletions internal/fs/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (t *ArchiveDownloadTask) RunWithoutPushUploadTask() (*ArchiveContentUploadT
DstActualPath: t.DstActualPath,
dstStorage: t.DstStorage,
DstStorageMp: t.DstStorageMp,
overwrite: t.Overwrite,
}
return uploadTask, nil
}
Expand All @@ -142,6 +143,7 @@ type ArchiveContentUploadTask struct {
DstStorageMp string
finalized bool
groupID string
overwrite bool
}

func (t *ArchiveContentUploadTask) GetName() string {
Expand Down Expand Up @@ -232,6 +234,7 @@ func (t *ArchiveContentUploadTask) RunWithNextTaskCallback(f func(nextTask *Arch
dstStorage: t.dstStorage,
DstStorageMp: t.DstStorageMp,
groupID: t.groupID,
overwrite: t.overwrite,
})
if err != nil {
es = stderrors.Join(es, err)
Expand All @@ -241,6 +244,12 @@ func (t *ArchiveContentUploadTask) RunWithNextTaskCallback(f func(nextTask *Arch
return es
}
} else {
if !t.overwrite {
dstPath := stdpath.Join(t.DstActualPath, t.ObjName)
if res, _ := op.Get(t.Ctx(), t.dstStorage, dstPath); res != nil {
return errs.ObjectAlreadyExists
}
}
file, err := os.Open(t.FilePath)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions internal/model/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type ArchiveDecompressArgs struct {
ArchiveInnerArgs
CacheFull bool
PutIntoNewDir bool
Overwrite bool
}

type SharingListArgs struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/op/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func Put(ctx context.Context, storage driver.Driver, dstDirPath string, file mod
return errors.WithMessagef(errs.StorageNotInit, "storage status: %s", storage.GetStorage().Status)
}
// UrlTree PUT
if storage.GetStorage().Driver == "UrlTree" {
if storage.Config().OnlyIndices {
var link string
dstDirPath, link = urlTreeSplitLineFormPath(stdpath.Join(dstDirPath, file.GetName()))
file = &stream.FileStream{Obj: &model.Object{Name: link}}
Expand Down
33 changes: 9 additions & 24 deletions server/handles/archive.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handles

import (
"encoding/json"
"fmt"
"io"
stdpath "path"
Expand Down Expand Up @@ -229,30 +228,15 @@ func FsArchiveList(c *gin.Context, req *ArchiveListReq, user *model.User) {
})
}

type StringOrArray []string

func (s *StringOrArray) UnmarshalJSON(data []byte) error {
var value string
if err := json.Unmarshal(data, &value); err == nil {
*s = []string{value}
return nil
}
var sliceValue []string
if err := json.Unmarshal(data, &sliceValue); err != nil {
return err
}
*s = sliceValue
return nil
}

type ArchiveDecompressReq struct {
SrcDir string `json:"src_dir" form:"src_dir"`
DstDir string `json:"dst_dir" form:"dst_dir"`
Name StringOrArray `json:"name" form:"name"`
ArchivePass string `json:"archive_pass" form:"archive_pass"`
InnerPath string `json:"inner_path" form:"inner_path"`
CacheFull bool `json:"cache_full" form:"cache_full"`
PutIntoNewDir bool `json:"put_into_new_dir" form:"put_into_new_dir"`
SrcDir string `json:"src_dir" form:"src_dir"`
DstDir string `json:"dst_dir" form:"dst_dir"`
Name []string `json:"name" form:"name"`
ArchivePass string `json:"archive_pass" form:"archive_pass"`
InnerPath string `json:"inner_path" form:"inner_path"`
CacheFull bool `json:"cache_full" form:"cache_full"`
PutIntoNewDir bool `json:"put_into_new_dir" form:"put_into_new_dir"`
Overwrite bool `json:"overwrite" form:"overwrite"`
}

func FsArchiveDecompress(c *gin.Context) {
Expand Down Expand Up @@ -295,6 +279,7 @@ func FsArchiveDecompress(c *gin.Context) {
},
CacheFull: req.CacheFull,
PutIntoNewDir: req.PutIntoNewDir,
Overwrite: req.Overwrite,
})
if e != nil {
if errors.Is(e, errs.WrongArchivePassword) {
Expand Down