Skip to content

Commit b054919

Browse files
authored
feat(ilanzou): add support for rapid upload and fix duplication handling (#1065)
* feat(ilanzou): add support for rapid upload token handling * feat(ilanzou): add NoOverwriteUpload option
1 parent 048ee9c commit b054919

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

drivers/ilanzou/driver.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,23 @@ func (d *ILanZou) Put(ctx context.Context, dstDir model.Obj, s model.FileStreame
296296
return nil, err
297297
}
298298
upToken := utils.Json.Get(res, "upToken").ToString()
299+
if upToken == "-1" {
300+
// 支持秒传
301+
var resp UploadTokenRapidResp
302+
err := utils.Json.Unmarshal(res, &resp)
303+
if err != nil {
304+
return nil, err
305+
}
306+
return &model.Object{
307+
ID: strconv.FormatInt(resp.Map.FileID, 10),
308+
Name: resp.Map.FileName,
309+
Size: s.GetSize(),
310+
Modified: s.ModTime(),
311+
Ctime: s.CreateTime(),
312+
IsFolder: false,
313+
HashInfo: utils.NewHashInfo(utils.MD5, etag),
314+
}, nil
315+
}
299316
now := time.Now()
300317
key := fmt.Sprintf("disk/%d/%d/%d/%s/%016d", now.Year(), now.Month(), now.Day(), d.account, now.UnixMilli())
301318
reader := driver.NewLimitedUploadStream(ctx, &driver.ReaderUpdatingProgress{

drivers/ilanzou/meta.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ func init() {
2929
op.RegisterDriver(func() driver.Driver {
3030
return &ILanZou{
3131
config: driver.Config{
32-
Name: "ILanZou",
33-
DefaultRoot: "0",
34-
LocalSort: true,
32+
Name: "ILanZou",
33+
DefaultRoot: "0",
34+
LocalSort: true,
35+
NoOverwriteUpload: true,
3536
},
3637
conf: Conf{
3738
base: "https://api.ilanzou.com",
@@ -47,9 +48,10 @@ func init() {
4748
op.RegisterDriver(func() driver.Driver {
4849
return &ILanZou{
4950
config: driver.Config{
50-
Name: "FeijiPan",
51-
DefaultRoot: "0",
52-
LocalSort: true,
51+
Name: "FeijiPan",
52+
DefaultRoot: "0",
53+
LocalSort: true,
54+
NoOverwriteUpload: true,
5355
},
5456
conf: Conf{
5557
base: "https://api.feijipan.com",

drivers/ilanzou/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ type Part struct {
4343
ETag string `json:"etag"`
4444
}
4545

46+
type UploadTokenRapidResp struct {
47+
Msg string `json:"msg"`
48+
Code int `json:"code"`
49+
UpToken string `json:"upToken"`
50+
Map struct {
51+
FileIconID int `json:"fileIconId"`
52+
FileName string `json:"fileName"`
53+
FileIcon string `json:"fileIcon"`
54+
FileID int64 `json:"fileId"`
55+
} `json:"map"`
56+
}
57+
4658
type UploadResultResp struct {
4759
Msg string `json:"msg"`
4860
Code int `json:"code"`

0 commit comments

Comments
 (0)