From 8188fb2d7d02f87e591289480f07e7a61e3ca5a5 Mon Sep 17 00:00:00 2001 From: MadDogOwner Date: Sun, 31 Aug 2025 15:47:38 +0800 Subject: [PATCH] fix(123open): get direct link (#1185) * fix(123open): correct query parameter name from 'fileId' to 'fileID' in getDirectLink function Signed-off-by: MadDogOwner * fix(123open): change SpaceTempExpr type from 'string' to 'int64' in UserInfoResp struct Signed-off-by: MadDogOwner * fix(123open): comment out unused fields in UserInfoResp struct Signed-off-by: MadDogOwner * fix(123open): add getUID method and cache UID Signed-off-by: MadDogOwner --------- Signed-off-by: MadDogOwner --- drivers/123_open/driver.go | 5 +++-- drivers/123_open/types.go | 26 +++++++++++++------------- drivers/123_open/util.go | 14 +++++++++++++- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/drivers/123_open/driver.go b/drivers/123_open/driver.go index 04785ac1..480d0f51 100644 --- a/drivers/123_open/driver.go +++ b/drivers/123_open/driver.go @@ -17,6 +17,7 @@ import ( type Open123 struct { model.Storage Addition + UID uint64 } func (d *Open123) Config() driver.Config { @@ -83,7 +84,7 @@ func (d *Open123) Link(ctx context.Context, file model.Obj, args model.LinkArgs) }, nil } - u, err := d.getUserInfo() + uid, err := d.getUID() if err != nil { return nil, err } @@ -91,7 +92,7 @@ func (d *Open123) Link(ctx context.Context, file model.Obj, args model.LinkArgs) duration := time.Duration(d.DirectLinkValidDuration) * time.Minute newURL, err := d.SignURL(res.Data.URL, d.DirectLinkPrivateKey, - u.Data.UID, duration) + uid, duration) if err != nil { return nil, err } diff --git a/drivers/123_open/types.go b/drivers/123_open/types.go index eb08529f..c1d64d2f 100644 --- a/drivers/123_open/types.go +++ b/drivers/123_open/types.go @@ -127,19 +127,19 @@ type RefreshTokenResp struct { type UserInfoResp struct { BaseResp Data struct { - UID uint64 `json:"uid"` - Username string `json:"username"` - DisplayName string `json:"displayName"` - HeadImage string `json:"headImage"` - Passport string `json:"passport"` - Mail string `json:"mail"` - SpaceUsed int64 `json:"spaceUsed"` - SpacePermanent int64 `json:"spacePermanent"` - SpaceTemp int64 `json:"spaceTemp"` - SpaceTempExpr string `json:"spaceTempExpr"` - Vip bool `json:"vip"` - DirectTraffic int64 `json:"directTraffic"` - IsHideUID bool `json:"isHideUID"` + UID uint64 `json:"uid"` + // Username string `json:"username"` + // DisplayName string `json:"displayName"` + // HeadImage string `json:"headImage"` + // Passport string `json:"passport"` + // Mail string `json:"mail"` + // SpaceUsed int64 `json:"spaceUsed"` + // SpacePermanent int64 `json:"spacePermanent"` + // SpaceTemp int64 `json:"spaceTemp"` + // SpaceTempExpr int64 `json:"spaceTempExpr"` + // Vip bool `json:"vip"` + // DirectTraffic int64 `json:"directTraffic"` + // IsHideUID bool `json:"isHideUID"` } `json:"data"` } diff --git a/drivers/123_open/util.go b/drivers/123_open/util.go index 146d21ba..841e6a16 100644 --- a/drivers/123_open/util.go +++ b/drivers/123_open/util.go @@ -158,6 +158,18 @@ func (d *Open123) getUserInfo() (*UserInfoResp, error) { return &resp, nil } +func (d *Open123) getUID() (uint64, error) { + if d.UID != 0 { + return d.UID, nil + } + resp, err := d.getUserInfo() + if err != nil { + return 0, err + } + d.UID = resp.Data.UID + return resp.Data.UID, nil +} + func (d *Open123) getFiles(parentFileId int64, limit int, lastFileId int64) (*FileListResp, error) { var resp FileListResp @@ -200,7 +212,7 @@ func (d *Open123) getDirectLink(fileId int64) (*DirectLinkResp, error) { _, err := d.Request(DirectLink, http.MethodGet, func(req *resty.Request) { req.SetQueryParams(map[string]string{ - "fileId": strconv.FormatInt(fileId, 10), + "fileID": strconv.FormatInt(fileId, 10), }) }, &resp) if err != nil {