Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(123&123share): Android Or TV #2

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions drivers/123/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Pan123 struct {
model.Storage
Addition
apiRateLimit sync.Map
params Params
}

func (d *Pan123) Config() driver.Config {
Expand All @@ -41,6 +42,25 @@ 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
}

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

_, err := d.request(UserInfo, http.MethodGet, nil, nil)
return err
}
Expand All @@ -65,13 +85,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,7 +95,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 @@ -257,7 +270,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:"66a4c82756134af2a57d323fd7a5e58c"`
}

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
Loading