Compare commits

...

48 Commits

Author SHA1 Message Date
1d3b86985f fix: config json and env tag 2022-07-22 13:40:12 +08:00
c711ba53a3 fix!: change default assets to local 2022-07-22 13:39:25 +08:00
532a326ad6 ci: prettify auto generate changelog 2022-07-21 22:26:24 +08:00
917ad07ab7 fix(123): download out of memory 2022-07-21 22:08:11 +08:00
50fd7de045 fix(139): rename file (close: #1331) 2022-07-21 21:08:49 +08:00
f6527f1c4c fix(native): download while root_folder is not root (fix: #1340) 2022-07-21 20:50:43 +08:00
a3ef3d1416 docs: add sponsor 2022-07-17 23:59:27 +08:00
89b05021f8 chore: moved alist-web 2022-07-14 22:25:51 +08:00
7e40acad3f feat: Added SubFolder and localAssets configuration(#1324)
Co-authored-by: eaglexmw <eagle_xmw@163.com>
2022-07-14 22:22:47 +08:00
eb15bce24b ci: auto generate changelog 2022-06-06 16:22:12 +08:00
52814266b8 chore: Merge pull request #1200 from alist-org/all-contributors/add-XZB-1248
docs: add XZB-1248 as a contributor for code
2022-06-06 16:16:11 +08:00
f845ec05e0 docs: update .all-contributorsrc [skip ci] 2022-06-06 08:15:50 +00:00
29fb02c886 docs: update CONTRIBUTORS.md [skip ci] 2022-06-06 08:15:49 +00:00
072e854a71 chore: Merge pull request #1199 from alist-org/dev
Merge dev branch
2022-06-06 16:10:35 +08:00
cae0a5f603 chore: Merge pull request #1191 from XZB-1248/dev
fix: filename is urlencoded when using Safari
2022-06-03 21:57:42 +08:00
XZB
7c6d8ca222 fix(proxy): filename is urlencoded when using Safari 2022-06-02 18:13:17 +08:00
f6be50f15a fix(189): login and get link (close #1182) 2022-05-31 16:03:54 +08:00
c35d54d092 chore: Merge pull request #1167 from Xhofe/dev 2022-05-28 21:01:47 +08:00
323dad2a1c fix(sftp): infinite loop while remove file (close #1094) 2022-05-28 21:01:04 +08:00
62aefc4f68 fix(189): new resty client 2022-05-28 20:43:13 +08:00
6a7eb8b3eb fix: don't save search files of balance account (close #1125) 2022-05-21 22:12:18 +08:00
eb549f2631 feat: add pdf viewer url to settings (close #1109) 2022-05-19 15:31:47 +08:00
9207eb69ee feat: add m4v to default video types (close #1114) 2022-05-19 15:31:40 +08:00
866df0540b chore: Merge pull request #1110 from foxxorcat/dev
增加123流式上传选择
2022-05-17 12:49:22 +08:00
04e04a1aa6 fix(189pc): delete user-agent for upload 2022-05-16 23:33:12 +08:00
6a66e39d5b feat(123):add io stream upload 2022-05-16 21:03:00 +08:00
f2b2728be7 fix(123,189pc,alidriver,xunlei):tempfile remove 2022-05-16 09:48:33 +08:00
39b8f28fc4 fix: disable pprof while not debug 2022-05-15 16:17:52 +08:00
e1ccc0b215 chore: Merge pull request #1093 from Xhofe/dev
2.5.2
2022-05-13 17:39:26 +08:00
87e339850d fix(ftp): remove dir (#1082) 2022-05-13 17:38:22 +08:00
79c9b6ac77 chore: Merge pull request #1090 from foxxorcat/dev (#1090) 2022-05-13 13:54:04 +08:00
aeb2297f1f perf(123):file thumbnail 2022-05-12 22:27:32 +08:00
3b59bb5c09 perf(123):upload 2022-05-12 21:39:55 +08:00
bc4bac921f chore: Merge pull request #1089 from foxxorcat/dev
修复迅雷一些已知问题
2022-05-12 20:42:49 +08:00
f917882a84 perf(xunlei):upload 2022-05-12 19:18:28 +08:00
6a67d1cf69 fix(xunlei):check captchaToken 2022-05-12 19:15:39 +08:00
041b3587bf fix(xunlei):turn page 2022-05-12 13:27:49 +08:00
0eef7a129c fix(xunlei):the verification code cannot be obtained from the mobile phone number or email 2022-05-12 13:26:12 +08:00
4b635f06e3 fix(189pc): delete user-agent for upload 2022-05-11 20:01:15 +08:00
279111a8e2 chore: Merge pull request #1079 from foxxorcat/dev 2022-05-10 22:35:59 +08:00
67674835da fix(alidriver):fast upload file is not close 2022-05-10 21:54:44 +08:00
732e9eb1c3 feat:add pprof 2022-05-10 21:40:43 +08:00
b6af9aa587 fix(139,189,189pc,alidrive,onedrive,yandex):http response body is not close #1072 2022-05-10 21:37:48 +08:00
a9027c0f06 fix(baidu.photo):update download api 2022-05-10 20:35:19 +08:00
d780fa18a5 fix(sftp): error while has no files(close #1078) 2022-05-10 18:18:06 +08:00
d5626d6e2f fix: cancel QueryEscape Disposition (close #1074) 2022-05-10 18:16:32 +08:00
52dcbfe1a4 fix(xunlei):missing x-client-id error in some user requests 2022-05-09 18:14:52 +08:00
bf0ee3d315 refactor(baidu.photo): add a file api of download 2022-05-09 12:43:51 +08:00
34 changed files with 415 additions and 193 deletions

View File

@ -78,11 +78,20 @@
"contributions": [ "contributions": [
"code" "code"
] ]
},
{
"login": "XZB-1248",
"name": "XZB-1248",
"avatar_url": "https://avatars.githubusercontent.com/u/28593573?v=4",
"profile": "https://github.com/XZB-1248",
"contributions": [
"code"
]
} }
], ],
"contributorsPerLine": 7, "contributorsPerLine": 7,
"projectName": "alist", "projectName": "alist",
"projectOwner": "Xhofe", "projectOwner": "alist-org",
"repoType": "github", "repoType": "github",
"repoHost": "https://github.com", "repoHost": "https://github.com",
"skipCi": true "skipCi": true

View File

@ -6,7 +6,19 @@ on:
- '*' - '*'
jobs: jobs:
changelog:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- run: npx changelogithub # or changelogithub@0.12 if ensure the stable result
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
release: release:
needs: changelog
strategy: strategy:
matrix: matrix:
platform: [ubuntu-latest] platform: [ubuntu-latest]

View File

@ -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 -->
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-) [![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END --> <!-- ALL-CONTRIBUTORS-BADGE:END -->
## Contributors ✨ ## Contributors ✨
@ -11,16 +11,17 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- markdownlint-disable --> <!-- markdownlint-disable -->
<table> <table>
<tr> <tr>
<td align="center"><a href="http://nn.ci"><img src="https://avatars.githubusercontent.com/u/36558727?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Xhofe</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=Xhofe" title="Code">💻</a> <a href="#ideas-Xhofe" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/Xhofe/alist/commits?author=Xhofe" title="Documentation">📖</a></td> <td align="center"><a href="http://nn.ci"><img src="https://avatars.githubusercontent.com/u/36558727?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Xhofe</b></sub></a><br /><a href="https://github.com/alist-org/alist/commits?author=Xhofe" title="Code">💻</a> <a href="#ideas-Xhofe" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/alist-org/alist/commits?author=Xhofe" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/foxxorcat"><img src="https://avatars.githubusercontent.com/u/95907542?v=4?s=100" width="100px;" alt=""/><br /><sub><b>foxxorcat</b></sub></a><br /><a href="https://github.com/Xhofe/alist/commits?author=foxxorcat" title="Code">💻</a></td> <td align="center"><a href="https://github.com/foxxorcat"><img src="https://avatars.githubusercontent.com/u/95907542?v=4?s=100" width="100px;" alt=""/><br /><sub><b>foxxorcat</b></sub></a><br /><a href="https://github.com/alist-org/alist/commits?author=foxxorcat" title="Code">💻</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://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/alist-org/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/alist-org/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/alist-org/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/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/alist-org/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> <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/alist-org/alist/commits?author=ericarena" title="Code">💻</a></td>
</tr> </tr>
<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> <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/alist-org/alist/commits?author=WntFlm" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/XZB-1248"><img src="https://avatars.githubusercontent.com/u/28593573?v=4?s=100" width="100px;" alt=""/><br /><sub><b>XZB-1248</b></sub></a><br /><a href="https://github.com/alist-org/alist/commits?author=XZB-1248" title="Code">💻</a></td>
</tr> </tr>
</table> </table>

View File

@ -72,7 +72,8 @@ Available at: <https://alist.nn.ci>.
<https://alist-doc.nn.ci/en/> <https://alist-doc.nn.ci/en/>
## Special sponsors ## Special sponsors
- [Find Resources - Aliyundrive Resource Search Engine](https://zhaoziyuan.la/) - [找资源 - 阿里云盘资源搜索引擎](https://zhaoziyuan.la/)
- [KinhDown 百度云盘不限速下载永久免费以稳定运行3年非常可靠!](https://kinhdown.com/?Type=Tutorials)
- [JetBrains: Essential tools for software developers and teams](https://www.jetbrains.com/) - [JetBrains: Essential tools for software developers and teams](https://www.jetbrains.com/)
## License ## License

View File

@ -73,6 +73,7 @@
## 特别赞助 ## 特别赞助
- [找资源 - 阿里云盘资源搜索引擎](https://zhaoziyuan.la/) - [找资源 - 阿里云盘资源搜索引擎](https://zhaoziyuan.la/)
- [KinhDown 百度云盘不限速下载永久免费以稳定运行3年非常可靠!](https://kinhdown.com/?Type=Tutorials)
- [JetBrains: Essential tools for software developers and teams](https://www.jetbrains.com/) - [JetBrains: Essential tools for software developers and teams](https://www.jetbrains.com/)
## 许可 ## 许可

View File

@ -124,6 +124,13 @@ func InitSettings() {
Access: model.PUBLIC, Access: model.PUBLIC,
Group: model.FRONT, Group: model.FRONT,
}, },
{
Key: "pdf viewer url",
Type: "string",
Value: "https://alist-org.github.io/pdf.js/web/viewer.html?file=$url",
Access: model.PUBLIC,
Group: model.FRONT,
},
{ {
Key: "autoplay video", Key: "autoplay video",
Value: "false", Value: "false",

View File

@ -2,8 +2,8 @@
# 构建前端,在当前目录产生一个dist文件夹 # 构建前端,在当前目录产生一个dist文件夹
BUILD_WEB() { BUILD_WEB() {
git clone https://github.com/alist-org/alist-web.git git clone https://github.com/alist-org/web-v2.git
cd alist-web cd web-v2
yarn yarn
yarn build yarn build
sed -i -e "s/\/CDN_URL\//\//g" dist/index.html sed -i -e "s/\/CDN_URL\//\//g" dist/index.html
@ -11,11 +11,11 @@ BUILD_WEB() {
rm -f dist/index.html-e rm -f dist/index.html-e
mv dist .. mv dist ..
cd .. || exit cd .. || exit
rm -rf alist-web rm -rf web-v2
} }
CDN_WEB() { CDN_WEB() {
curl -L https://github.com/alist-org/alist-web/releases/latest/download/dist.tar.gz -o dist.tar.gz curl -L https://github.com/alist-org/web-v2/releases/latest/download/dist.tar.gz -o dist.tar.gz
tar -zxvf dist.tar.gz tar -zxvf dist.tar.gz
rm -f dist.tar.gz rm -f dist.tar.gz
} }
@ -28,7 +28,7 @@ BUILD_DOCKER() {
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD) gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1) gitCommit=$(git log --pretty=format:"%h" -1)
gitTag=$(git describe --long --tags --dirty --always) gitTag=$(git describe --long --tags --dirty --always)
webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/web-v2/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
ldflags="\ ldflags="\
-w -s \ -w -s \
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \ -X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
@ -49,7 +49,7 @@ BUILD() {
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD) gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1) gitCommit=$(git log --pretty=format:"%h" -1)
gitTag=$(git describe --long --tags --dirty --always) gitTag=$(git describe --long --tags --dirty --always)
webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/web-v2/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
echo "build version: $gitTag" echo "build version: $gitTag"
ldflags="\ ldflags="\
@ -95,7 +95,7 @@ BUILD_MUSL() {
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD) gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1) gitCommit=$(git log --pretty=format:"%h" -1)
gitTag=$(git describe --long --tags --dirty --always) gitTag=$(git describe --long --tags --dirty --always)
webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/web-v2/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
ldflags="\ ldflags="\
-w -s --extldflags '-static -fpic' \ -w -s --extldflags '-static -fpic' \
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \ -X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \

View File

@ -24,22 +24,26 @@ type CacheConfig struct {
} }
type Config struct { type Config struct {
Force bool `json:"force"` Force bool `json:"force"`
Address string `json:"address" env:"ADDR"` Address string `json:"address" env:"ADDR"`
Port int `json:"port" env:"PORT"` Port int `json:"port" env:"PORT"`
Assets string `json:"assets" env:"ASSETS"` Assets string `json:"assets" env:"ASSETS"`
Database Database `json:"database"` LocalAssets string `json:"local_assets" env:"LOCAL_ASSETS"`
Scheme Scheme `json:"scheme"` SubFolder string `json:"sub_folder" env:"SUB_FOLDER"`
Cache CacheConfig `json:"cache"` Database Database `json:"database"`
TempDir string `json:"temp_dir" env:"TEMP_DIR"` Scheme Scheme `json:"scheme"`
Cache CacheConfig `json:"cache"`
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
} }
func DefaultConfig() *Config { func DefaultConfig() *Config {
return &Config{ return &Config{
Address: "0.0.0.0", Address: "0.0.0.0",
Port: 5244, Port: 5244,
Assets: "https://npm.elemecdn.com/alist-web@$version/dist", Assets: "/",
TempDir: "data/temp", SubFolder: "",
LocalAssets: "",
TempDir: "data/temp",
Database: Database{ Database: Database{
Type: "sqlite3", Type: "sqlite3",
Port: 0, Port: 0,

View File

@ -40,7 +40,7 @@ var (
"go", "sh", "c", "cpp", "h", "hpp", "tsx", "vtt", "srt", "ass"} "go", "sh", "c", "cpp", "h", "hpp", "tsx", "vtt", "srt", "ass"}
DProxyTypes = []string{"m3u8"} DProxyTypes = []string{"m3u8"}
OfficeTypes = []string{"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"} OfficeTypes = []string{"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"}
VideoTypes = []string{"mp4", "mkv", "avi", "mov", "rmvb", "webm", "flv"} VideoTypes = []string{"mp4", "mkv", "avi", "mov", "rmvb", "webm", "flv", "m4v"}
AudioTypes = []string{"mp3", "flac", "ogg", "m4a", "wav", "opus"} AudioTypes = []string{"mp3", "flac", "ogg", "m4a", "wav", "opus"}
ImageTypes = []string{"jpg", "tiff", "jpeg", "png", "gif", "bmp", "svg", "ico", "swf", "webp"} ImageTypes = []string{"jpg", "tiff", "jpeg", "png", "gif", "bmp", "svg", "ico", "swf", "webp"}
) )

View File

@ -3,14 +3,15 @@ package _23
import ( import (
"errors" "errors"
"fmt" "fmt"
"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 {
@ -46,6 +47,7 @@ func (driver Pan123) FormatFile(file *File) *model.File {
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
@ -65,7 +67,7 @@ func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]File,
"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

View File

@ -1,9 +1,18 @@
package _23 package _23
import ( import (
"bytes"
"crypto/md5" "crypto/md5"
"encoding/binary"
"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 +22,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{}
@ -67,6 +70,12 @@ func (driver Pan123) Items() []base.Item {
Required: true, Required: true,
Default: "asc", Default: "asc",
}, },
{
Name: "bool_1",
Label: "stream upload",
Type: base.TypeBool,
Description: "io stream upload (test)",
},
} }
} }
@ -125,7 +134,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))
} }
@ -167,7 +176,7 @@ func (driver Pan123) Link(args base.Args, account *model.Account) (*base.Link, e
return nil, err return nil, err
} }
u_ := fmt.Sprintf("https://%s%s", u.Host, u.Path) u_ := fmt.Sprintf("https://%s%s", u.Host, u.Path)
res, err := base.NoRedirectClient.R().SetQueryParamsFromValues(u.Query()).Get(u_) res, err := base.NoRedirectClient.R().SetQueryParamsFromValues(u.Query()).Head(u_)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -175,6 +184,7 @@ func (driver Pan123) Link(args base.Args, account *model.Account) (*base.Link, e
link := base.Link{ link := base.Link{
Url: resp.Data.DownloadUrl, Url: resp.Data.DownloadUrl,
} }
log.Debugln("res code: ", res.StatusCode())
if res.StatusCode() == 302 { if res.StatusCode() == 302 {
link.Url = res.Header().Get("location") link.Url = res.Header().Get("location")
} }
@ -300,46 +310,57 @@ 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-*") const DEFAULT int64 = 10485760
if err != nil { var uploadFile io.Reader
return err
}
defer func() {
_ = tempFile.Close()
_ = 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 account.Bool1 && file.GetSize() > uint64(DEFAULT) {
if err != nil { // 只计算前10MIB
return err buf := bytes.NewBuffer(make([]byte, 0, DEFAULT))
if n, err := io.CopyN(io.MultiWriter(buf, h), file, DEFAULT); err != io.EOF && n == 0 {
return err
}
// 增加额外参数防止MD5碰撞
h.Write([]byte(file.Name))
num := make([]byte, 8)
binary.BigEndian.PutUint64(num, file.Size)
h.Write(num)
// 拼装
uploadFile = io.MultiReader(buf, file)
} else {
// 计算完整文件MD5
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
if err != nil {
return err
}
defer func() {
_ = tempFile.Close()
_ = os.Remove(tempFile.Name())
}()
if _, err = io.Copy(io.MultiWriter(tempFile, h), file); err != nil {
return err
}
_, err = tempFile.Seek(0, io.SeekStart)
if err != nil {
return err
}
uploadFile = tempFile
} }
etag := hex.EncodeToString(h.Sum(nil)) etag := hex.EncodeToString(h.Sum(nil))
log.Debugln("md5:", etag)
_, err = tempFile.Seek(0, io.SeekStart)
if err != nil {
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
@ -361,7 +382,7 @@ func (driver Pan123) Upload(file *model.FileStream, account *model.Account) erro
input := &s3manager.UploadInput{ input := &s3manager.UploadInput{
Bucket: &resp.Data.Bucket, Bucket: &resp.Data.Bucket,
Key: &resp.Data.Key, Key: &resp.Data.Key,
Body: tempFile, Body: uploadFile,
} }
_, err = uploader.Upload(input) _, err = uploader.Upload(input)
if err != nil { if err != nil {

View File

@ -1,20 +1,22 @@
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 File 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 File) GetSize() uint64 { func (f File) GetSize() uint64 {

View File

@ -270,7 +270,7 @@ func (driver Cloud139) Rename(src string, dst string, account *model.Account) er
"accountType": 1, "accountType": 1,
}, },
} }
pathname = "/orchestration/personalCloud/catalog/v1.0/updateContentInfo" pathname = "/orchestration/personalCloud/content/v1.0/updateContentInfo"
} }
_, err = driver.Post(pathname, data, nil, account) _, err = driver.Post(pathname, data, nil, account)
return err return err
@ -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

View File

@ -7,6 +7,14 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io"
"math"
"net/http"
"regexp"
"strconv"
"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/model" "github.com/Xhofe/alist/model"
@ -14,14 +22,6 @@ import (
"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"
"io"
"math"
"net/http"
"net/http/cookiejar"
"regexp"
"strconv"
"strings"
"time"
) )
var client189Map map[string]*resty.Client var client189Map map[string]*resty.Client
@ -94,18 +94,12 @@ type LoginResp struct {
// Login refer to PanIndex // Login refer to PanIndex
func (driver Cloud189) Login(account *model.Account) error { func (driver Cloud189) Login(account *model.Account) error {
client, ok := client189Map[account.Name] client := resty.New()
if !ok { //client.SetCookieJar(cookieJar)
//cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) client.SetTimeout(base.DefaultTimeout)
client = resty.New() client.SetRetryCount(3)
//client.SetCookieJar(cookieJar) client.SetHeader("Referer", "https://cloud.189.cn/")
client.SetTimeout(base.DefaultTimeout) client.SetHeader("User-Agent", base.UserAgent)
client.SetRetryCount(3)
client.SetHeader("Referer", "https://cloud.189.cn/")
}
// clear cookie
jar, _ := cookiejar.New(nil)
client.SetCookieJar(jar)
url := "https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https%3A%2F%2Fcloud.189.cn%2Fmain.action" url := "https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https%3A%2F%2Fcloud.189.cn%2Fmain.action"
b := "" b := ""
lt := "" lt := ""
@ -131,7 +125,8 @@ func (driver Cloud189) Login(account *model.Account) error {
} }
} }
if lt == "" { if lt == "" {
return fmt.Errorf("get page: %s \nstatus: %d \nrequest url: %s", b, res.StatusCode(), res.RawResponse.Request.URL.String()) return fmt.Errorf("get page: %s \nstatus: %d \nrequest url: %s\nredirect url: %s",
b, res.StatusCode(), res.RawResponse.Request.URL.String(), res.Header().Get("location"))
} }
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]
@ -577,6 +572,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
} }

View File

@ -2,15 +2,16 @@ package _89
import ( import (
"fmt" "fmt"
"net/http"
"path/filepath"
"strings"
"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"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net/http"
"path/filepath"
"strings"
) )
type Cloud189 struct{} type Cloud189 struct{}
@ -179,23 +180,27 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error { resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse return http.ErrUseLastResponse
})) }))
res, err := client.R().Get("https:" + resp.FileDownloadUrl) res, err := client.R().SetHeader("User-Agent", base.UserAgent).Get("https:" + resp.FileDownloadUrl)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Debugln(res.Status()) log.Debugln(res.Status())
log.Debugln(res.String())
link := base.Link{ link := base.Link{
Headers: []base.Header{ Headers: []base.Header{
{Name: "User-Agent", Value: base.UserAgent}, {Name: "User-Agent", Value: base.UserAgent},
//{Name: "Authorization", Value: ""}, //{Name: "Authorization", Value: ""},
}, },
} }
log.Debugln("first url:", resp.FileDownloadUrl)
if res.StatusCode() == 302 { if res.StatusCode() == 302 {
link.Url = res.Header().Get("location") link.Url = res.Header().Get("location")
res, err = client.R().Get(link.Url) log.Debugln("second url:", link.Url)
_, _ = client.R().Get(link.Url)
if res.StatusCode() == 302 { if res.StatusCode() == 302 {
link.Url = res.Header().Get("location") link.Url = res.Header().Get("location")
} }
log.Debugln("third url:", link.Url)
} else { } else {
link.Url = resp.FileDownloadUrl link.Url = resp.FileDownloadUrl
} }

View File

@ -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.Set("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)))
@ -647,9 +650,10 @@ func (driver Cloud189) FastUpload(file *model.FileStream, parentFile *model.File
if err != nil { if err != nil {
return err return err
} }
defer tempFile.Close() defer func() {
defer os.Remove(tempFile.Name()) _ = tempFile.Close()
_ = os.Remove(tempFile.Name())
}()
// 初始化上传 // 初始化上传
state := GetState(account) state := GetState(account)
@ -715,6 +719,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.Set("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 +732,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()
} }
} }
@ -750,8 +757,10 @@ func (driver Cloud189) uploadFamily(file *model.FileStream, parentFile *model.Fi
return err return err
} }
defer tempFile.Close() defer func() {
defer os.Remove(tempFile.Name()) _ = tempFile.Close()
_ = os.Remove(tempFile.Name())
}()
fileMd5 := md5.New() fileMd5 := md5.New()
if _, err = io.Copy(io.MultiWriter(fileMd5, tempFile), file); err != nil { if _, err = io.Copy(io.MultiWriter(fileMd5, tempFile), file); err != nil {
@ -799,8 +808,10 @@ func (driver Cloud189) uploadPerson(file *model.FileStream, parentFile *model.Fi
return err return err
} }
defer tempFile.Close() defer func() {
defer os.Remove(tempFile.Name()) _ = tempFile.Close()
_ = os.Remove(tempFile.Name())
}()
fileMd5 := md5.New() fileMd5 := md5.New()
if _, err = io.Copy(io.MultiWriter(fileMd5, tempFile), file); err != nil { if _, err = io.Copy(io.MultiWriter(fileMd5, tempFile), file); err != nil {

View File

@ -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,14 +461,16 @@ 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
} }
defer tempFile.Close() defer func() {
defer os.Remove(tempFile.Name()) _ = tempFile.Close()
_ = os.Remove(tempFile.Name())
}()
delete(reqBody, "pre_hash") delete(reqBody, "pre_hash")
h := sha1.New() h := sha1.New()
@ -499,6 +508,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 +525,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)

View File

@ -113,7 +113,7 @@ func (driver Alist) Link(args base.Args, account *model.Account) (*base.Link, er
flag = "p" flag = "p"
} }
link := base.Link{} link := base.Link{}
link.Url = fmt.Sprintf("%s/%s%s?sign=%s", account.SiteUrl, flag, path, utils.SignWithToken(name, conf.Token)) link.Url = fmt.Sprintf("%s/%s%s?sign=%s", account.SiteUrl, flag, utils.Join(utils.ParsePath(account.RootFolder), path), utils.SignWithToken(name, conf.Token))
return &link, nil return &link, nil
} }

View File

@ -87,7 +87,7 @@ func (driver Baidu) GetAllFile(account *model.Account) (files []File, err error)
for { for {
var resp FileListResp var resp FileListResp
_, err = driver.Request(http.MethodGet, FILE_API_URL+"/list", func(r *resty.Request) { _, err = driver.Request(http.MethodGet, FILE_API_URL_V1+"/list", func(r *resty.Request) {
r.SetQueryParams(map[string]string{ r.SetQueryParams(map[string]string{
"need_thumbnail": "1", "need_thumbnail": "1",
"need_filter_hidden": "0", "need_filter_hidden": "0",

View File

@ -43,6 +43,14 @@ func (driver Baidu) Items() []base.Item {
Label: "album_id", Label: "album_id",
Type: base.TypeString, Type: base.TypeString,
}, },
{
Name: "internal_type",
Label: "download api",
Type: base.TypeSelect,
Required: true,
Values: "file,album",
Default: "album",
},
{ {
Name: "client_id", Name: "client_id",
Label: "client id", Label: "client id",
@ -156,6 +164,13 @@ func (driver Baidu) Files(path string, account *model.Account) ([]model.File, er
} }
func (driver Baidu) Link(args base.Args, account *model.Account) (*base.Link, error) { 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) file, err := driver.File(args.Path, account)
if err != nil { if err != nil {
return nil, err return nil, err
@ -190,6 +205,42 @@ func (driver Baidu) Link(args base.Args, account *model.Account) (*base.Link, er
}, nil }, 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) { func (driver Baidu) Path(path string, account *model.Account) (*model.File, []model.File, error) {
path = utils.ParsePath(path) path = utils.ParsePath(path)
file, err := driver.File(path, account) file, err := driver.File(path, account)
@ -402,7 +453,7 @@ func (driver Baidu) Upload(file *model.FileStream, account *model.Account) error
// 预上传 // 预上传
var precreateResp PrecreateResp var precreateResp PrecreateResp
_, err = driver.Request(http.MethodPost, FILE_API_URL+"/precreate", func(r *resty.Request) { _, err = driver.Request(http.MethodPost, FILE_API_URL_V1+"/precreate", func(r *resty.Request) {
r.SetFormData(params) r.SetFormData(params)
r.SetResult(&precreateResp) r.SetResult(&precreateResp)
}, account) }, account)
@ -431,7 +482,7 @@ func (driver Baidu) Upload(file *model.FileStream, account *model.Account) error
fallthrough fallthrough
case 2: // 创建文件 case 2: // 创建文件
params["uploadid"] = precreateResp.UploadID params["uploadid"] = precreateResp.UploadID
_, err = driver.Request(http.MethodPost, FILE_API_URL+"/create", func(r *resty.Request) { _, err = driver.Request(http.MethodPost, FILE_API_URL_V1+"/create", func(r *resty.Request) {
r.SetFormData(params) r.SetFormData(params)
r.SetResult(&precreateResp) r.SetResult(&precreateResp)
}, account) }, account)

View File

@ -97,7 +97,7 @@ type (
type ( type (
UploadFile struct { UploadFile struct {
FsID int64 `json:"fs_id"` FsID int64 `json:"fs_id"`
Size int `json:"size"` Size int64 `json:"size"`
Md5 string `json:"md5"` Md5 string `json:"md5"`
ServerFilename string `json:"server_filename"` ServerFilename string `json:"server_filename"`
Path string `json:"path"` Path string `json:"path"`

View File

@ -13,9 +13,10 @@ import (
) )
const ( const (
API_URL = "https://photo.baidu.com/youai" API_URL = "https://photo.baidu.com/youai"
ALBUM_API_URL = API_URL + "/album/v1" ALBUM_API_URL = API_URL + "/album/v1"
FILE_API_URL = API_URL + "/file/v1" FILE_API_URL_V1 = API_URL + "/file/v1"
FILE_API_URL_V2 = API_URL + "/file/v2"
) )
var ( var (

View File

@ -5,6 +5,7 @@ import (
"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" log "github.com/sirupsen/logrus"
"strings"
) )
func KeyCache(path string, account *model.Account) string { func KeyCache(path string, account *model.Account) string {
@ -15,6 +16,9 @@ func KeyCache(path string, account *model.Account) string {
} }
func SaveSearchFiles[T model.ISearchFile](key string, obj []T) { func SaveSearchFiles[T model.ISearchFile](key string, obj []T) {
if strings.Contains(key, ".balance") {
return
}
err := model.DeleteSearchFilesByPath(key) err := model.DeleteSearchFilesByPath(key)
if err != nil { if err != nil {
log.Errorln("failed create search files", err) log.Errorln("failed create search files", err)

View File

@ -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
} }

View File

@ -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
} }

View File

@ -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
@ -195,7 +195,7 @@ func (driver SFTP) Delete(path string, account *model.Account) error {
if err != nil { if err != nil {
return err return err
} }
return client.Remove(utils.Join(account.RootFolder, path)) return client.remove(utils.Join(account.RootFolder, path))
} }
func (driver SFTP) Upload(file *model.FileStream, account *model.Account) error { func (driver SFTP) Upload(file *model.FileStream, account *model.Account) error {

View File

@ -49,7 +49,7 @@ func (client *Client) Files(remotePath string) ([]os.FileInfo, error) {
return client.ReadDir(remotePath) return client.ReadDir(remotePath)
} }
func (client *Client) Remove(remotePath string) error { func (client *Client) remove(remotePath string) error {
f, err := client.Stat(remotePath) f, err := client.Stat(remotePath)
if err != nil { if err != nil {
return nil return nil

View File

@ -1,10 +1,6 @@
package xunlei package xunlei
import ( import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -14,7 +10,10 @@ import (
"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/aliyun/aliyun-oss-go-sdk/oss" "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/go-resty/resty/v2"
"github.com/google/uuid" "github.com/google/uuid"
) )
@ -105,7 +104,7 @@ func (driver XunLeiCloud) Items() []base.Item {
Label: "device id", Label: "device id",
Default: utils.GetMD5Encode(uuid.NewString()), Default: utils.GetMD5Encode(uuid.NewString()),
Type: base.TypeString, Type: base.TypeString,
Required: false, Required: true,
}, },
} }
} }
@ -117,8 +116,8 @@ func (driver XunLeiCloud) Save(account *model.Account, old *model.Account) error
client := GetClient(account) client := GetClient(account)
// 指定验证通过的captchaToken // 指定验证通过的captchaToken
if client.captchaToken != "" { if account.CaptchaToken != "" {
client.captchaToken = account.CaptchaToken client.UpdateCaptchaToken(strings.TrimSpace(account.CaptchaToken))
account.CaptchaToken = "" account.CaptchaToken = ""
} }
@ -169,15 +168,17 @@ func (driver XunLeiCloud) Files(path string, account *model.Account) ([]model.Fi
return nil, err return nil, err
} }
time.Sleep(time.Millisecond * 400) 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 = GetClient(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": parentFile.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)
@ -193,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)
@ -355,19 +357,26 @@ 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 func() {
_ = tempFile.Close()
_ = 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 = GetClient(account).Request("POST", FILE_API_URL, func(r *resty.Request) { _, err = GetClient(account).Request("POST", FILE_API_URL, func(r *resty.Request) {
@ -375,8 +384,8 @@ func (driver XunLeiCloud) Upload(file *model.FileStream, account *model.Account)
"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)
@ -388,18 +397,21 @@ 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 {
param.Endpoint = strings.TrimLeft(param.Endpoint, param.Bucket+".") param.Endpoint = strings.TrimLeft(param.Endpoint, param.Bucket+".")
client, err := oss.New(param.Endpoint, param.AccessKeyID, param.AccessKeySecret, oss.SecurityToken(param.SecurityToken), oss.EnableMD5(true)) s, err := session.NewSession(&aws.Config{
if err != nil { Credentials: credentials.NewStaticCredentials(param.AccessKeyID, param.AccessKeySecret, param.SecurityToken),
return err Region: aws.String("xunlei"),
} Endpoint: aws.String(param.Endpoint),
bucket, err := client.Bucket(param.Bucket) })
if err != nil {
return err
}
err = bucket.UploadFile(param.Key, tempFile.Name(), 1<<22, oss.Routines(3), oss.Checkpoint(true, ""), oss.Expires(param.Expiration))
if err != nil { if err != nil {
return err return err
} }
_, err = s3manager.NewUploader(s).Upload(&s3manager.UploadInput{
Bucket: aws.String(param.Bucket),
Key: aws.String(param.Key),
Expires: aws.Time(param.Expiration),
Body: file,
})
return err
} }
return nil return nil
} }

View File

@ -73,6 +73,8 @@ func (c *Client) requestCaptchaToken(action string, meta map[string]string) erro
SetBody(&param). SetBody(&param).
SetError(&e). SetError(&e).
SetResult(&resp). SetResult(&resp).
SetHeader("X-Device-Id", c.deviceID).
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
@ -115,8 +117,20 @@ func (c *Client) Login(account *model.Account) (err error) {
model.SaveAccount(account) 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"
err = c.requestCaptchaToken(getAction(http.MethodPost, url), map[string]string{"username": account.Username}) err = c.requestCaptchaToken(getAction(http.MethodPost, url), meta)
if err != nil { if err != nil {
return err return err
} }
@ -133,6 +147,8 @@ func (c *Client) Login(account *model.Account) (err error) {
Username: account.Username, Username: account.Username,
Password: account.Password, 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
@ -184,6 +200,8 @@ func (c *Client) RefreshToken() error {
"client_id": c.clientID, "client_id": c.clientID,
"client_secret": c.clientSecret, "client_secret": c.clientSecret,
}). }).
SetHeader("X-Device-Id", c.deviceID).
SetQueryParam("client_id", c.clientID).
Post(XLUSER_API_URL + "/auth/token") Post(XLUSER_API_URL + "/auth/token")
if err != nil { if err != nil {
return err return err
@ -211,7 +229,8 @@ func (c *Client) Request(method string, url string, callback func(*resty.Request
"X-Captcha-Token": c.captchaToken, "X-Captcha-Token": c.captchaToken,
"User-Agent": c.userAgent, "User-Agent": c.userAgent,
"client_id": c.clientID, "client_id": c.clientID,
}).SetQueryParam("client_id", c.clientID) }).
SetQueryParam("client_id", c.clientID)
if callback != nil { if callback != nil {
callback(req) callback(req)
} }
@ -250,3 +269,14 @@ func (c *Client) Request(method string, url string, callback func(*resty.Request
} }
return c.Request(method, url, callback, account) return c.Request(method, url, callback, account)
} }
func (c *Client) UpdateCaptchaToken(captchaToken string) bool {
c.Lock()
defer c.Unlock()
if captchaToken != "" {
c.captchaToken = captchaToken
return true
}
return false
}

View File

@ -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
View File

@ -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
View File

@ -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=

View File

@ -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"; filename*=UTF-8''%s`, file.Name, url.QueryEscape(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 {
@ -57,7 +57,7 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *base.Link, file *model.
if err != nil { if err != nil {
return err return err
} }
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename=%s`, url.QueryEscape(file.Name))) w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, file.Name, url.QueryEscape(file.Name)))
http.ServeContent(w, r, file.Name, fileStat.ModTime(), f) http.ServeContent(w, r, file.Name, fileStat.ModTime(), f)
return nil return nil
} else { } else {

View File

@ -1,14 +1,19 @@
package server package server
import ( import (
"io/fs"
"os"
"io/ioutil"
"net/http"
"net/http/pprof"
"strings"
"path/filepath"
"github.com/Xhofe/alist/utils"
"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() {
@ -17,37 +22,73 @@ func InitIndex() {
if !strings.Contains(conf.Conf.Assets, "/") { if !strings.Contains(conf.Conf.Assets, "/") {
conf.Conf.Assets = conf.DefaultConfig().Assets conf.Conf.Assets = conf.DefaultConfig().Assets
} }
index, err = public.Public.Open("index.html") // if LocalAssets is local path, read local index.html.
if (utils.IsDir(filepath.Dir(conf.Conf.LocalAssets))) && utils.Exists(filepath.Join(conf.Conf.LocalAssets, "index.html")) {
index, err = os.Open(filepath.Join(conf.Conf.LocalAssets, "index.html"))
defer index.Close()
log.Infof("used local index.html")
} else {
index, err = public.Public.Open("index.html")
}
if err != nil { if err != nil {
log.Fatal(err.Error()) log.Fatal(err.Error())
} }
data, _ := ioutil.ReadAll(index) data, _ := ioutil.ReadAll(index)
conf.RawIndexHtml = string(data)
// if exist SUB_FOLDER, replace it by config: SubFolder
subfolder := strings.Trim(conf.Conf.SubFolder, "/")
if strings.Contains(conf.RawIndexHtml, "SUB_FOLDER") {
conf.RawIndexHtml = strings.ReplaceAll(conf.RawIndexHtml, "SUB_FOLDER", subfolder)
}
cdnUrl := strings.ReplaceAll(conf.Conf.Assets, "$version", conf.WebTag) cdnUrl := strings.ReplaceAll(conf.Conf.Assets, "$version", conf.WebTag)
cdnUrl = strings.TrimRight(cdnUrl, "/") cdnUrl = strings.TrimRight(cdnUrl, "/")
conf.RawIndexHtml = string(data)
if strings.Contains(conf.RawIndexHtml, "CDN_URL") { if strings.Contains(conf.RawIndexHtml, "CDN_URL") {
conf.RawIndexHtml = strings.ReplaceAll(conf.RawIndexHtml, "/CDN_URL", cdnUrl) if (cdnUrl == "") && (subfolder != "") {
conf.RawIndexHtml = strings.ReplaceAll(conf.RawIndexHtml, "assets/", cdnUrl+"/assets/") conf.RawIndexHtml = strings.ReplaceAll(conf.RawIndexHtml, "CDN_URL", subfolder)
conf.RawIndexHtml = strings.ReplaceAll(conf.RawIndexHtml, "assets/", "/" + subfolder+"/assets/")
} else {
conf.RawIndexHtml = strings.ReplaceAll(conf.RawIndexHtml, "/CDN_URL", cdnUrl)
conf.RawIndexHtml = strings.ReplaceAll(conf.RawIndexHtml, "assets/", cdnUrl+"/assets/")
}
} }
} }
func Static(r *gin.Engine) { func Static(r *gin.Engine) {
var assets fs.FS
var pub fs.FS
var err error
var fsys fs.FS
//InitIndex() //InitIndex()
assets, err := fs.Sub(public.Public, "assets") // if LocalAssets is local path, read local assets.
fsys = os.DirFS(conf.Conf.LocalAssets)
if (utils.IsDir(filepath.Dir(conf.Conf.LocalAssets))) && utils.Exists(filepath.Join(conf.Conf.LocalAssets, "assets")) {
assets, err = fs.Sub(fsys, "assets")
log.Infof("used local assets")
} else {
assets, err = fs.Sub(public.Public, "assets")
}
if err != nil { if err != nil {
log.Fatalf("can't find assets folder") log.Fatalf("can't find assets folder")
} }
pub, err := fs.Sub(public.Public, "public") r.StaticFS("/assets/", http.FS(assets))
// if LocalAssets is local path, read local assets.
if (utils.IsDir(filepath.Dir(conf.Conf.LocalAssets))) && utils.Exists(filepath.Join(conf.Conf.LocalAssets, "public")) {
pub, err = fs.Sub(fsys, "public")
log.Infof("used local public")
} else {
pub, err = fs.Sub(public.Public, "public")
}
if err != nil { if err != nil {
log.Fatalf("can't find public folder") log.Fatalf("can't find public folder")
} }
r.StaticFS("/assets/", http.FS(assets))
r.StaticFS("/public/", http.FS(pub)) r.StaticFS("/public/", http.FS(pub))
r.NoRoute(func(c *gin.Context) { r.NoRoute(func(c *gin.Context) {
c.Header("Content-Type", "text/html") c.Header("Content-Type", "text/html")
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") && conf.Debug {
pprof.Index(c.Writer, c.Request)
} else { } else {
_, _ = c.Writer.WriteString(conf.IndexHtml) _, _ = c.Writer.WriteString(conf.IndexHtml)
} }