From 7a4d4568f91feb523d589322f1616235fac5f168 Mon Sep 17 00:00:00 2001 From: okatu-loli Date: Thu, 23 Oct 2025 18:21:17 +0800 Subject: [PATCH] feat(driver): Implement automatic root folder ID retrieval - Add `userInfoURL` constant for fetching user information. - Implement `ensureRootFolderID` function to retrieve and set the driver's root folder ID if not already present. - Integrate `ensureRootFolderID` into the driver's `Init` process. - Define `UserInfoData` struct to parse the `rootDirId` from user information responses. --- drivers/bitqiu/driver.go | 27 +++++++++++++++++++++++++++ drivers/bitqiu/types.go | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/drivers/bitqiu/driver.go b/drivers/bitqiu/driver.go index 0463d8a1..3aff8153 100644 --- a/drivers/bitqiu/driver.go +++ b/drivers/bitqiu/driver.go @@ -24,6 +24,7 @@ import ( const ( baseURL = "https://pan.bitqiu.com" loginURL = baseURL + "/loginServer/login" + userInfoURL = baseURL + "/user/getInfo" listURL = baseURL + "/apiToken/cfi/fs/resources/pages" uploadInitializeURL = baseURL + "/apiToken/cfi/fs/upload/v2/initialize" uploadCompleteURL = baseURL + "/apiToken/cfi/fs/upload/v2/complete" @@ -578,6 +579,32 @@ func (d *BitQiu) login(ctx context.Context) error { return fmt.Errorf("login failed: %s", resp.Message) } d.userID = strconv.FormatInt(resp.Data.UserID, 10) + return d.ensureRootFolderID(ctx) +} + +func (d *BitQiu) ensureRootFolderID(ctx context.Context) error { + rootID := d.Addition.GetRootId() + if rootID != "" && rootID != "0" { + return nil + } + + form := map[string]string{ + "org_channel": orgChannel, + } + var resp Response[UserInfoData] + if err := d.postForm(ctx, userInfoURL, form, &resp); err != nil { + return err + } + if resp.Code != successCode { + return fmt.Errorf("get user info failed: %s", resp.Message) + } + if resp.Data.RootDirID == "" { + return fmt.Errorf("get user info failed: empty root dir id") + } + if d.Addition.RootFolderID != resp.Data.RootDirID { + d.Addition.RootFolderID = resp.Data.RootDirID + op.MustSaveDriverStorage(d) + } return nil } diff --git a/drivers/bitqiu/types.go b/drivers/bitqiu/types.go index 4833c16f..8fbec989 100644 --- a/drivers/bitqiu/types.go +++ b/drivers/bitqiu/types.go @@ -40,6 +40,10 @@ type DownloadData struct { Size int64 `json:"size"` } +type UserInfoData struct { + RootDirID string `json:"rootDirId"` +} + type CreateDirData struct { DirID string `json:"dirId"` Name string `json:"name"`