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

增加pikpak自动apache #7204

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'main-upstream'
# Conflicts:
#	drivers/pikpak/driver.go
#	drivers/pikpak/meta.go
#	drivers/pikpak/util.go
xiaokai committed Sep 4, 2024

Verified

This commit was signed with the committer’s verified signature.
leninmehedy Lenin Mehedy
commit 744ab03b4cb0f42911d3473a4685f6e8bb3a3acc
32 changes: 14 additions & 18 deletions drivers/pikpak/driver.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,10 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/model"
@@ -13,9 +17,6 @@ import (
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
"golang.org/x/oauth2"
"net/http"
"strconv"
"strings"
)

type PikPak struct {
@@ -90,24 +91,19 @@ func (d *PikPak) Init(ctx context.Context) (err error) {

// 如果已经有RefreshToken,直接获取AccessToken
if d.Addition.RefreshToken != "" {
// 使用 oauth2 刷新令牌
// 初始化 oauth2Token
d.oauth2Token = oauth2.ReuseTokenSource(nil, utils.TokenSource(func() (*oauth2.Token, error) {
return oauth2Config.TokenSource(ctx, &oauth2.Token{
RefreshToken: d.Addition.RefreshToken,
}).Token()
}))
_, err := d.oauth2Token.Token()
if err != nil {
if err := d.login(); err != nil {
if d.RefreshTokenMethod == "oauth2" {
// 使用 oauth2 刷新令牌
// 初始化 oauth2Token
d.initializeOAuth2Token(ctx, oauth2Config, d.Addition.RefreshToken)
if err := d.refreshTokenByOAuth2(); err != nil {
return err
}
} else {
if err := d.refreshToken(d.Addition.RefreshToken); err != nil {
return err
}
d.oauth2Token = oauth2.ReuseTokenSource(nil, utils.TokenSource(func() (*oauth2.Token, error) {
return oauth2Config.TokenSource(ctx, &oauth2.Token{
RefreshToken: d.RefreshToken,
}).Token()
}))
}

} else {
// 如果没有填写RefreshToken,尝试登录 获取 refreshToken
if err := d.login(); err != nil {
17 changes: 9 additions & 8 deletions drivers/pikpak/meta.go
Original file line number Diff line number Diff line change
@@ -7,14 +7,15 @@ import (

type Addition struct {
driver.RootID
Username string `json:"username" required:"true"`
Password string `json:"password" required:"true"`
Platform string `json:"platform" required:"true" type:"select" options:"android,web"`
RefreshToken string `json:"refresh_token" required:"true" default:""`
CaptchaToken string `json:"captcha_token" default:""`
DeviceID string `json:"device_id" required:"false" default:""`
DisableMediaLink bool `json:"disable_media_link" default:"true"`
CaptchaApi string `json:"captcha_api" default:""`
Username string `json:"username" required:"true"`
Password string `json:"password" required:"true"`
Platform string `json:"platform" required:"true" type:"select" options:"android,web"`
RefreshToken string `json:"refresh_token" required:"true" default:""`
RefreshTokenMethod string `json:"refresh_token_method" required:"true" type:"select" options:"oauth2,http"`
CaptchaToken string `json:"captcha_token" default:""`
DeviceID string `json:"device_id" required:"false" default:""`
DisableMediaLink bool `json:"disable_media_link" default:"true"`
CaptchaApi string `json:"captcha_api" default:""`
}

var config = driver.Config{
15 changes: 8 additions & 7 deletions drivers/pikpak/util.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,14 @@ import (
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
"net/http"
"path/filepath"
"regexp"
"strings"
"sync"
"time"

"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/op"
@@ -15,13 +23,6 @@ import (
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"golang.org/x/oauth2"
"io"
"net/http"
"path/filepath"
"regexp"
"strings"
"sync"
"time"

"github.com/alist-org/alist/v3/drivers/base"
"github.com/go-resty/resty/v2"
You are viewing a condensed version of this merge commit. You can view the full changes here.