mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-19 12:16:24 +08:00
fix(123open): get direct link (#1185)
* fix(123open): correct query parameter name from 'fileId' to 'fileID' in getDirectLink function Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * fix(123open): change SpaceTempExpr type from 'string' to 'int64' in UserInfoResp struct Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * fix(123open): comment out unused fields in UserInfoResp struct Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * fix(123open): add getUID method and cache UID Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> --------- Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
This commit is contained in:
@ -17,6 +17,7 @@ import (
|
|||||||
type Open123 struct {
|
type Open123 struct {
|
||||||
model.Storage
|
model.Storage
|
||||||
Addition
|
Addition
|
||||||
|
UID uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Open123) Config() driver.Config {
|
func (d *Open123) Config() driver.Config {
|
||||||
@ -83,7 +84,7 @@ func (d *Open123) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := d.getUserInfo()
|
uid, err := d.getUID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
duration := time.Duration(d.DirectLinkValidDuration) * time.Minute
|
||||||
|
|
||||||
newURL, err := d.SignURL(res.Data.URL, d.DirectLinkPrivateKey,
|
newURL, err := d.SignURL(res.Data.URL, d.DirectLinkPrivateKey,
|
||||||
u.Data.UID, duration)
|
uid, duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -128,18 +128,18 @@ type UserInfoResp struct {
|
|||||||
BaseResp
|
BaseResp
|
||||||
Data struct {
|
Data struct {
|
||||||
UID uint64 `json:"uid"`
|
UID uint64 `json:"uid"`
|
||||||
Username string `json:"username"`
|
// Username string `json:"username"`
|
||||||
DisplayName string `json:"displayName"`
|
// DisplayName string `json:"displayName"`
|
||||||
HeadImage string `json:"headImage"`
|
// HeadImage string `json:"headImage"`
|
||||||
Passport string `json:"passport"`
|
// Passport string `json:"passport"`
|
||||||
Mail string `json:"mail"`
|
// Mail string `json:"mail"`
|
||||||
SpaceUsed int64 `json:"spaceUsed"`
|
// SpaceUsed int64 `json:"spaceUsed"`
|
||||||
SpacePermanent int64 `json:"spacePermanent"`
|
// SpacePermanent int64 `json:"spacePermanent"`
|
||||||
SpaceTemp int64 `json:"spaceTemp"`
|
// SpaceTemp int64 `json:"spaceTemp"`
|
||||||
SpaceTempExpr string `json:"spaceTempExpr"`
|
// SpaceTempExpr int64 `json:"spaceTempExpr"`
|
||||||
Vip bool `json:"vip"`
|
// Vip bool `json:"vip"`
|
||||||
DirectTraffic int64 `json:"directTraffic"`
|
// DirectTraffic int64 `json:"directTraffic"`
|
||||||
IsHideUID bool `json:"isHideUID"`
|
// IsHideUID bool `json:"isHideUID"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +158,18 @@ func (d *Open123) getUserInfo() (*UserInfoResp, error) {
|
|||||||
return &resp, nil
|
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) {
|
func (d *Open123) getFiles(parentFileId int64, limit int, lastFileId int64) (*FileListResp, error) {
|
||||||
var resp FileListResp
|
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) {
|
_, err := d.Request(DirectLink, http.MethodGet, func(req *resty.Request) {
|
||||||
req.SetQueryParams(map[string]string{
|
req.SetQueryParams(map[string]string{
|
||||||
"fileId": strconv.FormatInt(fileId, 10),
|
"fileID": strconv.FormatInt(fileId, 10),
|
||||||
})
|
})
|
||||||
}, &resp)
|
}, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user