Compare commits
53 Commits
Author | SHA1 | Date | |
---|---|---|---|
e1ccc0b215 | |||
87e339850d | |||
79c9b6ac77 | |||
aeb2297f1f | |||
3b59bb5c09 | |||
bc4bac921f | |||
f917882a84 | |||
6a67d1cf69 | |||
041b3587bf | |||
0eef7a129c | |||
4b635f06e3 | |||
279111a8e2 | |||
67674835da | |||
732e9eb1c3 | |||
b6af9aa587 | |||
a9027c0f06 | |||
d780fa18a5 | |||
d5626d6e2f | |||
52dcbfe1a4 | |||
bf0ee3d315 | |||
0237e78c1e | |||
44b8c6abf7 | |||
33e1acd344 | |||
c54cb61f14 | |||
734b204709 | |||
b7d9c5e4ff | |||
e698b457b9 | |||
5258c21656 | |||
1ca9a3d14e | |||
f23bec9a35 | |||
62a1acd1f4 | |||
fa6e3fe567 | |||
b71b62ee35 | |||
410b4939a4 | |||
62c0071f29 | |||
f043a41005 | |||
2e9da57036 | |||
d83cd37984 | |||
bad8b0ebbb | |||
4535e65948 | |||
3b413c2ee2 | |||
427ae56333 | |||
658fd5ad6e | |||
11830bb51c | |||
75c98429bf | |||
f77ea1b3a5 | |||
0a8bd96d33 | |||
68f37fc11f | |||
d6775cda69 | |||
43c6e07bac | |||
4901e9080c | |||
48049a5ea3 | |||
bd7260f0ff |
@ -51,6 +51,33 @@
|
|||||||
"contributions": [
|
"contributions": [
|
||||||
"doc"
|
"doc"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "Windman1320",
|
||||||
|
"name": "Windman",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/9999486?v=4",
|
||||||
|
"profile": "https://github.com/Windman1320",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "ericarena",
|
||||||
|
"name": "ericarena",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/4518927?v=4",
|
||||||
|
"profile": "https://github.com/ericarena",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "WntFlm",
|
||||||
|
"name": "WntFlm",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/34620278?v=4",
|
||||||
|
"profile": "https://github.com/WntFlm",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contributorsPerLine": 7,
|
"contributorsPerLine": 7,
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
Prerequisites:
|
Prerequisites:
|
||||||
|
|
||||||
- [git](https://nodejs.org/zh-cn/)
|
- [git](https://nodejs.org/zh-cn/)
|
||||||
- [Go 1.17+](https://golang.org/doc/install)
|
- [Go 1.18+](https://golang.org/doc/install)
|
||||||
- [gcc](https://gcc.gnu.org/)
|
- [gcc](https://gcc.gnu.org/)
|
||||||
- [nodejs](https://nodejs.org/)
|
- [nodejs](https://nodejs.org/)
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||||
[](#contributors-)
|
[](#contributors-)
|
||||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||||
|
|
||||||
## Contributors ✨
|
## Contributors ✨
|
||||||
@ -16,6 +16,11 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|||||||
<td align="center"><a href="https://www.iflu.cf/"><img src="https://avatars.githubusercontent.com/u/63903027?v=4?s=100" width="100px;" alt=""/><br /><sub><b>道辰</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=DaoChen6" title="Documentation">📖</a></td>
|
<td align="center"><a href="https://www.iflu.cf/"><img src="https://avatars.githubusercontent.com/u/63903027?v=4?s=100" width="100px;" alt=""/><br /><sub><b>道辰</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=DaoChen6" title="Documentation">📖</a></td>
|
||||||
<td align="center"><a href="https://vg-land.github.io/"><img src="https://avatars.githubusercontent.com/u/16739728?v=4?s=100" width="100px;" alt=""/><br /><sub><b>vg-land</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=vg-land" title="Code">💻</a></td>
|
<td align="center"><a href="https://vg-land.github.io/"><img src="https://avatars.githubusercontent.com/u/16739728?v=4?s=100" width="100px;" alt=""/><br /><sub><b>vg-land</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=vg-land" title="Code">💻</a></td>
|
||||||
<td align="center"><a href="https://c5y.moe"><img src="https://avatars.githubusercontent.com/u/18461360?v=4?s=100" width="100px;" alt=""/><br /><sub><b>凌莞~(=^▽^=)</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=Clansty" title="Documentation">📖</a></td>
|
<td align="center"><a href="https://c5y.moe"><img src="https://avatars.githubusercontent.com/u/18461360?v=4?s=100" width="100px;" alt=""/><br /><sub><b>凌莞~(=^▽^=)</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=Clansty" title="Documentation">📖</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/Windman1320"><img src="https://avatars.githubusercontent.com/u/9999486?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Windman</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=Windman1320" title="Code">💻</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/ericarena"><img src="https://avatars.githubusercontent.com/u/4518927?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ericarena</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=ericarena" title="Code">💻</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center"><a href="https://github.com/WntFlm"><img src="https://avatars.githubusercontent.com/u/34620278?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WntFlm</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=WntFlm" title="Code">💻</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ English | [中文](./README_cn.md) | [Contributors](./CONTRIBUTORS.md) | [Contri
|
|||||||
- [x] [Quark](https://pan.quark.cn)
|
- [x] [Quark](https://pan.quark.cn)
|
||||||
- [x] [XunleiCloud](https://pan.xunlei.com/)
|
- [x] [XunleiCloud](https://pan.xunlei.com/)
|
||||||
- [x] SFTP
|
- [x] SFTP
|
||||||
|
- [x] [Baidu.Photo](https://photo.baidu.com/)
|
||||||
- [x] Easy to deploy and out-of-the-box
|
- [x] Easy to deploy and out-of-the-box
|
||||||
- [x] File preview (PDF, markdown, code, plain text, ...)
|
- [x] File preview (PDF, markdown, code, plain text, ...)
|
||||||
- [x] Image preview in gallery mode
|
- [x] Image preview in gallery mode
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
- [x] [夸克网盘](https://pan.quark.cn)
|
- [x] [夸克网盘](https://pan.quark.cn)
|
||||||
- [x] [迅雷云盘](https://pan.xunlei.com/)
|
- [x] [迅雷云盘](https://pan.xunlei.com/)
|
||||||
- [x] SFTP
|
- [x] SFTP
|
||||||
|
- [x] [一刻相册](https://photo.baidu.com/)
|
||||||
- [x] 部署方便,开箱即用
|
- [x] 部署方便,开箱即用
|
||||||
- [x] 文件预览(PDF、markdown、代码、纯文本……)
|
- [x] 文件预览(PDF、markdown、代码、纯文本……)
|
||||||
- [x] 画廊模式下的图像预览
|
- [x] 画廊模式下的图像预览
|
||||||
|
@ -252,7 +252,7 @@ func InitSettings() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "ocr api",
|
Key: "ocr api",
|
||||||
Value: "https://api.xhofe.top/ocr/file/json",
|
Value: "https://api.nn.ci/ocr/file/json",
|
||||||
Description: "Used to identify verification codes",
|
Description: "Used to identify verification codes",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Access: model.PRIVATE,
|
Access: model.PRIVATE,
|
||||||
@ -266,6 +266,22 @@ func InitSettings() {
|
|||||||
Group: model.BACK,
|
Group: model.BACK,
|
||||||
Description: "Experimental function, not recommended as it's still under development",
|
Description: "Experimental function, not recommended as it's still under development",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Key: "Aria2 RPC url",
|
||||||
|
Value: "http://localhost:6800/jsonrpc",
|
||||||
|
Description: "Aria2 RPC url, e.g. 'http://aria2.example.com:6800/jsonrpc'",
|
||||||
|
Type: "string",
|
||||||
|
Access: model.PRIVATE,
|
||||||
|
Group: model.BACK,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "Aria2 RPC secret",
|
||||||
|
Value: "",
|
||||||
|
Description: "Aria2 RPC secret, e.g. '123456'",
|
||||||
|
Type: "string",
|
||||||
|
Access: model.PRIVATE,
|
||||||
|
Group: model.BACK,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, _ := range settings {
|
for i, _ := range settings {
|
||||||
v := settings[i]
|
v := settings[i]
|
||||||
|
@ -3,15 +3,15 @@ package _23
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Xhofe/alist/conf"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (driver Pan123) Login(account *model.Account) error {
|
func (driver Pan123) Login(account *model.Account) error {
|
||||||
@ -40,21 +40,22 @@ func (driver Pan123) Login(account *model.Account) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Pan123) FormatFile(file *Pan123File) *model.File {
|
func (driver Pan123) FormatFile(file *File) *model.File {
|
||||||
f := &model.File{
|
f := &model.File{
|
||||||
Id: strconv.FormatInt(file.FileId, 10),
|
Id: strconv.FormatInt(file.FileId, 10),
|
||||||
Name: file.FileName,
|
Name: file.FileName,
|
||||||
Size: file.Size,
|
Size: file.Size,
|
||||||
Driver: driver.Config().Name,
|
Driver: driver.Config().Name,
|
||||||
UpdatedAt: file.UpdateAt,
|
UpdatedAt: file.UpdateAt,
|
||||||
|
Thumbnail: file.DownloadUrl,
|
||||||
}
|
}
|
||||||
f.Type = file.GetType()
|
f.Type = file.GetType()
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]Pan123File, error) {
|
func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]File, error) {
|
||||||
next := "0"
|
next := "0"
|
||||||
res := make([]Pan123File, 0)
|
res := make([]File, 0)
|
||||||
for next != "-1" {
|
for next != "-1" {
|
||||||
var resp Pan123Files
|
var resp Pan123Files
|
||||||
query := map[string]string{
|
query := map[string]string{
|
||||||
@ -66,7 +67,7 @@ func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]Pan123
|
|||||||
"parentFileId": parentId,
|
"parentFileId": parentId,
|
||||||
"trashed": "false",
|
"trashed": "false",
|
||||||
}
|
}
|
||||||
_, err := driver.Request("https://www.123pan.com/api/file/list",
|
_, err := driver.Request("https://www.123pan.com/api/file/list/new",
|
||||||
base.Get, nil, query, nil, &resp, false, account)
|
base.Get, nil, query, nil, &resp, false, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -139,7 +140,7 @@ func (driver Pan123) Request(url string, method int, headers, query map[string]s
|
|||||||
// return body, nil
|
// return body, nil
|
||||||
//}
|
//}
|
||||||
|
|
||||||
func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File, error) {
|
func (driver Pan123) GetFile(path string, account *model.Account) (*File, error) {
|
||||||
dir, name := filepath.Split(path)
|
dir, name := filepath.Split(path)
|
||||||
dir = utils.ParsePath(dir)
|
dir = utils.ParsePath(dir)
|
||||||
_, err := driver.Files(dir, account)
|
_, err := driver.Files(dir, account)
|
||||||
@ -147,14 +148,15 @@ func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
parentFiles_, _ := base.GetCache(dir, account)
|
parentFiles_, _ := base.GetCache(dir, account)
|
||||||
parentFiles, _ := parentFiles_.([]Pan123File)
|
parentFiles, _ := parentFiles_.([]File)
|
||||||
for _, file := range parentFiles {
|
for _, file := range parentFiles {
|
||||||
if file.FileName == name {
|
if file.FileName == name {
|
||||||
if file.Type != conf.FOLDER {
|
//if file.Type != conf.FOLDER {
|
||||||
return &file, err
|
// return &file, err
|
||||||
} else {
|
//} else {
|
||||||
return nil, base.ErrNotFile
|
// return nil, base.ErrNotFile
|
||||||
}
|
//}
|
||||||
|
return &file, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, base.ErrPathNotFound
|
return nil, base.ErrPathNotFound
|
||||||
|
@ -4,6 +4,13 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
@ -13,12 +20,6 @@ import (
|
|||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pan123 struct{}
|
type Pan123 struct{}
|
||||||
@ -108,10 +109,10 @@ func (driver Pan123) File(path string, account *model.Account) (*model.File, err
|
|||||||
|
|
||||||
func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) {
|
func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) {
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
var rawFiles []Pan123File
|
var rawFiles []File
|
||||||
cache, err := base.GetCache(path, account)
|
cache, err := base.GetCache(path, account)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
rawFiles, _ = cache.([]Pan123File)
|
rawFiles, _ = cache.([]File)
|
||||||
} else {
|
} else {
|
||||||
file, err := driver.File(path, account)
|
file, err := driver.File(path, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,7 +126,7 @@ func (driver Pan123) Files(path string, account *model.Account) ([]model.File, e
|
|||||||
_ = base.SetCache(path, rawFiles, account)
|
_ = base.SetCache(path, rawFiles, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
files := make([]model.File, 0)
|
files := make([]model.File, 0, len(rawFiles))
|
||||||
for _, file := range rawFiles {
|
for _, file := range rawFiles {
|
||||||
files = append(files, *driver.FormatFile(&file))
|
files = append(files, *driver.FormatFile(&file))
|
||||||
}
|
}
|
||||||
@ -278,12 +279,13 @@ func (driver Pan123) Delete(path string, account *model.Account) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Debugln("delete 123 file: ", file)
|
||||||
data := base.Json{
|
data := base.Json{
|
||||||
"driveId": 0,
|
"driveId": 0,
|
||||||
"operation": true,
|
"operation": true,
|
||||||
"fileTrashInfoList": file,
|
"fileTrashInfoList": []File{*file},
|
||||||
}
|
}
|
||||||
_, err = driver.Request("https://www.123pan.com/api/file/trash",
|
_, err = driver.Request("https://www.123pan.com/b/api/file/trash",
|
||||||
base.Post, nil, nil, &data, nil, false, account)
|
base.Post, nil, nil, &data, nil, false, account)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -299,46 +301,36 @@ func (driver Pan123) Upload(file *model.FileStream, account *model.Account) erro
|
|||||||
if !parentFile.IsDir() {
|
if !parentFile.IsDir() {
|
||||||
return base.ErrNotFolder
|
return base.ErrNotFolder
|
||||||
}
|
}
|
||||||
parentFileId, _ := strconv.Atoi(parentFile.Id)
|
|
||||||
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer tempFile.Close()
|
||||||
_ = tempFile.Close()
|
defer os.Remove(tempFile.Name())
|
||||||
_ = os.Remove(tempFile.Name())
|
|
||||||
}()
|
|
||||||
_, err = io.Copy(tempFile, file)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tempFile.Seek(0, io.SeekStart)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
_, err = io.Copy(h, tempFile)
|
if _, err = io.Copy(io.MultiWriter(tempFile, h), file); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
etag := hex.EncodeToString(h.Sum(nil))
|
etag := hex.EncodeToString(h.Sum(nil))
|
||||||
log.Debugln("md5:", etag)
|
|
||||||
_, err = tempFile.Seek(0, io.SeekStart)
|
_, err = tempFile.Seek(0, io.SeekStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := base.Json{
|
data := base.Json{
|
||||||
"driveId": 0,
|
"driveId": 0,
|
||||||
"duplicate": true,
|
"duplicate": 2, // 2->覆盖 1->重命名 0->默认
|
||||||
"etag": etag,
|
"etag": etag,
|
||||||
"fileName": file.GetFileName(),
|
"fileName": file.GetFileName(),
|
||||||
"parentFileId": parentFileId,
|
"parentFileId": parentFile.Id,
|
||||||
"size": file.GetSize(),
|
"size": file.GetSize(),
|
||||||
"type": 0,
|
"type": 0,
|
||||||
}
|
}
|
||||||
var resp UploadResp
|
var resp UploadResp
|
||||||
_, err = driver.Request("https://www.123pan.com/api/file/upload_request",
|
_, err = driver.Request("https://www.123pan.com/api/file/upload_request",
|
||||||
base.Post, nil, nil, &data, &resp, false, account)
|
base.Post, map[string]string{"app-version": "1.1"}, nil, &data, &resp, false, account)
|
||||||
//res, err := driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
//res, err := driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1,31 +1,33 @@
|
|||||||
package _23
|
package _23
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/conf"
|
|
||||||
"github.com/Xhofe/alist/utils"
|
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pan123File struct {
|
type File struct {
|
||||||
FileName string `json:"FileName"`
|
FileName string `json:"FileName"`
|
||||||
Size int64 `json:"Size"`
|
Size int64 `json:"Size"`
|
||||||
UpdateAt *time.Time `json:"UpdateAt"`
|
UpdateAt *time.Time `json:"UpdateAt"`
|
||||||
FileId int64 `json:"FileId"`
|
FileId int64 `json:"FileId"`
|
||||||
Type int `json:"Type"`
|
Type int `json:"Type"`
|
||||||
Etag string `json:"Etag"`
|
Etag string `json:"Etag"`
|
||||||
S3KeyFlag string `json:"S3KeyFlag"`
|
S3KeyFlag string `json:"S3KeyFlag"`
|
||||||
|
DownloadUrl string `json:"DownloadUrl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Pan123File) GetSize() uint64 {
|
func (f File) GetSize() uint64 {
|
||||||
return uint64(f.Size)
|
return uint64(f.Size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Pan123File) GetName() string {
|
func (f File) GetName() string {
|
||||||
return f.FileName
|
return f.FileName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Pan123File) GetType() int {
|
func (f File) GetType() int {
|
||||||
if f.Type == 1 {
|
if f.Type == 1 {
|
||||||
return conf.FOLDER
|
return conf.FOLDER
|
||||||
}
|
}
|
||||||
@ -47,8 +49,8 @@ type Pan123TokenResp struct {
|
|||||||
type Pan123Files struct {
|
type Pan123Files struct {
|
||||||
BaseResp
|
BaseResp
|
||||||
Data struct {
|
Data struct {
|
||||||
InfoList []Pan123File `json:"InfoList"`
|
InfoList []File `json:"InfoList"`
|
||||||
Next string `json:"Next"`
|
Next string `json:"Next"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,6 +448,7 @@ func (driver Cloud139) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugf("%+v", res)
|
log.Debugf("%+v", res)
|
||||||
|
res.Body.Close()
|
||||||
start += byteSize
|
start += byteSize
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -110,8 +110,10 @@ func (driver Cloud189) Login(account *model.Account) error {
|
|||||||
b := ""
|
b := ""
|
||||||
lt := ""
|
lt := ""
|
||||||
ltText := regexp.MustCompile(`lt = "(.+?)"`)
|
ltText := regexp.MustCompile(`lt = "(.+?)"`)
|
||||||
|
var res *resty.Response
|
||||||
|
var err error
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
res, err := client.R().Get(url)
|
res, err = client.R().Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -129,7 +131,7 @@ func (driver Cloud189) Login(account *model.Account) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if lt == "" {
|
if lt == "" {
|
||||||
return errors.New("get page: " + b)
|
return fmt.Errorf("get page: %s \nstatus: %d \nrequest url: %s", b, res.StatusCode(), res.RawResponse.Request.URL.String())
|
||||||
}
|
}
|
||||||
captchaToken := regexp.MustCompile(`captchaToken' value='(.+?)'`).FindStringSubmatch(b)[1]
|
captchaToken := regexp.MustCompile(`captchaToken' value='(.+?)'`).FindStringSubmatch(b)[1]
|
||||||
returnUrl := regexp.MustCompile(`returnUrl = '(.+?)'`).FindStringSubmatch(b)[1]
|
returnUrl := regexp.MustCompile(`returnUrl = '(.+?)'`).FindStringSubmatch(b)[1]
|
||||||
@ -169,7 +171,7 @@ func (driver Cloud189) Login(account *model.Account) error {
|
|||||||
passwordRsa := RsaEncode([]byte(account.Password), jRsakey, true)
|
passwordRsa := RsaEncode([]byte(account.Password), jRsakey, true)
|
||||||
url = "https://open.e.189.cn/api/logbox/oauth2/loginSubmit.do"
|
url = "https://open.e.189.cn/api/logbox/oauth2/loginSubmit.do"
|
||||||
var loginResp LoginResp
|
var loginResp LoginResp
|
||||||
res, err := client.R().
|
res, err = client.R().
|
||||||
SetHeaders(map[string]string{
|
SetHeaders(map[string]string{
|
||||||
"lt": lt,
|
"lt": lt,
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
|
||||||
@ -575,6 +577,7 @@ func (driver Cloud189) NewUpload(file *model.FileStream, account *model.Account)
|
|||||||
|
|
||||||
r, err := base.HttpClient.Do(req)
|
r, err := base.HttpClient.Do(req)
|
||||||
log.Debugf("%+v %+v", r, r.Request.Header)
|
log.Debugf("%+v %+v", r, r.Request.Header)
|
||||||
|
r.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -607,6 +607,7 @@ func (driver Cloud189) CommonUpload(file *model.FileStream, parentFile *model.Fi
|
|||||||
|
|
||||||
uploadData := uploadUrl.UploadUrls[fmt.Sprint("partNumber_", i)]
|
uploadData := uploadUrl.UploadUrls[fmt.Sprint("partNumber_", i)]
|
||||||
req, _ := http.NewRequest(http.MethodPut, uploadData.RequestURL, byteData)
|
req, _ := http.NewRequest(http.MethodPut, uploadData.RequestURL, byteData)
|
||||||
|
req.Header.Del("User-Agent")
|
||||||
for k, v := range ParseHttpHeader(uploadData.RequestHeader) {
|
for k, v := range ParseHttpHeader(uploadData.RequestHeader) {
|
||||||
req.Header.Set(k, v)
|
req.Header.Set(k, v)
|
||||||
}
|
}
|
||||||
@ -619,8 +620,10 @@ func (driver Cloud189) CommonUpload(file *model.FileStream, parentFile *model.Fi
|
|||||||
}
|
}
|
||||||
if r.StatusCode != http.StatusOK {
|
if r.StatusCode != http.StatusOK {
|
||||||
data, _ := io.ReadAll(r.Body)
|
data, _ := io.ReadAll(r.Body)
|
||||||
|
r.Body.Close()
|
||||||
return fmt.Errorf(string(data))
|
return fmt.Errorf(string(data))
|
||||||
}
|
}
|
||||||
|
r.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
fileMd5Hex := strings.ToUpper(hex.EncodeToString(fileMd5.Sum(nil)))
|
fileMd5Hex := strings.ToUpper(hex.EncodeToString(fileMd5.Sum(nil)))
|
||||||
@ -715,6 +718,7 @@ func (driver Cloud189) FastUpload(file *model.FileStream, parentFile *model.File
|
|||||||
for i := 1; i <= count; i++ {
|
for i := 1; i <= count; i++ {
|
||||||
uploadData := uploadUrls.UploadUrls[fmt.Sprint("partNumber_", i)]
|
uploadData := uploadUrls.UploadUrls[fmt.Sprint("partNumber_", i)]
|
||||||
req, _ := http.NewRequest(http.MethodPut, uploadData.RequestURL, io.NewSectionReader(tempFile, int64(i-1)*DEFAULT, DEFAULT))
|
req, _ := http.NewRequest(http.MethodPut, uploadData.RequestURL, io.NewSectionReader(tempFile, int64(i-1)*DEFAULT, DEFAULT))
|
||||||
|
req.Header.Del("User-Agent")
|
||||||
for k, v := range ParseHttpHeader(uploadData.RequestHeader) {
|
for k, v := range ParseHttpHeader(uploadData.RequestHeader) {
|
||||||
req.Header.Set(k, v)
|
req.Header.Set(k, v)
|
||||||
}
|
}
|
||||||
@ -727,8 +731,10 @@ func (driver Cloud189) FastUpload(file *model.FileStream, parentFile *model.File
|
|||||||
}
|
}
|
||||||
if r.StatusCode != http.StatusOK {
|
if r.StatusCode != http.StatusOK {
|
||||||
data, _ := io.ReadAll(r.Body)
|
data, _ := io.ReadAll(r.Body)
|
||||||
|
r.Body.Close()
|
||||||
return fmt.Errorf(string(data))
|
return fmt.Errorf(string(data))
|
||||||
}
|
}
|
||||||
|
r.Body.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,10 +424,17 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
if account.Bool1 {
|
if account.Bool1 {
|
||||||
buf := make([]byte, 1024)
|
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||||
n, _ := file.Read(buf[:])
|
io.CopyN(buf, file, 1024)
|
||||||
reqBody["pre_hash"] = utils.GetSHA1Encode(string(buf[:n]))
|
reqBody["pre_hash"] = utils.GetSHA1Encode(buf.String())
|
||||||
file.File = io.NopCloser(io.MultiReader(bytes.NewReader(buf[:n]), file.File))
|
// 把头部拼接回去
|
||||||
|
file.File = struct {
|
||||||
|
io.Reader
|
||||||
|
io.Closer
|
||||||
|
}{
|
||||||
|
Reader: io.MultiReader(buf, file.File),
|
||||||
|
Closer: file.File,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
reqBody["content_hash_name"] = "none"
|
reqBody["content_hash_name"] = "none"
|
||||||
reqBody["proof_version"] = "v1"
|
reqBody["proof_version"] = "v1"
|
||||||
@ -454,7 +461,7 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
return fmt.Errorf("%s", e.Message)
|
return fmt.Errorf("%s", e.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Code == "PreHashMatched" && account.Bool1 {
|
if account.Bool1 && e.Code == "PreHashMatched" {
|
||||||
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -499,6 +506,7 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 秒传失败
|
||||||
if _, err = tempFile.Seek(0, io.SeekStart); err != nil {
|
if _, err = tempFile.Seek(0, io.SeekStart); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -515,6 +523,7 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugf("%+v", res)
|
log.Debugf("%+v", res)
|
||||||
|
res.Body.Close()
|
||||||
//res, err := base.BaseClient.R().
|
//res, err := base.BaseClient.R().
|
||||||
// SetHeader("Content-Type","").
|
// SetHeader("Content-Type","").
|
||||||
// SetBody(byteData).Put(resp.PartInfoList[i].UploadUrl)
|
// SetBody(byteData).Put(resp.PartInfoList[i].UploadUrl)
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
_ "github.com/Xhofe/alist/drivers/webdav"
|
_ "github.com/Xhofe/alist/drivers/webdav"
|
||||||
_ "github.com/Xhofe/alist/drivers/xunlei"
|
_ "github.com/Xhofe/alist/drivers/xunlei"
|
||||||
_ "github.com/Xhofe/alist/drivers/yandex"
|
_ "github.com/Xhofe/alist/drivers/yandex"
|
||||||
|
_ "github.com/Xhofe/alist/drivers/baiduphoto"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
259
drivers/baiduphoto/baidu.go
Normal file
259
drivers/baiduphoto/baidu.go
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
package baiduphoto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
|
"github.com/Xhofe/alist/model"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (driver Baidu) RefreshToken(account *model.Account) error {
|
||||||
|
err := driver.refreshToken(account)
|
||||||
|
if err != nil && err == base.ErrEmptyToken {
|
||||||
|
err = driver.refreshToken(account)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
account.Status = err.Error()
|
||||||
|
}
|
||||||
|
_ = model.SaveAccount(account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) refreshToken(account *model.Account) error {
|
||||||
|
u := "https://openapi.baidu.com/oauth/2.0/token"
|
||||||
|
var resp base.TokenResp
|
||||||
|
var e TokenErrResp
|
||||||
|
_, err := base.RestyClient.R().
|
||||||
|
SetResult(&resp).
|
||||||
|
SetError(&e).
|
||||||
|
SetQueryParams(map[string]string{
|
||||||
|
"grant_type": "refresh_token",
|
||||||
|
"refresh_token": account.RefreshToken,
|
||||||
|
"client_id": account.ClientId,
|
||||||
|
"client_secret": account.ClientSecret,
|
||||||
|
}).Get(u)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if e.ErrorMsg != "" {
|
||||||
|
return &e
|
||||||
|
}
|
||||||
|
if resp.RefreshToken == "" {
|
||||||
|
return base.ErrEmptyToken
|
||||||
|
}
|
||||||
|
account.Status = "work"
|
||||||
|
account.AccessToken, account.RefreshToken = resp.AccessToken, resp.RefreshToken
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Request(method string, url string, callback func(*resty.Request), account *model.Account) (*resty.Response, error) {
|
||||||
|
req := base.RestyClient.R()
|
||||||
|
req.SetQueryParam("access_token", account.AccessToken)
|
||||||
|
if callback != nil {
|
||||||
|
callback(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := req.Execute(method, url)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
log.Debug(res.String())
|
||||||
|
|
||||||
|
var erron Erron
|
||||||
|
if err = utils.Json.Unmarshal(res.Body(), &erron); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch erron.Errno {
|
||||||
|
case 0:
|
||||||
|
return res, nil
|
||||||
|
case -6:
|
||||||
|
if err = driver.RefreshToken(account); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("errno: %d, refer to https://photo.baidu.com/union/doc", erron.Errno)
|
||||||
|
}
|
||||||
|
return driver.Request(method, url, callback, account)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有根文件
|
||||||
|
func (driver Baidu) GetAllFile(account *model.Account) (files []File, err error) {
|
||||||
|
var cursor string
|
||||||
|
|
||||||
|
for {
|
||||||
|
var resp FileListResp
|
||||||
|
_, err = driver.Request(http.MethodGet, FILE_API_URL_V1+"/list", func(r *resty.Request) {
|
||||||
|
r.SetQueryParams(map[string]string{
|
||||||
|
"need_thumbnail": "1",
|
||||||
|
"need_filter_hidden": "0",
|
||||||
|
"cursor": cursor,
|
||||||
|
})
|
||||||
|
r.SetResult(&resp)
|
||||||
|
}, account)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = resp.Cursor
|
||||||
|
files = append(files, resp.List...)
|
||||||
|
|
||||||
|
if !resp.HasNextPage() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有相册
|
||||||
|
func (driver Baidu) GetAllAlbum(account *model.Account) (albums []Album, err error) {
|
||||||
|
var cursor string
|
||||||
|
for {
|
||||||
|
var resp AlbumListResp
|
||||||
|
_, err = driver.Request(http.MethodGet, ALBUM_API_URL+"/list", func(r *resty.Request) {
|
||||||
|
r.SetQueryParams(map[string]string{
|
||||||
|
"need_amount": "1",
|
||||||
|
"limit": "100",
|
||||||
|
"cursor": cursor,
|
||||||
|
})
|
||||||
|
r.SetResult(&resp)
|
||||||
|
}, account)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if albums == nil {
|
||||||
|
albums = make([]Album, 0, resp.TotalCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = resp.Cursor
|
||||||
|
albums = append(albums, resp.List...)
|
||||||
|
|
||||||
|
if !resp.HasNextPage() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取相册中所有文件
|
||||||
|
func (driver Baidu) GetAllAlbumFile(albumID string, account *model.Account) (files []AlbumFile, err error) {
|
||||||
|
var cursor string
|
||||||
|
for {
|
||||||
|
var resp AlbumFileListResp
|
||||||
|
_, err = driver.Request(http.MethodGet, ALBUM_API_URL+"/listfile", func(r *resty.Request) {
|
||||||
|
r.SetQueryParams(map[string]string{
|
||||||
|
"album_id": splitID(albumID)[0],
|
||||||
|
"need_amount": "1",
|
||||||
|
"limit": "1000",
|
||||||
|
"cursor": cursor,
|
||||||
|
})
|
||||||
|
r.SetResult(&resp)
|
||||||
|
}, account)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if files == nil {
|
||||||
|
files = make([]AlbumFile, 0, resp.TotalCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = resp.Cursor
|
||||||
|
files = append(files, resp.List...)
|
||||||
|
|
||||||
|
if !resp.HasNextPage() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建相册
|
||||||
|
func (driver Baidu) CreateAlbum(name string, account *model.Account) error {
|
||||||
|
if !checkName(name) {
|
||||||
|
return ErrNotSupportName
|
||||||
|
}
|
||||||
|
_, err := driver.Request(http.MethodPost, ALBUM_API_URL+"/create", func(r *resty.Request) {
|
||||||
|
r.SetQueryParams(map[string]string{
|
||||||
|
"title": name,
|
||||||
|
"tid": getTid(),
|
||||||
|
"source": "0",
|
||||||
|
})
|
||||||
|
}, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 相册改名
|
||||||
|
func (driver Baidu) SetAlbumName(albumID string, name string, account *model.Account) error {
|
||||||
|
if !checkName(name) {
|
||||||
|
return ErrNotSupportName
|
||||||
|
}
|
||||||
|
|
||||||
|
e := splitID(albumID)
|
||||||
|
_, err := driver.Request(http.MethodPost, ALBUM_API_URL+"/settitle", func(r *resty.Request) {
|
||||||
|
r.SetFormData(map[string]string{
|
||||||
|
"title": name,
|
||||||
|
"album_id": e[0],
|
||||||
|
"tid": e[1],
|
||||||
|
})
|
||||||
|
}, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除相册
|
||||||
|
func (driver Baidu) DeleteAlbum(albumID string, account *model.Account) error {
|
||||||
|
e := splitID(albumID)
|
||||||
|
_, err := driver.Request(http.MethodPost, ALBUM_API_URL+"/delete", func(r *resty.Request) {
|
||||||
|
r.SetFormData(map[string]string{
|
||||||
|
"album_id": e[0],
|
||||||
|
"tid": e[1],
|
||||||
|
"delete_origin_image": "0", // 是否删除原图 0 不删除
|
||||||
|
})
|
||||||
|
}, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除相册文件
|
||||||
|
func (driver Baidu) DeleteAlbumFile(albumID string, account *model.Account, fileIDs ...string) error {
|
||||||
|
e := splitID(albumID)
|
||||||
|
_, err := driver.Request(http.MethodPost, ALBUM_API_URL+"/delfile", func(r *resty.Request) {
|
||||||
|
r.SetFormData(map[string]string{
|
||||||
|
"album_id": e[0],
|
||||||
|
"tid": e[1],
|
||||||
|
"list": fsidsFormat(fileIDs...),
|
||||||
|
"del_origin": "0", // 是否删除原图 0 不删除 1 删除
|
||||||
|
})
|
||||||
|
}, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增加相册文件
|
||||||
|
func (driver Baidu) AddAlbumFile(albumID string, account *model.Account, fileIDs ...string) error {
|
||||||
|
e := splitID(albumID)
|
||||||
|
_, err := driver.Request(http.MethodGet, ALBUM_API_URL+"/addfile", func(r *resty.Request) {
|
||||||
|
r.SetQueryParams(map[string]string{
|
||||||
|
"album_id": e[0],
|
||||||
|
"tid": e[1],
|
||||||
|
"list": fsidsFormatNotUk(fileIDs...),
|
||||||
|
})
|
||||||
|
}, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存相册文件为根文件
|
||||||
|
func (driver Baidu) CopyAlbumFile(albumID string, account *model.Account, fileID string) (*CopyFile, error) {
|
||||||
|
var resp CopyFileResp
|
||||||
|
e := splitID(fileID)
|
||||||
|
_, err := driver.Request(http.MethodPost, ALBUM_API_URL+"/copyfile", func(r *resty.Request) {
|
||||||
|
r.SetFormData(map[string]string{
|
||||||
|
"album_id": splitID(albumID)[0],
|
||||||
|
"tid": e[2],
|
||||||
|
"uk": e[1],
|
||||||
|
"list": fsidsFormatNotUk(fileID),
|
||||||
|
})
|
||||||
|
r.SetResult(&resp)
|
||||||
|
}, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp.List[0], err
|
||||||
|
}
|
502
drivers/baiduphoto/driver.go
Normal file
502
drivers/baiduphoto/driver.go
Normal file
@ -0,0 +1,502 @@
|
|||||||
|
package baiduphoto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"math"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
|
"github.com/Xhofe/alist/model"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Baidu struct{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
base.RegisterDriver(new(Baidu))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Config() base.DriverConfig {
|
||||||
|
return base.DriverConfig{
|
||||||
|
Name: "Baidu.Photo",
|
||||||
|
LocalSort: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Items() []base.Item {
|
||||||
|
return []base.Item{
|
||||||
|
{
|
||||||
|
Name: "refresh_token",
|
||||||
|
Label: "refresh token",
|
||||||
|
Type: base.TypeString,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "root_folder",
|
||||||
|
Label: "album_id",
|
||||||
|
Type: base.TypeString,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "internal_type",
|
||||||
|
Label: "download api",
|
||||||
|
Type: base.TypeSelect,
|
||||||
|
Required: true,
|
||||||
|
Values: "file,album",
|
||||||
|
Default: "album",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "client_id",
|
||||||
|
Label: "client id",
|
||||||
|
Default: "iYCeC9g08h5vuP9UqvPHKKSVrKFXGa1v",
|
||||||
|
Type: base.TypeString,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "client_secret",
|
||||||
|
Label: "client secret",
|
||||||
|
Default: "jXiFMOPVPCWlO2M5CwWQzffpNPaGTRBG",
|
||||||
|
Type: base.TypeString,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Save(account *model.Account, old *model.Account) error {
|
||||||
|
if account == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return driver.RefreshToken(account)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) File(path string, account *model.Account) (*model.File, error) {
|
||||||
|
path = utils.ParsePath(path)
|
||||||
|
if path == "/" {
|
||||||
|
return &model.File{
|
||||||
|
Id: account.RootFolder,
|
||||||
|
Name: account.Name,
|
||||||
|
Size: 0,
|
||||||
|
Type: conf.FOLDER,
|
||||||
|
Driver: driver.Config().Name,
|
||||||
|
UpdatedAt: account.UpdatedAt,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dir, name := utils.Split(path)
|
||||||
|
files, err := driver.Files(dir, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
if file.Name == name {
|
||||||
|
return &file, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, base.ErrPathNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Files(path string, account *model.Account) ([]model.File, error) {
|
||||||
|
path = utils.ParsePath(path)
|
||||||
|
var files []model.File
|
||||||
|
cache, err := base.GetCache(path, account)
|
||||||
|
if err == nil {
|
||||||
|
files, _ = cache.([]model.File)
|
||||||
|
return files, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := driver.File(path, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if IsAlbum(file) {
|
||||||
|
albumFiles, err := driver.GetAllAlbumFile(file.Id, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
files = make([]model.File, 0, len(albumFiles))
|
||||||
|
for _, file := range albumFiles {
|
||||||
|
var thumbnail string
|
||||||
|
if len(file.Thumburl) > 0 {
|
||||||
|
thumbnail = file.Thumburl[0]
|
||||||
|
}
|
||||||
|
files = append(files, model.File{
|
||||||
|
Id: joinID(file.Fsid, file.Uk, file.Tid),
|
||||||
|
Name: file.Name(),
|
||||||
|
Size: file.Size,
|
||||||
|
Type: utils.GetFileType(utils.Ext(file.Path)),
|
||||||
|
Driver: driver.Config().Name,
|
||||||
|
UpdatedAt: getTime(file.Mtime),
|
||||||
|
Thumbnail: thumbnail,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else if IsRoot(file) {
|
||||||
|
albums, err := driver.GetAllAlbum(account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
files = make([]model.File, 0, len(albums))
|
||||||
|
for _, album := range albums {
|
||||||
|
files = append(files, model.File{
|
||||||
|
Id: joinID(album.AlbumID, album.Tid),
|
||||||
|
Name: album.Title,
|
||||||
|
Size: 0,
|
||||||
|
Type: conf.FOLDER,
|
||||||
|
Driver: driver.Config().Name,
|
||||||
|
UpdatedAt: getTime(album.Mtime),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(files) > 0 {
|
||||||
|
_ = base.SetCache(path, files, account)
|
||||||
|
}
|
||||||
|
return files, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
|
if account.InternalType == "file" {
|
||||||
|
return driver.LinkFile(args, account)
|
||||||
|
}
|
||||||
|
return driver.LinkAlbum(args, account)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) LinkAlbum(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
|
file, err := driver.File(args.Path, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !IsAlbumFile(file) {
|
||||||
|
return nil, base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
album, err := driver.File(utils.Dir(utils.ParsePath(args.Path)), account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
e := splitID(file.Id)
|
||||||
|
res, err := base.NoRedirectClient.R().
|
||||||
|
SetQueryParams(map[string]string{
|
||||||
|
"access_token": account.AccessToken,
|
||||||
|
"album_id": splitID(album.Id)[0],
|
||||||
|
"tid": e[2],
|
||||||
|
"fsid": e[0],
|
||||||
|
"uk": e[1],
|
||||||
|
}).
|
||||||
|
Head(ALBUM_API_URL + "/download")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &base.Link{
|
||||||
|
Headers: []base.Header{
|
||||||
|
{Name: "User-Agent", Value: base.UserAgent},
|
||||||
|
},
|
||||||
|
Url: res.Header().Get("location"),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) LinkFile(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
|
file, err := driver.File(args.Path, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !IsAlbumFile(file) {
|
||||||
|
return nil, base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
album, err := driver.File(utils.Dir(utils.ParsePath(args.Path)), account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 拷贝到根目录
|
||||||
|
cfile, err := driver.CopyAlbumFile(album.Id, account, file.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := driver.Request(http.MethodGet, FILE_API_URL_V2+"/download", func(r *resty.Request) {
|
||||||
|
r.SetQueryParams(map[string]string{
|
||||||
|
"fsid": fmt.Sprint(cfile.Fsid),
|
||||||
|
})
|
||||||
|
}, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &base.Link{
|
||||||
|
Headers: []base.Header{
|
||||||
|
{Name: "User-Agent", Value: base.UserAgent},
|
||||||
|
},
|
||||||
|
Url: utils.Json.Get(res.Body(), "dlink").ToString(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Path(path string, account *model.Account) (*model.File, []model.File, error) {
|
||||||
|
path = utils.ParsePath(path)
|
||||||
|
file, err := driver.File(path, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if !file.IsDir() {
|
||||||
|
return file, nil, nil
|
||||||
|
}
|
||||||
|
files, err := driver.Files(path, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
return nil, files, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Preview(path string, account *model.Account) (interface{}, error) {
|
||||||
|
return nil, base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if IsAlbum(srcFile) {
|
||||||
|
return driver.SetAlbumName(srcFile.Id, utils.Base(dst), account)
|
||||||
|
}
|
||||||
|
return base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) MakeDir(path string, account *model.Account) error {
|
||||||
|
dir, name := utils.Split(path)
|
||||||
|
parentFile, err := driver.File(dir, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !IsRoot(parentFile) {
|
||||||
|
return base.ErrNotSupport
|
||||||
|
}
|
||||||
|
return driver.CreateAlbum(name, account)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Move(src string, dst string, account *model.Account) error {
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if IsAlbumFile(srcFile) {
|
||||||
|
// 移动相册文件
|
||||||
|
dstAlbum, err := driver.File(utils.Dir(dst), account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !IsAlbum(dstAlbum) {
|
||||||
|
return base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
srcAlbum, err := driver.File(utils.Dir(src), account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
newFile, err := driver.CopyAlbumFile(srcAlbum.Id, account, srcFile.Id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = driver.DeleteAlbumFile(srcAlbum.Id, account, srcFile.Id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = driver.AddAlbumFile(dstAlbum.Id, account, joinID(newFile.Fsid))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Copy(src string, dst string, account *model.Account) error {
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if IsAlbumFile(srcFile) {
|
||||||
|
// 复制相册文件
|
||||||
|
dstAlbum, err := driver.File(utils.Dir(dst), account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !IsAlbum(dstAlbum) {
|
||||||
|
return base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
srcAlbum, err := driver.File(utils.Dir(src), account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
newFile, err := driver.CopyAlbumFile(srcAlbum.Id, account, srcFile.Id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = driver.AddAlbumFile(dstAlbum.Id, account, joinID(newFile.Fsid))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Delete(path string, account *model.Account) error {
|
||||||
|
file, err := driver.File(path, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除相册
|
||||||
|
if IsAlbum(file) {
|
||||||
|
return driver.DeleteAlbum(file.Id, account)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成相册文件
|
||||||
|
if IsAlbumFile(file) {
|
||||||
|
// 删除相册文件
|
||||||
|
album, err := driver.File(utils.Dir(path), account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return driver.DeleteAlbumFile(album.Id, account, file.Id)
|
||||||
|
}
|
||||||
|
return base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) Upload(file *model.FileStream, account *model.Account) error {
|
||||||
|
if file == nil {
|
||||||
|
return base.ErrEmptyFile
|
||||||
|
}
|
||||||
|
|
||||||
|
parentFile, err := driver.File(file.ParentPath, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !IsAlbum(parentFile) {
|
||||||
|
return base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
tempFile.Close()
|
||||||
|
os.Remove(tempFile.Name())
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 计算需要的数据
|
||||||
|
const DEFAULT = 1 << 22
|
||||||
|
const SliceSize = 1 << 18
|
||||||
|
count := int(math.Ceil(float64(file.Size) / float64(DEFAULT)))
|
||||||
|
|
||||||
|
sliceMD5List := make([]string, 0, count)
|
||||||
|
fileMd5 := md5.New()
|
||||||
|
sliceMd5 := md5.New()
|
||||||
|
for i := 1; i <= count; i++ {
|
||||||
|
if n, err := io.CopyN(io.MultiWriter(fileMd5, sliceMd5, tempFile), file, DEFAULT); err != io.EOF && n == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sliceMD5List = append(sliceMD5List, hex.EncodeToString(sliceMd5.Sum(nil)))
|
||||||
|
sliceMd5.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = tempFile.Seek(0, io.SeekStart); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
content_md5 := hex.EncodeToString(fileMd5.Sum(nil))
|
||||||
|
slice_md5 := content_md5
|
||||||
|
if file.GetSize() > SliceSize {
|
||||||
|
sliceData := make([]byte, SliceSize)
|
||||||
|
if _, err = io.ReadFull(tempFile, sliceData); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sliceMd5.Write(sliceData)
|
||||||
|
slice_md5 = hex.EncodeToString(sliceMd5.Sum(nil))
|
||||||
|
if _, err = tempFile.Seek(0, io.SeekStart); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始执行上传
|
||||||
|
params := map[string]string{
|
||||||
|
"autoinit": "1",
|
||||||
|
"isdir": "0",
|
||||||
|
"rtype": "1",
|
||||||
|
"ctype": "11",
|
||||||
|
"path": utils.ParsePath(file.Name),
|
||||||
|
"size": fmt.Sprint(file.Size),
|
||||||
|
"slice-md5": slice_md5,
|
||||||
|
"content-md5": content_md5,
|
||||||
|
"block_list": MustString(utils.Json.MarshalToString(sliceMD5List)),
|
||||||
|
}
|
||||||
|
|
||||||
|
// 预上传
|
||||||
|
var precreateResp PrecreateResp
|
||||||
|
_, err = driver.Request(http.MethodPost, FILE_API_URL_V1+"/precreate", func(r *resty.Request) {
|
||||||
|
r.SetFormData(params)
|
||||||
|
r.SetResult(&precreateResp)
|
||||||
|
}, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch precreateResp.ReturnType {
|
||||||
|
case 1: // 上传文件
|
||||||
|
uploadParams := map[string]string{
|
||||||
|
"method": "upload",
|
||||||
|
"path": params["path"],
|
||||||
|
"uploadid": precreateResp.UploadID,
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
|
uploadParams["partseq"] = fmt.Sprint(i)
|
||||||
|
_, err = driver.Request(http.MethodPost, "https://c3.pcs.baidu.com/rest/2.0/pcs/superfile2", func(r *resty.Request) {
|
||||||
|
r.SetQueryParams(uploadParams)
|
||||||
|
r.SetFileReader("file", file.Name, io.LimitReader(tempFile, DEFAULT))
|
||||||
|
}, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
case 2: // 创建文件
|
||||||
|
params["uploadid"] = precreateResp.UploadID
|
||||||
|
_, err = driver.Request(http.MethodPost, FILE_API_URL_V1+"/create", func(r *resty.Request) {
|
||||||
|
r.SetFormData(params)
|
||||||
|
r.SetResult(&precreateResp)
|
||||||
|
}, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
case 3: // 增加到相册
|
||||||
|
err = driver.AddAlbumFile(parentFile.Id, account, joinID(precreateResp.Data.FsID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ base.Driver = (*Baidu)(nil)
|
126
drivers/baiduphoto/types.go
Normal file
126
drivers/baiduphoto/types.go
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
package baiduphoto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TokenErrResp struct {
|
||||||
|
ErrorDescription string `json:"error_description"`
|
||||||
|
ErrorMsg string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *TokenErrResp) Error() string {
|
||||||
|
return fmt.Sprint(e.ErrorMsg, " : ", e.ErrorDescription)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Erron struct {
|
||||||
|
Errno int `json:"errno"`
|
||||||
|
RequestID int `json:"request_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Page struct {
|
||||||
|
HasMore int `json:"has_more"`
|
||||||
|
Cursor string `json:"cursor"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Page) HasNextPage() bool {
|
||||||
|
return p.HasMore == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
FileListResp struct {
|
||||||
|
Page
|
||||||
|
List []File `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
File struct {
|
||||||
|
Fsid int64 `json:"fsid"` // 文件ID
|
||||||
|
Path string `json:"path"` // 文件路径
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
Ctime int64 `json:"ctime"` // 创建时间 s
|
||||||
|
Mtime int64 `json:"mtime"` // 修改时间 s
|
||||||
|
Thumburl []string `json:"thumburl"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (f File) Name() string {
|
||||||
|
return utils.Base(f.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*相册部分*/
|
||||||
|
type (
|
||||||
|
AlbumListResp struct {
|
||||||
|
Page
|
||||||
|
List []Album `json:"list"`
|
||||||
|
Reset int64 `json:"reset"`
|
||||||
|
TotalCount int64 `json:"total_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
Album struct {
|
||||||
|
AlbumID string `json:"album_id"`
|
||||||
|
Tid int64 `json:"tid"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
JoinTime int64 `json:"join_time"`
|
||||||
|
CreateTime int64 `json:"create_time"`
|
||||||
|
Mtime int64 `json:"mtime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumFileListResp struct {
|
||||||
|
Page
|
||||||
|
List []AlbumFile `json:"list"`
|
||||||
|
Reset int64 `json:"reset"`
|
||||||
|
TotalCount int64 `json:"total_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumFile struct {
|
||||||
|
File
|
||||||
|
Tid int64 `json:"tid"`
|
||||||
|
Uk int64 `json:"uk"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
CopyFileResp struct {
|
||||||
|
List []CopyFile `json:"list"`
|
||||||
|
}
|
||||||
|
CopyFile struct {
|
||||||
|
FromFsid int64 `json:"from_fsid"` // 源ID
|
||||||
|
Fsid int64 `json:"fsid"` // 目标ID
|
||||||
|
Path string `json:"path"`
|
||||||
|
ShootTime int `json:"shoot_time"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
/*上传部分*/
|
||||||
|
type (
|
||||||
|
UploadFile struct {
|
||||||
|
FsID int64 `json:"fs_id"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
Md5 string `json:"md5"`
|
||||||
|
ServerFilename string `json:"server_filename"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Ctime int `json:"ctime"`
|
||||||
|
Mtime int `json:"mtime"`
|
||||||
|
Isdir int `json:"isdir"`
|
||||||
|
Category int `json:"category"`
|
||||||
|
ServerMd5 string `json:"server_md5"`
|
||||||
|
ShootTime int `json:"shoot_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateFileResp struct {
|
||||||
|
Data UploadFile `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
PrecreateResp struct {
|
||||||
|
ReturnType int `json:"return_type"` //存在返回2 不存在返回1 已经保存3
|
||||||
|
//存在返回
|
||||||
|
CreateFileResp
|
||||||
|
|
||||||
|
//不存在返回
|
||||||
|
Path string `json:"path"`
|
||||||
|
UploadID string `json:"uploadid"`
|
||||||
|
Blocklist []int64 `json:"block_list"`
|
||||||
|
}
|
||||||
|
)
|
84
drivers/baiduphoto/util.go
Normal file
84
drivers/baiduphoto/util.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package baiduphoto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"math/rand"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Xhofe/alist/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
API_URL = "https://photo.baidu.com/youai"
|
||||||
|
ALBUM_API_URL = API_URL + "/album/v1"
|
||||||
|
FILE_API_URL_V1 = API_URL + "/file/v1"
|
||||||
|
FILE_API_URL_V2 = API_URL + "/file/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNotSupportName = errors.New("only chinese and english, numbers and underscores are supported, and the length is no more than 20")
|
||||||
|
)
|
||||||
|
|
||||||
|
//Tid生成
|
||||||
|
func getTid() string {
|
||||||
|
return fmt.Sprintf("3%d%.0f", time.Now().Unix(), math.Floor(9000000*rand.Float64()+1000000))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查名称
|
||||||
|
func checkName(name string) bool {
|
||||||
|
return len(name) <= 20 && regexp.MustCompile("[\u4e00-\u9fa5A-Za-z0-9_]").MatchString(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTime(t int64) *time.Time {
|
||||||
|
tm := time.Unix(t, 0)
|
||||||
|
return &tm
|
||||||
|
}
|
||||||
|
|
||||||
|
func fsidsFormat(ids ...string) string {
|
||||||
|
var buf []string
|
||||||
|
for _, id := range ids {
|
||||||
|
e := strings.Split(id, "|")
|
||||||
|
buf = append(buf, fmt.Sprintf("{\"fsid\":%s,\"uk\":%s}", e[0], e[1]))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("[%s]", strings.Join(buf, ","))
|
||||||
|
}
|
||||||
|
|
||||||
|
func fsidsFormatNotUk(ids ...string) string {
|
||||||
|
var buf []string
|
||||||
|
for _, id := range ids {
|
||||||
|
buf = append(buf, fmt.Sprintf("{\"fsid\":%s}", strings.Split(id, "|")[0]))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("[%s]", strings.Join(buf, ","))
|
||||||
|
}
|
||||||
|
|
||||||
|
func splitID(id string) []string {
|
||||||
|
return strings.SplitN(id, "|", 3)[:3]
|
||||||
|
}
|
||||||
|
|
||||||
|
func joinID(ids ...interface{}) string {
|
||||||
|
idsStr := make([]string, 0, len(ids))
|
||||||
|
for _, id := range ids {
|
||||||
|
idsStr = append(idsStr, fmt.Sprint(id))
|
||||||
|
}
|
||||||
|
return strings.Join(idsStr, "|")
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsAlbum(file *model.File) bool {
|
||||||
|
return file.Id != "" && file.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsAlbumFile(file *model.File) bool {
|
||||||
|
return file.Id != "" && !file.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsRoot(file *model.File) bool {
|
||||||
|
return file.Id == "" && file.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
func MustString(str string, err error) string {
|
||||||
|
return str
|
||||||
|
}
|
61
drivers/base/base.go
Normal file
61
drivers/base/base.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package base
|
||||||
|
|
||||||
|
import "github.com/Xhofe/alist/model"
|
||||||
|
|
||||||
|
type Base struct{}
|
||||||
|
|
||||||
|
func (b Base) Config() DriverConfig {
|
||||||
|
return DriverConfig{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Items() []Item {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Save(account *model.Account, old *model.Account) error {
|
||||||
|
return ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) File(path string, account *model.Account) (*model.File, error) {
|
||||||
|
return nil, ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Files(path string, account *model.Account) ([]model.File, error) {
|
||||||
|
return nil, ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Link(args Args, account *model.Account) (*Link, error) {
|
||||||
|
return nil, ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Path(path string, account *model.Account) (*model.File, []model.File, error) {
|
||||||
|
return nil, nil, ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Preview(path string, account *model.Account) (interface{}, error) {
|
||||||
|
return nil, ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) MakeDir(path string, account *model.Account) error {
|
||||||
|
return ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Move(src string, dst string, account *model.Account) error {
|
||||||
|
return ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
return ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Copy(src string, dst string, account *model.Account) error {
|
||||||
|
return ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Delete(path string, account *model.Account) error {
|
||||||
|
return ErrNotImplement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Base) Upload(file *model.FileStream, account *model.Account) error {
|
||||||
|
return ErrNotImplement
|
||||||
|
}
|
@ -227,13 +227,21 @@ func (driver FTP) Copy(src string, dst string, account *model.Account) error {
|
|||||||
|
|
||||||
func (driver FTP) Delete(path string, account *model.Account) error {
|
func (driver FTP) Delete(path string, account *model.Account) error {
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
|
file, err := driver.File(path, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
realPath := utils.Join(account.RootFolder, path)
|
realPath := utils.Join(account.RootFolder, path)
|
||||||
conn, err := driver.Login(account)
|
conn, err := driver.Login(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//defer func() { _ = conn.Quit() }()
|
//defer func() { _ = conn.Quit() }()
|
||||||
err = conn.Delete(realPath)
|
if file.IsDir() {
|
||||||
|
err = conn.RemoveDirRecur(realPath)
|
||||||
|
} else {
|
||||||
|
err = conn.Delete(realPath)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,8 +307,10 @@ func (driver Onedrive) UploadBig(file *model.FileStream, account *model.Account)
|
|||||||
res, err := base.HttpClient.Do(req)
|
res, err := base.HttpClient.Do(req)
|
||||||
if res.StatusCode != 201 && res.StatusCode != 202 {
|
if res.StatusCode != 201 && res.StatusCode != 202 {
|
||||||
data, _ := ioutil.ReadAll(res.Body)
|
data, _ := ioutil.ReadAll(res.Body)
|
||||||
|
res.Body.Close()
|
||||||
return errors.New(string(data))
|
return errors.New(string(data))
|
||||||
}
|
}
|
||||||
|
res.Body.Close()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -51,37 +51,37 @@ type SortResp struct {
|
|||||||
type DownResp struct {
|
type DownResp struct {
|
||||||
Resp
|
Resp
|
||||||
Data []struct {
|
Data []struct {
|
||||||
Fid string `json:"fid"`
|
//Fid string `json:"fid"`
|
||||||
FileName string `json:"file_name"`
|
//FileName string `json:"file_name"`
|
||||||
PdirFid string `json:"pdir_fid"`
|
//PdirFid string `json:"pdir_fid"`
|
||||||
Category int `json:"category"`
|
//Category int `json:"category"`
|
||||||
FileType int `json:"file_type"`
|
//FileType int `json:"file_type"`
|
||||||
Size int `json:"size"`
|
//Size int `json:"size"`
|
||||||
FormatType string `json:"format_type"`
|
//FormatType string `json:"format_type"`
|
||||||
Status int `json:"status"`
|
//Status int `json:"status"`
|
||||||
Tags string `json:"tags"`
|
//Tags string `json:"tags"`
|
||||||
LCreatedAt int64 `json:"l_created_at"`
|
//LCreatedAt int64 `json:"l_created_at"`
|
||||||
LUpdatedAt int64 `json:"l_updated_at"`
|
//LUpdatedAt int64 `json:"l_updated_at"`
|
||||||
NameSpace int `json:"name_space"`
|
//NameSpace int `json:"name_space"`
|
||||||
Thumbnail string `json:"thumbnail"`
|
//Thumbnail string `json:"thumbnail"`
|
||||||
DownloadUrl string `json:"download_url"`
|
DownloadUrl string `json:"download_url"`
|
||||||
Md5 string `json:"md5"`
|
//Md5 string `json:"md5"`
|
||||||
RiskType int `json:"risk_type"`
|
//RiskType int `json:"risk_type"`
|
||||||
RangeSize int `json:"range_size"`
|
//RangeSize int `json:"range_size"`
|
||||||
BackupSign int `json:"backup_sign"`
|
//BackupSign int `json:"backup_sign"`
|
||||||
ObjCategory string `json:"obj_category"`
|
//ObjCategory string `json:"obj_category"`
|
||||||
Duration int `json:"duration"`
|
//Duration int `json:"duration"`
|
||||||
FileSource string `json:"file_source"`
|
//FileSource string `json:"file_source"`
|
||||||
File bool `json:"file"`
|
//File bool `json:"file"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
//CreatedAt int64 `json:"created_at"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
//UpdatedAt int64 `json:"updated_at"`
|
||||||
PrivateExtra struct {
|
//PrivateExtra struct {
|
||||||
} `json:"_private_extra"`
|
//} `json:"_private_extra"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
Metadata struct {
|
//Metadata struct {
|
||||||
Acc2 string `json:"acc2"`
|
// Acc2 string `json:"acc2"`
|
||||||
Acc1 string `json:"acc1"`
|
// Acc1 string `json:"acc1"`
|
||||||
} `json:"metadata"`
|
//} `json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpPreResp struct {
|
type UpPreResp struct {
|
||||||
|
@ -116,7 +116,7 @@ func (driver SFTP) Files(path string, account *model.Account) ([]model.File, err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var files []model.File
|
files := make([]model.File, 0)
|
||||||
rawFiles, err := client.Files(remotePath)
|
rawFiles, err := client.Files(remotePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Template struct {
|
type Template struct {
|
||||||
|
base.Base
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Template) Config() base.DriverConfig {
|
func (driver Template) Config() base.DriverConfig {
|
||||||
@ -111,39 +112,40 @@ func (driver Template) Path(path string, account *model.Account) (*model.File, [
|
|||||||
return nil, files, nil
|
return nil, files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Template) Preview(path string, account *model.Account) (interface{}, error) {
|
// Optional function
|
||||||
//TODO preview interface if driver support
|
//func (driver Template) Preview(path string, account *model.Account) (interface{}, error) {
|
||||||
return nil, base.ErrNotImplement
|
// //TODO preview interface if driver support
|
||||||
}
|
// return nil, base.ErrNotImplement
|
||||||
|
//}
|
||||||
func (driver Template) MakeDir(path string, account *model.Account) error {
|
//
|
||||||
//TODO make dir
|
//func (driver Template) MakeDir(path string, account *model.Account) error {
|
||||||
return base.ErrNotImplement
|
// //TODO make dir
|
||||||
}
|
// return base.ErrNotImplement
|
||||||
|
//}
|
||||||
func (driver Template) Move(src string, dst string, account *model.Account) error {
|
//
|
||||||
//TODO move file/dir
|
//func (driver Template) Move(src string, dst string, account *model.Account) error {
|
||||||
return base.ErrNotImplement
|
// //TODO move file/dir
|
||||||
}
|
// return base.ErrNotImplement
|
||||||
|
//}
|
||||||
func (driver Template) Rename(src string, dst string, account *model.Account) error {
|
//
|
||||||
//TODO rename file/dir
|
//func (driver Template) Rename(src string, dst string, account *model.Account) error {
|
||||||
return base.ErrNotImplement
|
// //TODO rename file/dir
|
||||||
}
|
// return base.ErrNotImplement
|
||||||
|
//}
|
||||||
func (driver Template) Copy(src string, dst string, account *model.Account) error {
|
//
|
||||||
//TODO copy file/dir
|
//func (driver Template) Copy(src string, dst string, account *model.Account) error {
|
||||||
return base.ErrNotImplement
|
// //TODO copy file/dir
|
||||||
}
|
// return base.ErrNotImplement
|
||||||
|
//}
|
||||||
func (driver Template) Delete(path string, account *model.Account) error {
|
//
|
||||||
//TODO delete file/dir
|
//func (driver Template) Delete(path string, account *model.Account) error {
|
||||||
return base.ErrNotImplement
|
// //TODO delete file/dir
|
||||||
}
|
// return base.ErrNotImplement
|
||||||
|
//}
|
||||||
func (driver Template) Upload(file *model.FileStream, account *model.Account) error {
|
//
|
||||||
//TODO upload file
|
//func (driver Template) Upload(file *model.FileStream, account *model.Account) error {
|
||||||
return base.ErrNotImplement
|
// //TODO upload file
|
||||||
}
|
// return base.ErrNotImplement
|
||||||
|
//}
|
||||||
|
|
||||||
var _ base.Driver = (*Template)(nil)
|
var _ base.Driver = (*Template)(nil)
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
package xunlei
|
package xunlei
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
"time"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
|
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type XunLeiCloud struct{}
|
type XunLeiCloud struct{}
|
||||||
@ -48,8 +48,61 @@ func (driver XunLeiCloud) Items() []base.Item {
|
|||||||
Description: "account password",
|
Description: "account password",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "root_folder",
|
Name: "captcha_token",
|
||||||
Label: "root folder file_id",
|
Label: "verified captcha token",
|
||||||
|
Type: base.TypeString,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "root_folder",
|
||||||
|
Label: "root folder file_id",
|
||||||
|
Type: base.TypeString,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "client_version",
|
||||||
|
Label: "client version",
|
||||||
|
Default: "7.43.0.7998",
|
||||||
|
Type: base.TypeString,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "client_id",
|
||||||
|
Label: "client id",
|
||||||
|
Default: "Xp6vsxz_7IYVw2BB",
|
||||||
|
Type: base.TypeString,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "client_secret",
|
||||||
|
Label: "client secret",
|
||||||
|
Default: "Xp6vsy4tN9toTVdMSpomVdXpRmES",
|
||||||
|
Type: base.TypeString,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "algorithms",
|
||||||
|
Label: "algorithms",
|
||||||
|
Default: "hrVPGbeqYPs+CIscj05VpAtjalzY5yjpvlMS8bEo,DrI0uTP,HHK0VXyMgY0xk2K0o,BBaXsExvL3GadmIacjWv7ISUJp3ifAwqbJumu,5toJ7ejB+bh1,5LsZTFAFjgvFvIl1URBgOAJ,QcJ5Ry+,hYgZVz8r7REROaCYfd9,zw6gXgkk/8TtGrmx6EGfekPESLnbZfDFwqR,gtSwLnMBa8h12nF3DU6+LwEQPHxd,fMG8TvtAYbCkxuEbIm0Xi/Lb7Z",
|
||||||
|
Type: base.TypeString,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "package_name",
|
||||||
|
Label: "package name",
|
||||||
|
Default: "com.xunlei.downloadprovider",
|
||||||
|
Type: base.TypeString,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "user_agent",
|
||||||
|
Label: "user agent",
|
||||||
|
Default: "ANDROID-com.xunlei.downloadprovider/7.43.0.7998 netWorkType/WIFI appid/40 deviceName/Samsung_Sm-g9810 deviceModel/SM-G9810 OSVersion/7.1.2 protocolVersion/301 platformVersion/10 sdkVersion/220200 Oauth2Client/0.9 (Linux 4_0_9+) (JAVA 0)",
|
||||||
|
Type: base.TypeString,
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "device_id",
|
||||||
|
Label: "device id",
|
||||||
|
Default: utils.GetMD5Encode(uuid.NewString()),
|
||||||
Type: base.TypeString,
|
Type: base.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
@ -60,10 +113,18 @@ func (driver XunLeiCloud) Save(account *model.Account, old *model.Account) error
|
|||||||
if account == nil {
|
if account == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
state := GetState(account)
|
|
||||||
if state.isTokensExpires() {
|
client := GetClient(account)
|
||||||
return state.Login(account)
|
// 指定验证通过的captchaToken
|
||||||
|
if account.CaptchaToken != "" {
|
||||||
|
client.UpdateCaptchaToken(strings.TrimSpace(account.CaptchaToken))
|
||||||
|
account.CaptchaToken = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if client.token == "" {
|
||||||
|
return client.Login(account)
|
||||||
|
}
|
||||||
|
|
||||||
account.Status = "work"
|
account.Status = "work"
|
||||||
model.SaveAccount(account)
|
model.SaveAccount(account)
|
||||||
return nil
|
return nil
|
||||||
@ -101,19 +162,23 @@ func (driver XunLeiCloud) Files(path string, account *model.Account) ([]model.Fi
|
|||||||
files, _ := cache.([]model.File)
|
files, _ := cache.([]model.File)
|
||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
file, err := driver.File(path, account)
|
|
||||||
|
parentFile, err := driver.File(path, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * 300)
|
||||||
files := make([]model.File, 0)
|
files := make([]model.File, 0)
|
||||||
|
var pageToken string
|
||||||
for {
|
for {
|
||||||
var fileList FileList
|
var fileList FileList
|
||||||
_, err = GetState(account).Request("GET", FILE_API_URL, func(r *resty.Request) {
|
_, err = GetClient(account).Request("GET", FILE_API_URL, func(r *resty.Request) {
|
||||||
r.SetQueryParams(map[string]string{
|
r.SetQueryParams(map[string]string{
|
||||||
"parent_id": file.Id,
|
"parent_id": parentFile.Id,
|
||||||
"page_token": fileList.NextPageToken,
|
"page_token": pageToken,
|
||||||
"with_audit": "true",
|
"with_audit": "true",
|
||||||
|
"limit": "100",
|
||||||
"filters": `{"phase": {"eq": "PHASE_TYPE_COMPLETE"}, "trashed":{"eq":false}}`,
|
"filters": `{"phase": {"eq": "PHASE_TYPE_COMPLETE"}, "trashed":{"eq":false}}`,
|
||||||
})
|
})
|
||||||
r.SetResult(&fileList)
|
r.SetResult(&fileList)
|
||||||
@ -129,6 +194,7 @@ func (driver XunLeiCloud) Files(path string, account *model.Account) ([]model.Fi
|
|||||||
if fileList.NextPageToken == "" {
|
if fileList.NextPageToken == "" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
pageToken = fileList.NextPageToken
|
||||||
}
|
}
|
||||||
if len(files) > 0 {
|
if len(files) > 0 {
|
||||||
_ = base.SetCache(path, files, account)
|
_ = base.SetCache(path, files, account)
|
||||||
@ -162,8 +228,9 @@ func (driver XunLeiCloud) Link(args base.Args, account *model.Account) (*base.Li
|
|||||||
return nil, base.ErrNotFile
|
return nil, base.ErrNotFile
|
||||||
}
|
}
|
||||||
var lFile Files
|
var lFile Files
|
||||||
_, err = GetState(account).Request("GET", FILE_API_URL+"/{id}", func(r *resty.Request) {
|
clinet := GetClient(account)
|
||||||
r.SetPathParam("id", file.Id)
|
_, err = clinet.Request("GET", FILE_API_URL+"/{fileID}", func(r *resty.Request) {
|
||||||
|
r.SetPathParam("fileID", file.Id)
|
||||||
r.SetQueryParam("with_audit", "true")
|
r.SetQueryParam("with_audit", "true")
|
||||||
r.SetResult(&lFile)
|
r.SetResult(&lFile)
|
||||||
}, account)
|
}, account)
|
||||||
@ -172,7 +239,7 @@ func (driver XunLeiCloud) Link(args base.Args, account *model.Account) (*base.Li
|
|||||||
}
|
}
|
||||||
return &base.Link{
|
return &base.Link{
|
||||||
Headers: []base.Header{
|
Headers: []base.Header{
|
||||||
{Name: "User-Agent", Value: base.UserAgent},
|
{Name: "User-Agent", Value: clinet.userAgent},
|
||||||
},
|
},
|
||||||
Url: lFile.WebContentLink,
|
Url: lFile.WebContentLink,
|
||||||
}, nil
|
}, nil
|
||||||
@ -180,7 +247,6 @@ func (driver XunLeiCloud) Link(args base.Args, account *model.Account) (*base.Li
|
|||||||
|
|
||||||
func (driver XunLeiCloud) Path(path string, account *model.Account) (*model.File, []model.File, error) {
|
func (driver XunLeiCloud) Path(path string, account *model.Account) (*model.File, []model.File, error) {
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
log.Debugf("xunlei path: %s", path)
|
|
||||||
file, err := driver.File(path, account)
|
file, err := driver.File(path, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -199,6 +265,18 @@ func (driver XunLeiCloud) Preview(path string, account *model.Account) (interfac
|
|||||||
return nil, base.ErrNotSupport
|
return nil, base.ErrNotSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver XunLeiCloud) Rename(src string, dst string, account *model.Account) error {
|
||||||
|
srcFile, err := driver.File(src, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = GetClient(account).Request("PATCH", FILE_API_URL+"/{fileID}", func(r *resty.Request) {
|
||||||
|
r.SetPathParam("fileID", srcFile.Id)
|
||||||
|
r.SetBody(&base.Json{"name": filepath.Base(dst)})
|
||||||
|
}, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (driver XunLeiCloud) MakeDir(path string, account *model.Account) error {
|
func (driver XunLeiCloud) MakeDir(path string, account *model.Account) error {
|
||||||
dir, name := filepath.Split(path)
|
dir, name := filepath.Split(path)
|
||||||
parentFile, err := driver.File(dir, account)
|
parentFile, err := driver.File(dir, account)
|
||||||
@ -208,7 +286,7 @@ func (driver XunLeiCloud) MakeDir(path string, account *model.Account) error {
|
|||||||
if !parentFile.IsDir() {
|
if !parentFile.IsDir() {
|
||||||
return base.ErrNotFolder
|
return base.ErrNotFolder
|
||||||
}
|
}
|
||||||
_, err = GetState(account).Request("POST", FILE_API_URL, func(r *resty.Request) {
|
_, err = GetClient(account).Request("POST", FILE_API_URL, func(r *resty.Request) {
|
||||||
r.SetBody(&base.Json{
|
r.SetBody(&base.Json{
|
||||||
"kind": FOLDER,
|
"kind": FOLDER,
|
||||||
"name": name,
|
"name": name,
|
||||||
@ -229,7 +307,7 @@ func (driver XunLeiCloud) Move(src string, dst string, account *model.Account) e
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = GetState(account).Request("POST", FILE_API_URL+":batchMove", func(r *resty.Request) {
|
_, err = GetClient(account).Request("POST", FILE_API_URL+":batchMove", func(r *resty.Request) {
|
||||||
r.SetBody(&base.Json{
|
r.SetBody(&base.Json{
|
||||||
"to": base.Json{"parent_id": dstDirFile.Id},
|
"to": base.Json{"parent_id": dstDirFile.Id},
|
||||||
"ids": []string{srcFile.Id},
|
"ids": []string{srcFile.Id},
|
||||||
@ -248,7 +326,7 @@ func (driver XunLeiCloud) Copy(src string, dst string, account *model.Account) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = GetState(account).Request("POST", FILE_API_URL+":batchCopy", func(r *resty.Request) {
|
_, err = GetClient(account).Request("POST", FILE_API_URL+":batchCopy", func(r *resty.Request) {
|
||||||
r.SetBody(&base.Json{
|
r.SetBody(&base.Json{
|
||||||
"to": base.Json{"parent_id": dstDirFile.Id},
|
"to": base.Json{"parent_id": dstDirFile.Id},
|
||||||
"ids": []string{srcFile.Id},
|
"ids": []string{srcFile.Id},
|
||||||
@ -262,8 +340,8 @@ func (driver XunLeiCloud) Delete(path string, account *model.Account) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = GetState(account).Request("PATCH", FILE_API_URL+"/{id}/trash", func(r *resty.Request) {
|
_, err = GetClient(account).Request("PATCH", FILE_API_URL+"/{fileID}/trash", func(r *resty.Request) {
|
||||||
r.SetPathParam("id", srcFile.Id)
|
r.SetPathParam("fileID", srcFile.Id)
|
||||||
r.SetBody(&base.Json{})
|
r.SetBody(&base.Json{})
|
||||||
}, account)
|
}, account)
|
||||||
return err
|
return err
|
||||||
@ -279,28 +357,33 @@ func (driver XunLeiCloud) Upload(file *model.FileStream, account *model.Account)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
/*
|
||||||
if err != nil {
|
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
defer os.Remove(tempFile.Name())
|
defer tempFile.Close()
|
||||||
|
defer os.Remove(tempFile.Name())
|
||||||
|
|
||||||
gcid, err := getGcid(io.TeeReader(file, tempFile), int64(file.Size))
|
gcid, err := getGcid(io.TeeReader(file, tempFile), int64(file.Size))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tempFile.Close()
|
if _, err = tempFile.Seek(0, io.SeekStart); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
var resp UploadTaskResponse
|
var resp UploadTaskResponse
|
||||||
_, err = GetState(account).Request("POST", FILE_API_URL, func(r *resty.Request) {
|
_, err = GetClient(account).Request("POST", FILE_API_URL, func(r *resty.Request) {
|
||||||
r.SetBody(&base.Json{
|
r.SetBody(&base.Json{
|
||||||
"kind": FILE,
|
"kind": FILE,
|
||||||
"parent_id": parentFile.Id,
|
"parent_id": parentFile.Id,
|
||||||
"name": file.Name,
|
"name": file.Name,
|
||||||
"size": fmt.Sprint(file.Size),
|
"size": file.Size,
|
||||||
"hash": gcid,
|
"hash": "1CF254FBC456E1B012CD45C546636AA62CF8350E",
|
||||||
"upload_type": UPLOAD_TYPE_RESUMABLE,
|
"upload_type": UPLOAD_TYPE_RESUMABLE,
|
||||||
})
|
})
|
||||||
r.SetResult(&resp)
|
r.SetResult(&resp)
|
||||||
@ -311,30 +394,24 @@ func (driver XunLeiCloud) Upload(file *model.FileStream, account *model.Account)
|
|||||||
|
|
||||||
param := resp.Resumable.Params
|
param := resp.Resumable.Params
|
||||||
if resp.UploadType == UPLOAD_TYPE_RESUMABLE {
|
if resp.UploadType == UPLOAD_TYPE_RESUMABLE {
|
||||||
client, err := oss.New(param.Endpoint, param.AccessKeyID, param.AccessKeySecret, oss.SecurityToken(param.SecurityToken), oss.EnableMD5(true))
|
param.Endpoint = strings.TrimLeft(param.Endpoint, param.Bucket+".")
|
||||||
|
s, err := session.NewSession(&aws.Config{
|
||||||
|
Credentials: credentials.NewStaticCredentials(param.AccessKeyID, param.AccessKeySecret, param.SecurityToken),
|
||||||
|
Region: aws.String("xunlei"),
|
||||||
|
Endpoint: aws.String(param.Endpoint),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bucket, err := client.Bucket(param.Bucket)
|
_, err = s3manager.NewUploader(s).Upload(&s3manager.UploadInput{
|
||||||
if err != nil {
|
Bucket: aws.String(param.Bucket),
|
||||||
return err
|
Key: aws.String(param.Key),
|
||||||
}
|
Expires: aws.Time(param.Expiration),
|
||||||
return bucket.UploadFile(param.Key, tempFile.Name(), 1<<22, oss.Routines(3), oss.Checkpoint(true, ""), oss.Expires(param.Expiration))
|
Body: file,
|
||||||
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver XunLeiCloud) Rename(src string, dst string, account *model.Account) error {
|
|
||||||
_, dstName := filepath.Split(dst)
|
|
||||||
srcFile, err := driver.File(src, account)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = GetState(account).Request("PATCH", FILE_API_URL+"/{id}", func(r *resty.Request) {
|
|
||||||
r.SetPathParam("id", srcFile.Id)
|
|
||||||
r.SetBody(&base.Json{"name": dstName})
|
|
||||||
}, account)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ base.Driver = (*XunLeiCloud)(nil)
|
var _ base.Driver = (*XunLeiCloud)(nil)
|
||||||
|
@ -1,23 +1,35 @@
|
|||||||
package xunlei
|
package xunlei
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Erron struct {
|
type Erron struct {
|
||||||
Error string `json:"error"`
|
|
||||||
ErrorCode int64 `json:"error_code"`
|
ErrorCode int64 `json:"error_code"`
|
||||||
|
ErrorMsg string `json:"error"`
|
||||||
ErrorDescription string `json:"error_description"`
|
ErrorDescription string `json:"error_description"`
|
||||||
// ErrorDetails interface{} `json:"error_details"`
|
// ErrorDetails interface{} `json:"error_details"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Erron) HasError() bool {
|
||||||
|
return e.ErrorCode != 0 || e.ErrorMsg != "" || e.ErrorDescription != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Erron) Error() string {
|
||||||
|
return fmt.Sprintf("ErrorCode: %d ,Error: %s ,ErrorDescription: %s ", e.ErrorCode, e.ErrorMsg, e.ErrorDescription)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 验证码Token
|
||||||
|
**/
|
||||||
type CaptchaTokenRequest struct {
|
type CaptchaTokenRequest struct {
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
CaptchaToken string `json:"captcha_token"`
|
CaptchaToken string `json:"captcha_token"`
|
||||||
ClientID string `json:"client_id"`
|
ClientID string `json:"client_id"`
|
||||||
DeviceID string `json:"device_id"`
|
DeviceID string `json:"device_id"`
|
||||||
Meta map[string]string `json:"meta"`
|
Meta map[string]string `json:"meta"`
|
||||||
//RedirectUri string `json:"redirect_uri"`
|
RedirectUri string `json:"redirect_uri"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CaptchaTokenResponse struct {
|
type CaptchaTokenResponse struct {
|
||||||
@ -26,6 +38,9 @@ type CaptchaTokenResponse struct {
|
|||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 登录
|
||||||
|
**/
|
||||||
type TokenResponse struct {
|
type TokenResponse struct {
|
||||||
TokenType string `json:"token_type"`
|
TokenType string `json:"token_type"`
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
@ -36,6 +51,10 @@ type TokenResponse struct {
|
|||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TokenResponse) Token() string {
|
||||||
|
return fmt.Sprint(t.TokenType, " ", t.AccessToken)
|
||||||
|
}
|
||||||
|
|
||||||
type SignInRequest struct {
|
type SignInRequest struct {
|
||||||
CaptchaToken string `json:"captcha_token"`
|
CaptchaToken string `json:"captcha_token"`
|
||||||
|
|
||||||
@ -46,6 +65,9 @@ type SignInRequest struct {
|
|||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 文件
|
||||||
|
**/
|
||||||
type FileList struct {
|
type FileList struct {
|
||||||
Kind string `json:"kind"`
|
Kind string `json:"kind"`
|
||||||
NextPageToken string `json:"next_page_token"`
|
NextPageToken string `json:"next_page_token"`
|
||||||
@ -116,6 +138,9 @@ type Files struct {
|
|||||||
//Collection interface{} `json:"collection"`
|
//Collection interface{} `json:"collection"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 上传
|
||||||
|
**/
|
||||||
type UploadTaskResponse struct {
|
type UploadTaskResponse struct {
|
||||||
UploadType string `json:"upload_type"`
|
UploadType string `json:"upload_type"`
|
||||||
|
|
||||||
|
@ -3,40 +3,10 @@ package xunlei
|
|||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/Xhofe/alist/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
// 小米浏览器
|
|
||||||
CLIENT_ID = "X7MtiU0Gb5YqWv-6"
|
|
||||||
CLIENT_SECRET = "84MYEih3Eeu2HF4RrGce3Q"
|
|
||||||
CLIENT_VERSION = "5.1.0.51045"
|
|
||||||
|
|
||||||
ALG_VERSION = "1"
|
|
||||||
PACKAGE_NAME = "com.xunlei.xcloud.lib"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Algorithms = []string{
|
|
||||||
"",
|
|
||||||
"BXza40wm+P4zw8rEFpHA",
|
|
||||||
"UfZLfKfYRmKTA0",
|
|
||||||
"OMBGVt/9Wcaln1XaBz",
|
|
||||||
"Jn217F4rk5FPPWyhoeV",
|
|
||||||
"w5OwkGo0pGpb0Xe/XZ5T3",
|
|
||||||
"5guM3DNiY4F78x49zQ97q75",
|
|
||||||
"QXwn4D2j884wJgrYXjGClM/IVrJX",
|
|
||||||
"NXBRosYvbHIm6w8vEB",
|
|
||||||
"2kZ8Ie1yW2ib4O2iAkNpJobP",
|
|
||||||
"11CoVJJQEc",
|
|
||||||
"xf3QWysVwnVsNv5DCxU+cgNT1rK",
|
|
||||||
"9eEfKkrqkfw",
|
|
||||||
"T78dnANexYRbiZy",
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
API_URL = "https://api-pan.xunlei.com/drive/v1"
|
API_URL = "https://api-pan.xunlei.com/drive/v1"
|
||||||
FILE_API_URL = API_URL + "/files"
|
FILE_API_URL = API_URL + "/files"
|
||||||
@ -44,9 +14,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FOLDER = "drive#folder"
|
FOLDER = "drive#folder"
|
||||||
FILE = "drive#file"
|
FILE = "drive#file"
|
||||||
|
|
||||||
RESUMABLE = "drive#resumable"
|
RESUMABLE = "drive#resumable"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,47 +26,32 @@ const (
|
|||||||
UPLOAD_TYPE_URL = "UPLOAD_TYPE_URL"
|
UPLOAD_TYPE_URL = "UPLOAD_TYPE_URL"
|
||||||
)
|
)
|
||||||
|
|
||||||
func captchaSign(driverID string, time int64) string {
|
|
||||||
str := fmt.Sprint(CLIENT_ID, CLIENT_VERSION, PACKAGE_NAME, driverID, time)
|
|
||||||
for _, algorithm := range Algorithms {
|
|
||||||
str = utils.GetMD5Encode(fmt.Sprint(str, algorithm))
|
|
||||||
}
|
|
||||||
return fmt.Sprint(ALG_VERSION, ".", str)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getAction(method string, u string) string {
|
func getAction(method string, u string) string {
|
||||||
c, _ := url.Parse(u)
|
c, _ := url.Parse(u)
|
||||||
return fmt.Sprint(method, ":", c.Path)
|
return method + ":" + c.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算文件Gcid
|
||||||
func getGcid(r io.Reader, size int64) (string, error) {
|
func getGcid(r io.Reader, size int64) (string, error) {
|
||||||
calcBlockSize := func(j int64) int64 {
|
calcBlockSize := func(j int64) int64 {
|
||||||
if j >= 0 && j <= 134217728 {
|
if j >= 0 && j <= 0x8000000 {
|
||||||
return 262144
|
return 0x40000
|
||||||
}
|
}
|
||||||
if j <= 134217728 || j > 268435456 {
|
if j <= 0x8000000 || j > 0x10000000 {
|
||||||
if j <= 268435456 || j > 536870912 {
|
if j <= 0x10000000 || j > 0x20000000 {
|
||||||
return 2097152
|
return 0x200000
|
||||||
}
|
}
|
||||||
return 1048576
|
return 0x100000
|
||||||
}
|
}
|
||||||
return 524288
|
return 0x80000
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
calcBlockSize := func(j int64) int64 {
|
|
||||||
psize := int64(0x40000)
|
|
||||||
for j/psize > 0x200 {
|
|
||||||
psize <<= 1
|
|
||||||
}
|
|
||||||
return psize
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
hash1 := sha1.New()
|
hash1 := sha1.New()
|
||||||
hash2 := sha1.New()
|
hash2 := sha1.New()
|
||||||
|
readSize := calcBlockSize(size)
|
||||||
for {
|
for {
|
||||||
hash2.Reset()
|
hash2.Reset()
|
||||||
if n, err := io.CopyN(hash2, r, calcBlockSize(size)); err != nil && n == 0 {
|
if n, err := io.CopyN(hash2, r, readSize); err != nil && n == 0 {
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package xunlei
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -13,281 +14,269 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var xunleiClient = resty.New().SetHeaders(map[string]string{"Accept": "application/json;charset=UTF-8"}).SetTimeout(base.DefaultTimeout)
|
// 缓存登录状态
|
||||||
|
var userClients sync.Map
|
||||||
|
|
||||||
// 一个账户只允许登陆一次
|
func GetClient(account *model.Account) *Client {
|
||||||
var userStateCache = struct {
|
if v, ok := userClients.Load(account.Username); ok {
|
||||||
|
return v.(*Client)
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &Client{
|
||||||
|
Client: base.RestyClient,
|
||||||
|
|
||||||
|
clientID: account.ClientId,
|
||||||
|
clientSecret: account.ClientSecret,
|
||||||
|
clientVersion: account.ClientVersion,
|
||||||
|
packageName: account.PackageName,
|
||||||
|
algorithms: strings.Split(account.Algorithms, ","),
|
||||||
|
userAgent: account.UserAgent,
|
||||||
|
deviceID: account.DeviceId,
|
||||||
|
}
|
||||||
|
userClients.Store(account.Username, client)
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
*resty.Client
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
States map[string]*State
|
|
||||||
}{States: make(map[string]*State)}
|
|
||||||
|
|
||||||
func GetState(account *model.Account) *State {
|
clientID string
|
||||||
userStateCache.Lock()
|
clientSecret string
|
||||||
defer userStateCache.Unlock()
|
clientVersion string
|
||||||
if v, ok := userStateCache.States[account.Username]; ok && v != nil {
|
packageName string
|
||||||
return v
|
algorithms []string
|
||||||
}
|
userAgent string
|
||||||
state := new(State).Init()
|
deviceID string
|
||||||
userStateCache.States[account.Username] = state
|
|
||||||
return state
|
captchaToken string
|
||||||
|
|
||||||
|
token string
|
||||||
|
refreshToken string
|
||||||
|
userID string
|
||||||
}
|
}
|
||||||
|
|
||||||
type State struct {
|
// 请求验证码token
|
||||||
sync.Mutex
|
func (c *Client) requestCaptchaToken(action string, meta map[string]string) error {
|
||||||
captchaToken string
|
param := CaptchaTokenRequest{
|
||||||
captchaTokenExpiresTime int64
|
|
||||||
|
|
||||||
tokenType string
|
|
||||||
accessToken string
|
|
||||||
refreshToken string
|
|
||||||
tokenExpiresTime int64 //Milli
|
|
||||||
|
|
||||||
userID string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *State) init() *State {
|
|
||||||
s.captchaToken = ""
|
|
||||||
s.captchaTokenExpiresTime = 0
|
|
||||||
s.tokenType = ""
|
|
||||||
s.accessToken = ""
|
|
||||||
s.refreshToken = ""
|
|
||||||
s.tokenExpiresTime = 0
|
|
||||||
s.userID = "0"
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *State) getToken(account *model.Account) (string, error) {
|
|
||||||
if s.isTokensExpires() {
|
|
||||||
if err := s.refreshToken_(account); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fmt.Sprint(s.tokenType, " ", s.accessToken), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *State) getCaptchaToken(action string, account *model.Account) (string, error) {
|
|
||||||
if s.isCaptchaTokenExpires() {
|
|
||||||
return s.newCaptchaToken(action, nil, account)
|
|
||||||
}
|
|
||||||
return s.captchaToken, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *State) isCaptchaTokenExpires() bool {
|
|
||||||
return time.Now().UnixMilli() >= s.captchaTokenExpiresTime || s.captchaToken == "" || s.tokenType == ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *State) isTokensExpires() bool {
|
|
||||||
return time.Now().UnixMilli() >= s.tokenExpiresTime || s.accessToken == ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *State) newCaptchaToken(action string, meta map[string]string, account *model.Account) (string, error) {
|
|
||||||
ctime := time.Now().UnixMilli()
|
|
||||||
driverID := utils.GetMD5Encode(account.Username)
|
|
||||||
creq := CaptchaTokenRequest{
|
|
||||||
Action: action,
|
Action: action,
|
||||||
CaptchaToken: s.captchaToken,
|
CaptchaToken: c.captchaToken,
|
||||||
ClientID: CLIENT_ID,
|
ClientID: c.clientID,
|
||||||
DeviceID: driverID,
|
DeviceID: c.deviceID,
|
||||||
Meta: map[string]string{
|
Meta: meta,
|
||||||
"captcha_sign": captchaSign(driverID, ctime),
|
RedirectUri: "xlaccsdk01://xunlei.com/callback?state=harbor",
|
||||||
"client_version": CLIENT_VERSION,
|
|
||||||
"package_name": PACKAGE_NAME,
|
|
||||||
"timestamp": fmt.Sprint(ctime),
|
|
||||||
"user_id": s.userID,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for k, v := range meta {
|
|
||||||
creq.Meta[k] = v
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var e Erron
|
var e Erron
|
||||||
var resp CaptchaTokenResponse
|
var resp CaptchaTokenResponse
|
||||||
_, err := xunleiClient.R().
|
_, err := c.Client.R().
|
||||||
SetBody(&creq).
|
SetBody(¶m).
|
||||||
SetError(&e).
|
SetError(&e).
|
||||||
SetResult(&resp).
|
SetResult(&resp).
|
||||||
SetHeader("X-Device-Id", driverID).
|
SetHeader("X-Device-Id", c.deviceID).
|
||||||
SetQueryParam("client_id", CLIENT_ID).
|
SetQueryParam("client_id", c.clientID).
|
||||||
Post(XLUSER_API_URL + "/shield/captcha/init")
|
Post(XLUSER_API_URL + "/shield/captcha/init")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
if e.ErrorCode != 0 {
|
if e.HasError() {
|
||||||
return "", fmt.Errorf("%s : %s", e.Error, e.ErrorDescription)
|
return &e
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Url != "" {
|
if resp.Url != "" {
|
||||||
return "", fmt.Errorf("需要验证验证码")
|
return fmt.Errorf("need verify:%s", resp.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.captchaTokenExpiresTime = (ctime + resp.ExpiresIn*1000) - 30000
|
if resp.CaptchaToken == "" {
|
||||||
s.captchaToken = resp.CaptchaToken
|
return fmt.Errorf("empty captchaToken")
|
||||||
return s.captchaToken, nil
|
}
|
||||||
|
c.captchaToken = resp.CaptchaToken
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) refreshToken_(account *model.Account) error {
|
// 验证码签名
|
||||||
var e Erron
|
func (c *Client) captchaSign(time string) string {
|
||||||
var resp TokenResponse
|
str := fmt.Sprint(c.clientID, c.clientVersion, c.packageName, c.deviceID, time)
|
||||||
_, err := xunleiClient.R().
|
for _, algorithm := range c.algorithms {
|
||||||
SetResult(&resp).SetError(&e).
|
str = utils.GetMD5Encode(str + algorithm)
|
||||||
SetBody(&base.Json{
|
|
||||||
"grant_type": "refresh_token",
|
|
||||||
"refresh_token": s.refreshToken,
|
|
||||||
"client_id": CLIENT_ID,
|
|
||||||
"client_secret": CLIENT_SECRET,
|
|
||||||
}).
|
|
||||||
SetHeader("X-Device-Id", utils.GetMD5Encode(account.Username)).SetQueryParam("client_id", CLIENT_ID).
|
|
||||||
Post(XLUSER_API_URL + "/auth/token")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch e.ErrorCode {
|
|
||||||
case 4122, 4121:
|
|
||||||
return s.login(account)
|
|
||||||
case 0:
|
|
||||||
s.tokenExpiresTime = (time.Now().UnixMilli() + resp.ExpiresIn*1000) - 30000
|
|
||||||
s.tokenType = resp.TokenType
|
|
||||||
s.accessToken = resp.AccessToken
|
|
||||||
s.refreshToken = resp.RefreshToken
|
|
||||||
s.userID = resp.UserID
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("%s : %s", e.Error, e.ErrorDescription)
|
|
||||||
}
|
}
|
||||||
|
return "1." + str
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) login(account *model.Account) error {
|
// 登录
|
||||||
s.init()
|
func (c *Client) Login(account *model.Account) (err error) {
|
||||||
ctime := time.Now().UnixMilli()
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
account.Status = err.Error()
|
||||||
|
} else {
|
||||||
|
account.Status = "work"
|
||||||
|
}
|
||||||
|
model.SaveAccount(account)
|
||||||
|
}()
|
||||||
|
|
||||||
|
meta := make(map[string]string)
|
||||||
|
if strings.Contains(account.Username, "@") {
|
||||||
|
meta["email"] = account.Username
|
||||||
|
} else if len(account.Username) >= 11 {
|
||||||
|
if !strings.Contains(account.Username, "+") {
|
||||||
|
account.Username = "+86 " + account.Username
|
||||||
|
}
|
||||||
|
meta["phone_number"] = account.Username
|
||||||
|
} else {
|
||||||
|
meta["username"] = account.Username
|
||||||
|
}
|
||||||
|
|
||||||
url := XLUSER_API_URL + "/auth/signin"
|
url := XLUSER_API_URL + "/auth/signin"
|
||||||
captchaToken, err := s.newCaptchaToken(getAction("POST", url), map[string]string{"username": account.Username}, account)
|
err = c.requestCaptchaToken(getAction(http.MethodPost, url), meta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
signReq := SignInRequest{
|
|
||||||
CaptchaToken: captchaToken,
|
|
||||||
ClientID: CLIENT_ID,
|
|
||||||
ClientSecret: CLIENT_SECRET,
|
|
||||||
Username: account.Username,
|
|
||||||
Password: account.Password,
|
|
||||||
}
|
|
||||||
|
|
||||||
var e Erron
|
var e Erron
|
||||||
var resp TokenResponse
|
var resp TokenResponse
|
||||||
_, err = xunleiClient.R().
|
_, err = c.Client.R().
|
||||||
SetResult(&resp).
|
SetResult(&resp).
|
||||||
SetError(&e).
|
SetError(&e).
|
||||||
SetBody(&signReq).
|
SetBody(&SignInRequest{
|
||||||
SetHeader("X-Device-Id", utils.GetMD5Encode(account.Username)).
|
CaptchaToken: c.captchaToken,
|
||||||
SetQueryParam("client_id", CLIENT_ID).
|
ClientID: c.clientID,
|
||||||
|
ClientSecret: c.clientSecret,
|
||||||
|
Username: account.Username,
|
||||||
|
Password: account.Password,
|
||||||
|
}).
|
||||||
|
SetHeader("X-Device-Id", c.deviceID).
|
||||||
|
SetQueryParam("client_id", c.clientID).
|
||||||
Post(url)
|
Post(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer model.SaveAccount(account)
|
if e.HasError() {
|
||||||
if e.ErrorCode != 0 {
|
return &e
|
||||||
account.Status = e.Error
|
|
||||||
return fmt.Errorf("%s : %s", e.Error, e.ErrorDescription)
|
|
||||||
}
|
}
|
||||||
account.Status = "work"
|
|
||||||
s.tokenExpiresTime = (ctime + resp.ExpiresIn*1000) - 30000
|
if resp.RefreshToken == "" {
|
||||||
s.tokenType = resp.TokenType
|
return base.ErrEmptyToken
|
||||||
s.accessToken = resp.AccessToken
|
}
|
||||||
s.refreshToken = resp.RefreshToken
|
|
||||||
s.userID = resp.UserID
|
c.token = resp.Token()
|
||||||
|
c.refreshToken = resp.RefreshToken
|
||||||
|
c.userID = resp.UserID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) Request(method string, url string, callback func(*resty.Request), account *model.Account) (*resty.Response, error) {
|
// 刷新验证码token
|
||||||
s.Lock()
|
func (c *Client) RefreshCaptchaToken(action string) error {
|
||||||
token, err := s.getToken(account)
|
c.Lock()
|
||||||
if err != nil {
|
defer c.Unlock()
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
captchaToken, err := s.getCaptchaToken(getAction(method, url), account)
|
timestamp := fmt.Sprint(time.Now().UnixMilli())
|
||||||
if err != nil {
|
param := map[string]string{
|
||||||
return nil, err
|
"client_version": c.clientVersion,
|
||||||
|
"package_name": c.packageName,
|
||||||
|
"user_id": c.userID,
|
||||||
|
"captcha_sign": c.captchaSign(timestamp),
|
||||||
|
"timestamp": timestamp,
|
||||||
}
|
}
|
||||||
|
return c.requestCaptchaToken(action, param)
|
||||||
|
}
|
||||||
|
|
||||||
req := xunleiClient.R().
|
// 刷新token
|
||||||
SetHeaders(map[string]string{
|
func (c *Client) RefreshToken() error {
|
||||||
"X-Device-Id": utils.GetMD5Encode(account.Username),
|
c.Lock()
|
||||||
"Authorization": token,
|
defer c.Unlock()
|
||||||
"X-Captcha-Token": captchaToken,
|
|
||||||
|
var e Erron
|
||||||
|
var resp TokenResponse
|
||||||
|
_, err := c.Client.R().
|
||||||
|
SetError(&e).
|
||||||
|
SetResult(&resp).
|
||||||
|
SetBody(&base.Json{
|
||||||
|
"grant_type": "refresh_token",
|
||||||
|
"refresh_token": c.refreshToken,
|
||||||
|
"client_id": c.clientID,
|
||||||
|
"client_secret": c.clientSecret,
|
||||||
}).
|
}).
|
||||||
SetQueryParam("client_id", CLIENT_ID)
|
SetHeader("X-Device-Id", c.deviceID).
|
||||||
|
SetQueryParam("client_id", c.clientID).
|
||||||
callback(req)
|
Post(XLUSER_API_URL + "/auth/token")
|
||||||
s.Unlock()
|
if err != nil {
|
||||||
|
return err
|
||||||
var res *resty.Response
|
}
|
||||||
switch method {
|
if e.HasError() {
|
||||||
case "GET":
|
return &e
|
||||||
res, err = req.Get(url)
|
|
||||||
case "POST":
|
|
||||||
res, err = req.Post(url)
|
|
||||||
case "DELETE":
|
|
||||||
res, err = req.Delete(url)
|
|
||||||
case "PATCH":
|
|
||||||
res, err = req.Patch(url)
|
|
||||||
case "PUT":
|
|
||||||
res, err = req.Put(url)
|
|
||||||
default:
|
|
||||||
return nil, base.ErrNotSupport
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.RefreshToken == "" {
|
||||||
|
return base.ErrEmptyToken
|
||||||
|
}
|
||||||
|
|
||||||
|
c.token = resp.TokenType + " " + resp.AccessToken
|
||||||
|
c.refreshToken = resp.RefreshToken
|
||||||
|
c.userID = resp.UserID
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Request(method string, url string, callback func(*resty.Request), account *model.Account) (*resty.Response, error) {
|
||||||
|
c.Lock()
|
||||||
|
req := c.Client.R().
|
||||||
|
SetHeaders(map[string]string{
|
||||||
|
"X-Device-Id": c.deviceID,
|
||||||
|
"Authorization": c.token,
|
||||||
|
"X-Captcha-Token": c.captchaToken,
|
||||||
|
"User-Agent": c.userAgent,
|
||||||
|
"client_id": c.clientID,
|
||||||
|
}).
|
||||||
|
SetQueryParam("client_id", c.clientID)
|
||||||
|
if callback != nil {
|
||||||
|
callback(req)
|
||||||
|
}
|
||||||
|
c.Unlock()
|
||||||
|
|
||||||
|
res, err := req.Execute(method, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Debug(res.String())
|
log.Debug(res.String())
|
||||||
|
|
||||||
var e Erron
|
var e Erron
|
||||||
err = utils.Json.Unmarshal(res.Body(), &e)
|
if err = utils.Json.Unmarshal(res.Body(), &e); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理错误
|
||||||
switch e.ErrorCode {
|
switch e.ErrorCode {
|
||||||
case 9:
|
case 0:
|
||||||
_, err = s.newCaptchaToken(getAction(method, url), nil, account)
|
return res, nil
|
||||||
if err != nil {
|
case 4122, 4121, 10: // token过期
|
||||||
return nil, err
|
if err = c.RefreshToken(); err == nil {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
case 4122, 4121: // Authorization expired
|
case 16: // 登录失效
|
||||||
return s.Request(method, url, callback, account)
|
if err = c.Login(account); err != nil {
|
||||||
case 0:
|
return nil, err
|
||||||
if res.StatusCode() == http.StatusOK {
|
}
|
||||||
return res, nil
|
case 9: // 验证码token过期
|
||||||
|
if err = c.RefreshCaptchaToken(getAction(method, url)); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf(res.String())
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("%s : %s", e.Error, e.ErrorDescription)
|
return nil, &e
|
||||||
}
|
}
|
||||||
|
return c.Request(method, url, callback, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) Init() *State {
|
func (c *Client) UpdateCaptchaToken(captchaToken string) bool {
|
||||||
s.Lock()
|
c.Lock()
|
||||||
defer s.Unlock()
|
defer c.Unlock()
|
||||||
return s.init()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *State) GetCaptchaToken(action string, account *model.Account) (string, error) {
|
if captchaToken != "" {
|
||||||
s.Lock()
|
c.captchaToken = captchaToken
|
||||||
defer s.Unlock()
|
return true
|
||||||
return s.getCaptchaToken(action, account)
|
}
|
||||||
}
|
return false
|
||||||
|
|
||||||
func (s *State) GetToken(account *model.Account) (string, error) {
|
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
return s.getToken(account)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *State) Login(account *model.Account) error {
|
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
return s.login(account)
|
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,8 @@ func (driver Yandex) Upload(file *model.FileStream, account *model.Account) erro
|
|||||||
}
|
}
|
||||||
req.Header.Set("Content-Length", strconv.FormatUint(file.Size, 10))
|
req.Header.Set("Content-Length", strconv.FormatUint(file.Size, 10))
|
||||||
req.Header.Set("Content-Type", "application/octet-stream")
|
req.Header.Set("Content-Type", "application/octet-stream")
|
||||||
_, err = base.HttpClient.Do(req)
|
res, err := base.HttpClient.Do(req)
|
||||||
|
res.Body.Close()
|
||||||
//res, err := base.RestyClient.R().
|
//res, err := base.RestyClient.R().
|
||||||
// SetHeader("Content-Length", strconv.FormatUint(file.Size, 10)).
|
// SetHeader("Content-Length", strconv.FormatUint(file.Size, 10)).
|
||||||
// SetBody(file).Put(resp.Href)
|
// SetBody(file).Put(resp.Href)
|
||||||
|
3
go.mod
3
go.mod
@ -27,15 +27,12 @@ require (
|
|||||||
require github.com/kr/fs v0.1.0 // indirect
|
require github.com/kr/fs v0.1.0 // indirect
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
|
|
||||||
github.com/fatih/color v1.13.0
|
github.com/fatih/color v1.13.0
|
||||||
github.com/mattn/go-colorable v0.1.9 // indirect
|
github.com/mattn/go-colorable v0.1.9 // indirect
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/XiaoMi/pegasus-go-client v0.0.0-20210427083443-f3b6b08bc4c2 // indirect
|
github.com/XiaoMi/pegasus-go-client v0.0.0-20210427083443-f3b6b08bc4c2 // indirect
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible
|
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect
|
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect
|
||||||
github.com/cenkalti/backoff/v4 v4.1.0 // indirect
|
github.com/cenkalti/backoff/v4 v4.1.0 // indirect
|
||||||
|
9
go.sum
9
go.sum
@ -20,8 +20,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
|
|||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible h1:uuJIwCFhbZy+zdvLy5zrcIToPEQP0s5CFOZ0Zj03O/w=
|
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
|
|
||||||
github.com/allegro/bigcache/v2 v2.2.5 h1:mRc8r6GQjuJsmSKQNPsR5jQVXc8IJ1xsW5YXUYMLfqI=
|
github.com/allegro/bigcache/v2 v2.2.5 h1:mRc8r6GQjuJsmSKQNPsR5jQVXc8IJ1xsW5YXUYMLfqI=
|
||||||
github.com/allegro/bigcache/v2 v2.2.5/go.mod h1:FppZsIO+IZk7gCuj5FiIDHGygD9xvWQcqg1uIPMb6tY=
|
github.com/allegro/bigcache/v2 v2.2.5/go.mod h1:FppZsIO+IZk7gCuj5FiIDHGygD9xvWQcqg1uIPMb6tY=
|
||||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||||
@ -34,8 +32,6 @@ github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQ
|
|||||||
github.com/aws/aws-sdk-go v1.27.0 h1:0xphMHGMLBrPMfxR2AmVjZKcMEESEgWF8Kru94BNByk=
|
github.com/aws/aws-sdk-go v1.27.0 h1:0xphMHGMLBrPMfxR2AmVjZKcMEESEgWF8Kru94BNByk=
|
||||||
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||||
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
|
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
|
||||||
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
|
|
||||||
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
|
|
||||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
@ -466,8 +462,6 @@ github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThC
|
|||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||||
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
||||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
|
||||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
|
||||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||||
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
||||||
@ -659,9 +653,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
|
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
@ -50,6 +50,13 @@ type Account struct {
|
|||||||
CustomHost string `json:"custom_host"`
|
CustomHost string `json:"custom_host"`
|
||||||
ExtractFolder string `json:"extract_folder"`
|
ExtractFolder string `json:"extract_folder"`
|
||||||
Bool1 bool `json:"bool_1"`
|
Bool1 bool `json:"bool_1"`
|
||||||
|
// for xunlei
|
||||||
|
Algorithms string `json:"algorithms"`
|
||||||
|
ClientVersion string `json:"client_version"`
|
||||||
|
PackageName string `json:"package_name"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
CaptchaToken string `json:"captcha_token"`
|
||||||
|
DeviceId string `json:"device_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var accountsMap = make(map[string]Account)
|
var accountsMap = make(map[string]Account)
|
||||||
|
@ -26,7 +26,7 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *base.Link, file *model.
|
|||||||
_ = link.Data.Close()
|
_ = link.Data.Close()
|
||||||
}()
|
}()
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename=%s`, url.QueryEscape(file.Name)))
|
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename=%s`, file.Name))
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(file.Size, 10))
|
w.Header().Set("Content-Length", strconv.FormatInt(file.Size, 10))
|
||||||
if link.Header != nil {
|
if link.Header != nil {
|
||||||
for h, val := range link.Header {
|
for h, val := range link.Header {
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/fs"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/public"
|
"github.com/Xhofe/alist/public"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io/fs"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitIndex() {
|
func InitIndex() {
|
||||||
@ -48,6 +50,8 @@ func Static(r *gin.Engine) {
|
|||||||
c.Status(200)
|
c.Status(200)
|
||||||
if strings.HasPrefix(c.Request.URL.Path, "/@manage") {
|
if strings.HasPrefix(c.Request.URL.Path, "/@manage") {
|
||||||
_, _ = c.Writer.WriteString(conf.ManageHtml)
|
_, _ = c.Writer.WriteString(conf.ManageHtml)
|
||||||
|
} else if strings.HasPrefix(c.Request.URL.Path, "/debug/pprof") {
|
||||||
|
pprof.Index(c.Writer, c.Request)
|
||||||
} else {
|
} else {
|
||||||
_, _ = c.Writer.WriteString(conf.IndexHtml)
|
_, _ = c.Writer.WriteString(conf.IndexHtml)
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,14 @@ package webdav
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"mime"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/drivers/operate"
|
"github.com/Xhofe/alist/drivers/operate"
|
||||||
@ -14,12 +22,6 @@ import (
|
|||||||
"github.com/Xhofe/alist/server/common"
|
"github.com/Xhofe/alist/server/common"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileSystem struct{}
|
type FileSystem struct{}
|
||||||
@ -197,8 +199,17 @@ func (fs *FileSystem) Upload(ctx context.Context, r *http.Request, rawPath strin
|
|||||||
} else {
|
} else {
|
||||||
delete(upFileMap, rawPath)
|
delete(upFileMap, rawPath)
|
||||||
}
|
}
|
||||||
|
mimeType := r.Header.Get("Content-Type")
|
||||||
|
if mimeType == "" || strings.ToLower(mimeType) == "application/octet-stream" {
|
||||||
|
mimeTypeTmp := mime.TypeByExtension(path.Ext(fileName))
|
||||||
|
if mimeTypeTmp != "" {
|
||||||
|
mimeType = mimeTypeTmp
|
||||||
|
} else {
|
||||||
|
mimeType = "application/octet-stream"
|
||||||
|
}
|
||||||
|
}
|
||||||
fileData := model.FileStream{
|
fileData := model.FileStream{
|
||||||
MIMEType: r.Header.Get("Content-Type"),
|
MIMEType: mimeType,
|
||||||
File: r.Body,
|
File: r.Body,
|
||||||
Size: fileSize,
|
Size: fileSize,
|
||||||
Name: fileName,
|
Name: fileName,
|
||||||
|
Reference in New Issue
Block a user