Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/123-client-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
xrgzs committed Dec 17, 2024
2 parents cf58ab3 + c6a6a2a commit 59325bf
Show file tree
Hide file tree
Showing 8 changed files with 511 additions and 138 deletions.
38 changes: 28 additions & 10 deletions drivers/123/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
"github.com/google/uuid"
"golang.org/x/time/rate"
"io"
"net/http"
"net/url"
"strings"
"sync"
"time"

Expand All @@ -30,6 +32,7 @@ type Pan123 struct {
model.Storage
Addition
apiRateLimit sync.Map
params Params
}

func (d *Pan123) Config() driver.Config {
Expand All @@ -41,6 +44,29 @@ func (d *Pan123) GetAddition() driver.Additional {
}

func (d *Pan123) Init(ctx context.Context) error {
// 拼接UserAgent
if d.PlatformType == "android" {
d.params.UserAgent = AndroidUserAgentPrefix + "(" + d.OsVersion + ";" + d.DeviceName + " " + d.DeiveType + ")"
d.params.Platform = AndroidPlatformParam
d.params.AppVersion = AndroidAppVer
d.params.XChannel = AndroidXChannel
d.params.XAppVersion = AndroidXAppVer

} else if d.PlatformType == "tv" {
d.params.UserAgent = TVUserAgentPrefix + "(" + d.OsVersion + ";" + d.DeviceName + " " + d.DeiveType + ")"
d.params.Platform = TVPlatformParam
d.params.AppVersion = TVAndroidAppVer
}

if d.Addition.LoginUuid == "" {
d.Addition.LoginUuid = strings.ReplaceAll(uuid.New().String(), "-", "")
}

d.params.OsVersion = d.OsVersion
d.params.DeviceName = d.DeviceName
d.params.DeviceType = d.DeiveType
d.params.LoginUuid = d.Addition.LoginUuid

_, err := d.request(UserInfo, http.MethodGet, nil, nil)
return err
}
Expand All @@ -65,13 +91,6 @@ func (d *Pan123) List(ctx context.Context, dir model.Obj, args model.ListArgs) (
func (d *Pan123) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
if f, ok := file.(File); ok {
//var resp DownResp
var headers map[string]string
if !utils.IsLocalIPAddr(args.IP) {
headers = map[string]string{
//"X-Real-IP": "1.1.1.1",
"X-Forwarded-For": args.IP,
}
}
data := base.Json{
"driveId": 0,
"etag": f.Etag,
Expand All @@ -82,8 +101,7 @@ func (d *Pan123) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
"type": f.Type,
}
resp, err := d.request(DownloadInfo, http.MethodPost, func(req *resty.Request) {

req.SetBody(data).SetHeaders(headers)
req.SetBody(data)
}, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -258,7 +276,7 @@ func (d *Pan123) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr

func (d *Pan123) APIRateLimit(ctx context.Context, api string) error {
value, _ := d.apiRateLimit.LoadOrStore(api,
rate.NewLimiter(rate.Every(700*time.Millisecond), 1))
rate.NewLimiter(rate.Every(800*time.Millisecond), 1))
limiter := value.(*rate.Limiter)

return limiter.Wait(ctx)
Expand Down
13 changes: 10 additions & 3 deletions drivers/123/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import (
)

type Addition struct {
Username string `json:"username" required:"true"`
Password string `json:"password" required:"true"`
Username string `json:"username"`
Password string `json:"password"`
UseQrCodeLogin bool `json:"use_qr_code_login"`
UniID string `json:"uni_id"`
driver.RootID
//OrderBy string `json:"order_by" type:"select" options:"file_id,file_name,size,update_at" default:"file_name"`
//OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
AccessToken string
AccessToken string `json:"accesstoken" type:"text"`
PlatformType string `json:"platformType" type:"select" options:"android,tv" default:"android" required:"true"`
DeviceName string `json:"devicename" default:"Xiaomi"`
DeiveType string `json:"devicetype" default:"M1810E5A"`
OsVersion string `json:"osversion" default:"Android_8.1.0"`
LoginUuid string `json:"loginuuid" default:""`
}

var config = driver.Config{
Expand Down
18 changes: 18 additions & 0 deletions drivers/123/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,21 @@ type S3PreSignedURLs struct {
PreSignedUrls map[string]string `json:"presignedUrls"`
} `json:"data"`
}

type QrCodeGenerateResp struct {
Data struct {
UniID string `json:"uniID"`
Url string `json:"url"`
} `json:"data"`
}

type QrCodeResultResp struct {
Data struct {
Expire time.Time `json:"expire"`
LoginType int `json:"login_type"`
RefreshTokenExpireTime int `json:"refresh_token_expire_time"`
Token string `json:"token"`
LoginStatus int `json:"loginStatus"`
ScanPlatform int `json:"scanPlatform"`
} `json:"data"`
}
Loading

0 comments on commit 59325bf

Please sign in to comment.