Skip to content

Commit 7071539

Browse files
committed
feat(doubao_new): replace hardcoded Doubao parameters with dynamic values
Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent 947bae6 commit 7071539

3 files changed

Lines changed: 22 additions & 19 deletions

File tree

drivers/doubao_new/auth.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ import (
2626
const (
2727
defaultAuthRefreshAheadSeconds = int64(120)
2828
defaultDpopRefreshAheadSeconds = int64(5)
29-
doubaoBizAuthClientID = "cli_a872ee858eae100e"
30-
doubaoBizAuthClientType = "Lark"
31-
doubaoBizAuthScope = "internal"
32-
doubaoBizAuthAid = "497858"
33-
doubaoBizAuthSDKSource = "web"
34-
doubaoBizAuthSDKVersion = "2.2.11-doubao.0"
3529
)
3630

3731
type Clock interface {
@@ -421,14 +415,14 @@ func (d *DoubaoNew) fetchBizAuth(dpop string) (string, error) {
421415
req.SetHeader("dpop", dpop)
422416
}
423417
values := url.Values{}
424-
values.Set("client_id", doubaoBizAuthClientID)
425-
values.Set("client_type", doubaoBizAuthClientType)
426-
values.Set("scope", doubaoBizAuthScope)
418+
values.Set("client_id", d.AuthClientID)
419+
values.Set("client_type", d.AuthClientType)
420+
values.Set("scope", d.AuthScope)
427421
values.Set("d_pop", dpop)
428422
req.SetBody(values.Encode())
429-
req.SetQueryParam("aid", doubaoBizAuthAid)
430-
req.SetQueryParam("account_sdk_source", doubaoBizAuthSDKSource)
431-
req.SetQueryParam("sdk_version", doubaoBizAuthSDKVersion)
423+
req.SetQueryParam("aid", d.AppID)
424+
req.SetQueryParam("account_sdk_source", d.AuthSDKSource)
425+
req.SetQueryParam("sdk_version", d.AuthSDKVersion)
432426

433427
res, err := req.Post(DoubaoURL + "/passport/user/biz_auth/")
434428
if err != nil {
@@ -489,7 +483,10 @@ func (d *DoubaoNew) resolveAuthorizationForRequest(method, rawURL string) (strin
489483
// 刷新 Authorization Token 的前置条件:
490484
// 1. DPoP 密钥对
491485
// 2. Cookie
492-
if d.DpopKeyPair == nil || strings.TrimSpace(d.Cookie) == "" {
486+
// 3. AuthClientID、AuthClientType、AuthScope、AuthSDKSource、AuthSDKVersion
487+
if d.DpopKeyPair == nil || strings.TrimSpace(d.Cookie) == "" ||
488+
d.AuthClientID == "" || d.AuthClientType == "" || d.AuthScope == "" ||
489+
d.AuthSDKSource == "" || d.AuthSDKVersion == "" {
493490
return d.resolveAuthorization(), nil
494491
}
495492

drivers/doubao_new/meta.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ type Addition struct {
99
// Usually one of two
1010
driver.RootID
1111
// define other
12-
Cookie string `json:"cookie" required:"true" help:"Web Cookie"`
12+
Cookie string `json:"cookie" required:"true" help:"Web Cookie"`
13+
AppID string `json:"app_id" required:"true" default:"497858" help:"Doubao App ID"`
14+
AuthClientID string `json:"auth_client_id" help:"Doubao Biz Auth Client ID"`
15+
AuthClientType string `json:"auth_client_type" help:"Doubao Biz Auth Client Type"`
16+
AuthScope string `json:"auth_scope" help:"Doubao Biz Auth Scope"`
17+
AuthSDKSource string `json:"auth_sdk_source" help:"Doubao Biz Auth SDK Source"`
18+
AuthSDKVersion string `json:"auth_sdk_version" help:"Doubao Biz Auth SDK Version"`
1319
}
1420

1521
var config = driver.Config{

drivers/doubao_new/upload.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (d *DoubaoNew) prepareUpload(ctx context.Context, name string, size int64,
2121
values := url.Values{}
2222
values.Set("shouldBypassScsDialog", "true")
2323
values.Set("doubao_storage", "imagex_other")
24-
values.Set("doubao_app_id", doubaoBizAuthAid)
24+
values.Set("doubao_app_id", d.AppID)
2525
req.SetQueryParamsFromValues(values)
2626
req.SetHeader("Content-Type", "application/json")
2727
req.SetHeader("x-command", "space.api.box.upload.prepare")
@@ -58,7 +58,7 @@ func (d *DoubaoNew) uploadBlocks(ctx context.Context, uploadID string, blocks []
5858
values := url.Values{}
5959
values.Set("shouldBypassScsDialog", "true")
6060
values.Set("doubao_storage", "imagex_other")
61-
values.Set("doubao_app_id", doubaoBizAuthAid)
61+
values.Set("doubao_app_id", d.AppID)
6262
req.SetQueryParamsFromValues(values)
6363
req.SetHeader("Content-Type", "application/json")
6464
req.SetHeader("x-command", "space.api.box.upload.blocks")
@@ -128,7 +128,7 @@ func (d *DoubaoNew) mergeUploadBlocks(ctx context.Context, uploadID string, seqL
128128
values.Set("upload_id", uploadID)
129129
values.Set("mount_point", "explorer")
130130
values.Set("doubao_storage", "imagex_other")
131-
values.Set("doubao_app_id", doubaoBizAuthAid)
131+
values.Set("doubao_app_id", d.AppID)
132132
urlStr := DownloadBaseURL + "/space/api/box/stream/upload/merge_block/?" + values.Encode()
133133
if err := d.applyAuthHeaders(req, http.MethodPost, urlStr); err != nil {
134134
return UploadMergeData{}, err
@@ -228,7 +228,7 @@ func (d *DoubaoNew) uploadBlockV3(ctx context.Context, uploadID string, block Up
228228
values.Set("checksum", block.Checksum)
229229
values.Set("mount_point", "explorer")
230230
values.Set("doubao_storage", "imagex_other")
231-
values.Set("doubao_app_id", doubaoBizAuthAid)
231+
values.Set("doubao_app_id", d.AppID)
232232
urlStr := DownloadBaseURL + "/space/api/box/stream/upload/v3/block/?" + values.Encode()
233233
if err := d.applyAuthHeaders(req, http.MethodPost, urlStr); err != nil {
234234
return err
@@ -260,7 +260,7 @@ func (d *DoubaoNew) finishUpload(ctx context.Context, uploadID string, numBlocks
260260
values := url.Values{}
261261
values.Set("shouldBypassScsDialog", "true")
262262
values.Set("doubao_storage", "imagex_other")
263-
values.Set("doubao_app_id", doubaoBizAuthAid)
263+
values.Set("doubao_app_id", d.AppID)
264264
req.SetQueryParamsFromValues(values)
265265
req.SetHeader("Content-Type", "application/json")
266266
req.SetHeader("x-command", "space.api.box.upload.finish")

0 commit comments

Comments
 (0)