Skip to content

Commit e79839e

Browse files
committed
fix: 在和相册请求中添加上下文参数以支持取消操作
Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent 1c16cc8 commit e79839e

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

drivers/139/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ func (d *Yun139) Rename(ctx context.Context, srcObj model.Obj, newName string) e
428428
"path": path.Join(srcObj.GetPath(), srcObj.GetID()),
429429
}
430430
var resp ModifyCloudDocV2Resp
431-
_, err = d.andAlbumRequest(pathname, data, &resp)
431+
_, err = d.andAlbumRequest(ctx, pathname, data, &resp)
432432
if err != nil {
433433
return err
434434
}
@@ -516,7 +516,7 @@ func (d *Yun139) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
516516
}
517517

518518
var resp base.Json // Assuming a generic JSON response for success/failure
519-
_, err = d.andAlbumRequest(pathname, body, &resp)
519+
_, err = d.andAlbumRequest(ctx, pathname, body, &resp)
520520
// For now, we assume no error means success.
521521
default:
522522
err = errs.NotImplement

drivers/139/util.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ func sortedJsonStringify(obj interface{}) (string, error) {
10671067
}
10681068

10691069
// yun139EncryptedRequest handles the common encrypted request/response flow.
1070-
func (d *Yun139) yun139EncryptedRequest(url string, body interface{}, headers map[string]string, aesKeyHex string, resp interface{}) ([]byte, error) {
1070+
func (d *Yun139) yun139EncryptedRequest(ctx context.Context, url string, body interface{}, headers map[string]string, aesKeyHex string, resp interface{}) ([]byte, error) {
10711071
// 1. Decode AES key
10721072
aesKey, err := hex.DecodeString(aesKeyHex)
10731073
if err != nil {
@@ -1094,6 +1094,7 @@ func (d *Yun139) yun139EncryptedRequest(url string, body interface{}, headers ma
10941094

10951095
// 4. Make the request
10961096
res, err := base.RestyClient.R().
1097+
SetContext(ctx).
10971098
SetHeaders(headers).
10981099
SetBody(payload).
10991100
Post(url)
@@ -1177,7 +1178,7 @@ func (d *Yun139) step3_third_party_login(dycpwd string) (string, error) {
11771178
}
11781179

11791180
// 使用通用加密请求函数
1180-
decryptedLayer1StrBytes, err := d.yun139EncryptedRequest(ssoLoginURL, ssoRequestBodyRaw, ssoLoginHeaders, KEY_HEX_1, nil)
1181+
decryptedLayer1StrBytes, err := d.yun139EncryptedRequest(context.TODO(), ssoLoginURL, ssoRequestBodyRaw, ssoLoginHeaders, KEY_HEX_1, nil)
11811182
if err != nil {
11821183
return "", fmt.Errorf("step3 encrypted request failed: %w", err)
11831184
}
@@ -1251,7 +1252,7 @@ func (d *Yun139) loginWithPassword() (string, error) {
12511252
return newAuth, nil
12521253
}
12531254

1254-
func (d *Yun139) andAlbumRequest(pathname string, body interface{}, resp interface{}) ([]byte, error) {
1255+
func (d *Yun139) andAlbumRequest(ctx context.Context, pathname string, body interface{}, resp interface{}) ([]byte, error) {
12551256
url := "https://group.yun.139.com/hcy/family/adapter/andAlbum/openApi" + pathname
12561257

12571258
headers := map[string]string{
@@ -1269,7 +1270,7 @@ func (d *Yun139) andAlbumRequest(pathname string, body interface{}, resp interfa
12691270
"accept-encoding": "gzip",
12701271
}
12711272

1272-
return d.yun139EncryptedRequest(url, body, headers, KEY_HEX_1, resp)
1273+
return d.yun139EncryptedRequest(ctx, url, body, headers, KEY_HEX_1, resp)
12731274
}
12741275

12751276
func (d *Yun139) handleMetaGroupCopy(ctx context.Context, srcObj, dstDir model.Obj) error {
@@ -1298,7 +1299,7 @@ func (d *Yun139) handleMetaGroupCopy(ctx context.Context, srcObj, dstDir model.O
12981299
}
12991300

13001301
var resp base.Json
1301-
_, err := d.andAlbumRequest(pathname, body, &resp)
1302+
_, err := d.andAlbumRequest(ctx, pathname, body, &resp)
13021303
return err
13031304
}
13041305

0 commit comments

Comments
 (0)