Skip to content

Commit

Permalink
Merge pull request #416 from px-org/dev
Browse files Browse the repository at this point in the history
v3.1.4
  • Loading branch information
libsgh authored May 17, 2023
2 parents 4fc7ce5 + 82d3f7a commit 565a04d
Show file tree
Hide file tree
Showing 31 changed files with 741 additions and 229 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ English | [中文](https://github.com/px-org/PanIndex/blob/dev/README_ZH.md)
- Local directory
- [189](https://cloud.189.cn/)
- [Teambition Team](https://www.teambition.com/)
- [Aliyundrive](https://www.aliyundrive.com/)
- [Aliyundrive](https://www.aliyundrive.com/)(share)
- OneDrive / Sharepoint([global](https://www.office.com/)[cn](https://portal.partner.microsoftonline.cn/))
- [139](https://yun.139.com/)
- [Google Drive](https://drive.google.com/)
- WebDav
- FTP
- [S3](https://aws.amazon.com/s3/)Object Storage
- [S3](https://aws.amazon.com/s3/)(Object Storage)
- [PikPak](https://mypikpak.com "https://mypikpak.com")
- [115](https://115.com/ "https://115.com/")
- [123](https://www.123pan.com/ "https://www.123pan.com/")
Expand Down
2 changes: 1 addition & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- 本地目录
- [天翼云](https://cloud.189.cn/)
- [Teambition 团队盘](https://www.teambition.com/)
- [阿里云盘](https://www.aliyundrive.com/)
- [阿里云盘](https://www.aliyundrive.com/)(分享)
- 微软云盘 / Sharepoint([国际版](https://www.office.com/)[世纪互联](https://portal.partner.microsoftonline.cn/))
- [和彩云](https://yun.139.com/)
- [谷歌云盘](https://drive.google.com/)
Expand Down
10 changes: 8 additions & 2 deletions control/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/px-org/PanIndex/dao"
"github.com/px-org/PanIndex/module"
"github.com/px-org/PanIndex/pan/ali"
_alishare "github.com/px-org/PanIndex/pan/alishare"
"github.com/px-org/PanIndex/pan/base"
"github.com/px-org/PanIndex/service"
"github.com/px-org/PanIndex/util"
Expand All @@ -30,7 +31,12 @@ func AliTranscode(c *gin.Context) {
fileId := c.Query("fileId")
account := dao.GetAccountById(accountId)
p, _ := base.GetPan(account.Mode)
result, _ := p.(*ali.Ali).Transcode(account, fileId)
var result string
if pan, ok := p.(*ali.Ali); ok {
result, _ = pan.Transcode(account, fileId)
} else {
result, _ = p.(*_alishare.AliShare).Transcode(account, fileId)
}
c.String(http.StatusOK, result)
c.Abort()
}
Expand Down Expand Up @@ -171,7 +177,7 @@ func IndexData(c *gin.Context) {
fns, isFile, lastFile, nextFile = service.Index(ac, path, fullPath, sortBy, order, true)
}
noReferrer := false
if ac.Mode == "aliyundrive" {
if ac.Mode == "aliyundrive" || ac.Mode == "aliyundrive-share" {
noReferrer = true
}
if c.GetBool("has_pwd") {
Expand Down
15 changes: 13 additions & 2 deletions jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jobs
import (
"github.com/px-org/PanIndex/dao"
"github.com/px-org/PanIndex/module"
"github.com/px-org/PanIndex/pan/ali"
"github.com/px-org/PanIndex/pan/base"
"github.com/px-org/PanIndex/util"
"github.com/robfig/cron/v3"
Expand All @@ -14,7 +15,7 @@ func Run() {
//aliyundrive onedrive googledrive refresh token
util.Cron.AddFunc("0 59 * * * ?", func() {
for _, account := range module.GloablConfig.Accounts {
if account.Mode == "aliyundrive" || account.Mode == "onedrive" || account.Mode == "onedrive-cn" || account.Mode == "googledrive" || account.Mode == "pikpak" {
if account.Mode == "aliyundrive" || account.Mode == "aliyundrive-share" || account.Mode == "onedrive" || account.Mode == "onedrive-cn" || account.Mode == "googledrive" || account.Mode == "pikpak" {
dao.SyncAccountStatus(account)
}
}
Expand All @@ -24,7 +25,7 @@ func Run() {
for _, account := range module.GloablConfig.Accounts {
p, _ := base.GetPan(account.Mode)
if account.Mode == "cloud189" || account.Mode == "yun139" ||
account.Mode == "teambition-us" || account.Mode == "teambition" {
account.Mode == "teambition-us" || account.Mode == "teambition" || account.Mode == "123" || account.Mode == "115" {
status := p.IsLogin(&account)
if !status {
log.Debugf("[cron] account:%s, logout, start login...", account.Name)
Expand All @@ -35,6 +36,16 @@ func Run() {
}
}
})
util.Cron.AddFunc("0 0 0 4 * ?", func() {
//extra jobs, eg:sign
for _, account := range module.GloablConfig.Accounts {
p, _ := base.GetPan(account.Mode)
if account.Mode == "aliyundrive" {
//aliyundrive sign
p.(ali.Ali).SignActivity(account)
}
}
})
accounts := []module.Account{}
dao.DB.Raw("select * from account where cache_policy ='dc' and sync_cron!='' and sync_dir!=''").Find(&accounts)
for _, ac := range accounts {
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
_ "github.com/px-org/PanIndex/pan/115"
_ "github.com/px-org/PanIndex/pan/123"
_ "github.com/px-org/PanIndex/pan/ali"
_ "github.com/px-org/PanIndex/pan/alishare"
_ "github.com/px-org/PanIndex/pan/cloud189"
_ "github.com/px-org/PanIndex/pan/ftp"
_ "github.com/px-org/PanIndex/pan/googledrive"
Expand Down
48 changes: 0 additions & 48 deletions module/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package module
import (
"github.com/go-resty/resty/v2"
"github.com/smallnest/weighted"
"time"
)

var (
Expand Down Expand Up @@ -173,61 +172,14 @@ type Cache struct {
Data interface{} `json:"data"`
}

type Ali struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
}
type Cloud189 struct {
Cloud189Session *resty.Client
SessionKey string `json:"session_key"`
AccessToken string `json:"access_token"`
RootId string `json:"root_id"`
FamilyId string `json:"family_id"`
}
type TokenResp struct {
RespError
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
TokenType string `json:"token_type"`
//local use
Signature string `json:"signature"`
Nonce int `json:"nonce"`
PrivateKeyHex string `json:"private_key_hex"`

UserInfo

DefaultSboxDriveId string `json:"default_sbox_drive_id"`
ExpireTime *time.Time `json:"expire_time"`
State string `json:"state"`
ExistLink []interface{} `json:"exist_link"`
NeedLink bool `json:"need_link"`
PinSetup bool `json:"pin_setup"`
IsFirstLogin bool `json:"is_first_login"`
NeedRpVerify bool `json:"need_rp_verify"`
DeviceId string `json:"device_id"`
}
type UserInfo struct {
RespError
DomainId string `json:"domain_id"`
UserId string `json:"user_id"`
Avatar string `json:"avatar"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
Email string `json:"email"`
NickName string `json:"nick_name"`
Phone string `json:"phone"`
Role string `json:"role"`
Status string `json:"status"`
UserName string `json:"user_name"`
Description string `json:"description"`
DefaultDriveId string `json:"default_drive_id"`
UserData map[string]interface{} `json:"user_data"`
}
type RespError struct {
Code string `json:"code"`
Message string `json:"message"`
}
type PartInfo struct {
PartNumber int `json:"partNumber"`
UploadUrl string `json:"uploadUrl"`
Expand Down
4 changes: 3 additions & 1 deletion pan/115/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var Sessions = map[string]*driver115.Pan115Client{}

var UA = driver115.UADefalut

var RootId = "0"

func init() {
base.RegisterPan("115", &Pan115{})
}
Expand Down Expand Up @@ -79,7 +81,7 @@ func (p Pan115) Files(account module.Account, fileId, path, sortColumn, sortOrde
func (p Pan115) File(account module.Account, fileId, path string) (module.FileNode, error) {
client := GetClient(&account)
fn := module.FileNode{}
if fileId == "0" {
if fileId == RootId {
return module.FileNode{
FileId: "0",
FileName: "root",
Expand Down
28 changes: 24 additions & 4 deletions pan/123/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

var Sessions = map[string]LoginResp{}

var RootId = "0"

func init() {
base.RegisterPan("123", &Pan123{})
}
Expand All @@ -42,6 +44,13 @@ func (p Pan123) AuthLogin(account *module.Account) (string, error) {
_, err := base.Client.R().
SetResult(&resp).
SetBody(reqBody).
SetHeaders(map[string]string{
"Origin": "https://www.123pan.com",
"Content-Type": "application/json;charset=UTF-8",
"platform": "web",
"App-Version": "3",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
}).
Post("https://www.123pan.com/b/api/user/sign_in")
//refresh_token_expire_time 1 month
if err != nil || resp.Code != 200 {
Expand Down Expand Up @@ -112,7 +121,17 @@ func (p Pan123) Files(account module.Account, fileId, path, sortColumn, sortOrde
func (p Pan123) File(account module.Account, fileId, path string) (module.FileNode, error) {
var resp FileResp
fn := module.FileNode{}
_, err := p.request(&account, "https://www.123pan.com/a/api/file/info", http.MethodPost, func(req *resty.Request) {
if fileId == RootId {
return module.FileNode{
FileId: "0",
FileName: "root",
FileSize: 0,
IsFolder: true,
Path: "/",
LastOpTime: time.Now().Format("2006-01-02 15:04:05"),
}, nil
}
_, err := p.request(&account, "https://www.123pan.com/b/api/file/info", http.MethodPost, func(req *resty.Request) {
req.SetBody(base.KV{
"fileIdList": []base.KV{
{
Expand Down Expand Up @@ -337,9 +356,10 @@ func (p Pan123) GetDownloadUrl(account module.Account, fileId string) (string, e
return "", err
}
}
dRedirectRep, _ := base.Client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(0)).R().Get(u.String())
if dRedirectRep.StatusCode() == 302 {
return dRedirectRep.Header().Get("location"), err
var downloadUrlResp DownloadUrlResp
_, err = p.request(&account, u.String(), http.MethodGet, nil, &downloadUrlResp)
if downloadUrlResp.Code == 0 {
return downloadUrlResp.Data.RedirectURL, err
}
}
return "", err
Expand Down
8 changes: 8 additions & 0 deletions pan/123/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ type ListUploadResp struct {
} `json:"Parts"`
} `json:"data"`
}

type DownloadUrlResp struct {
Message string `json:"message"`
Code int `json:"code"`
Data struct {
RedirectURL string `json:"redirect_url"`
} `json:"data"`
}
8 changes: 5 additions & 3 deletions pan/123/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ func (p *Pan123) request(account *module.Account, url string, method string, cal
req := base.Client.R().
SetAuthToken(session.Data.Token)
req.SetHeaders(map[string]string{
"origin": "https://www.123pan.com",
"content-type": "application/json;charset=UTF-8",
"Origin": "https://www.123pan.com",
"Content-Type": "application/json;charset=UTF-8",
"platform": "web",
"app-version": "1.2",
"Cookie": "jwt=" + session.Data.Token,
"App-Version": "3",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
})
if callback != nil {
callback(req)
Expand Down
Loading

0 comments on commit 565a04d

Please sign in to comment.