mirror of
https://github.com/AlistGo/alist.git
synced 2025-12-18 18:30:10 +08:00
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.
This commit is contained in:
parent
6ba3dc9725
commit
7a4d4568f9
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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"`
|
||||
|
||||
Loading…
Reference in New Issue
Block a user