Compare commits

..

57 Commits

Author SHA1 Message Date
微凉 f31fc9155a 🔖 release v1.0.5 2021-06-30 21:25:27 +08:00
微凉 d3db012dd0 🚡 move response struct 2021-06-30 21:13:29 +08:00
微凉 74b86ef5e5 🔧 修改每次请求文件数量 2021-06-30 19:32:38 +08:00
微凉 6be90429ad :anguished: remove sponsor 2021-06-30 11:28:22 +08:00
微凉 a6bbff2199 🎇 创建默认配置文件 2021-05-26 19:14:58 +08:00
微凉 3827d3ed67 Merge pull request #111 from daofeng2015/main
fix:api格式修改,新增加生成默认配置文件
2021-05-26 10:54:38 +08:00
daofeng e242867f41 fix:api格式修改,新增加生成默认配置文件 2021-05-26 00:50:37 +08:00
微凉 e09a75a87c ✨ close #109 文件夹软链接 2021-05-17 16:36:55 +08:00
微凉 e0a80b1477 Update README.md 2021-05-15 22:34:35 +08:00
微凉 d693e27ec0 🔖 release 1.0.4 2021-05-01 20:42:00 +08:00
微凉 b20f0717fe :bug: fix: #101 分次请求文件 2021-04-30 19:01:40 +08:00
微凉 427244d8d5 🎇 指定路径与深度rebuild 2021-04-14 13:34:14 +08:00
zsbai b613598c2b 在线预览视频时间延长到4小时 (#96)
* Update request.go

* Update req_bean.go
2021-04-13 23:37:20 +08:00
微凉 f0013320a6 🔖 release v1.0.3 2021-04-09 10:45:16 +08:00
微凉 974caf74d9 :fire: 只初始化一次client 2021-04-09 10:38:57 +08:00
Hello_海生 0bb02664c7 :bug: fix: #85 修复 x509: certificate signed by unknown authority (#86)
* 修复 x509: certificate signed by unknown authority

* 添加忽略证书验证
2021-04-09 10:30:03 +08:00
微凉 6c5a0cba6e :bug: 修复refresh_token失效时无限刷新的bug 2021-03-31 11:05:39 +08:00
微凉 7e21e12e11 👷 release增加Linux386 2021-03-31 09:08:06 +08:00
微凉 11489d8856 Merge pull request #68 from 122cygf/main
修复了因为Referer导致不能下载的问题
2021-03-31 08:04:51 +08:00
lzz 6d824a4ee9 Update auth.go 2021-03-31 00:23:51 +08:00
lzz 8d74d070d4 Update req_bean.go 2021-03-31 00:21:49 +08:00
Xhofe 77aae6660e ✨ 增加视频接口 2021-03-30 10:22:07 +08:00
微凉 76081a81a6 💚 linux_386构建出错 2021-03-21 10:31:53 +08:00
微凉 8760ab283d 💚 linux_386构建出错 2021-03-21 10:23:00 +08:00
微凉 61ab27398c 👷 添加linux386测试 2021-03-21 10:14:59 +08:00
微凉 2e64df7e3d Merge pull request #48 from phoon/main
自定义监听地址配置
2021-03-19 18:45:53 +08:00
Peven 9561f0c951 update conf.yml.example 2021-03-17 18:25:20 +08:00
Peven 03f5a54764 allow to set address in configuration file 2021-03-17 18:08:22 +08:00
微凉 9952c3e90b 💚 版本号 2021-03-17 13:01:02 +08:00
微凉 d94e319df3 🔖 release v1.0.1 2021-03-17 12:56:47 +08:00
微凉 b51b2deea1 💚 错误的文件名 2021-03-17 11:46:53 +08:00
微凉 7dda701f1e 💚 CI重复ID 2021-03-17 11:40:45 +08:00
微凉 3b93445648 👷 release ci surpoort cgo 2021-03-17 11:34:24 +08:00
微凉 a353081126 :bug: 重建时删除不完全 2021-03-16 23:52:41 +08:00
微凉 a5b2f998ab 🎇 支持mysql 2021-03-16 23:15:37 +08:00
微凉 4d0d892ce7 🎇 多盘支持 2021-03-16 21:25:16 +08:00
微凉 8e9ddcf81e :bug: fix: #43 直链密码错误 2021-03-16 16:25:02 +08:00
微凉 5c6344cac0 🎇 直链url密码哈希 2021-03-14 19:13:09 +08:00
微凉 7076efb6be 💚 降低构建系统版本 2021-03-13 23:04:13 +08:00
微凉 6d19b49a8d 🔖 release v1.0.0 2021-03-13 20:25:18 +08:00
微凉 4fa11879f2 :bug: 目录名 2021-03-12 22:03:50 +08:00
微凉 abe9d9237a 🚧 获取链接 2021-03-12 18:12:56 +08:00
微凉 e4d206d59c 🔹 删除list与get接口 2021-03-08 20:28:44 +08:00
微凉 8636014397 🚧 合并get与list 2021-03-08 20:26:02 +08:00
微凉 c0f50ffeff 🚧 参数校验 2021-03-07 21:51:26 +08:00
微凉 b677d6ad21 :heavy_minus_sign: 去除缓存 2021-03-07 21:02:56 +08:00
微凉 443067b80f 🚧 密码逻辑 2021-03-06 23:19:16 +08:00
微凉 3138e031f5 🐝 reformat code 2021-03-05 21:25:44 +08:00
微凉 d137ef8759 🚧 构建目录树 2021-03-05 21:07:45 +08:00
微凉 389226662c 🚧 添加model 2021-03-04 23:50:51 +08:00
微凉 9cb548d4f7 ⭐ 跳过检查更新 2021-02-27 20:06:09 +08:00
微凉 0e7083a713 Merge pull request #27 from 122cygf/main
⭐ 下载链接有效期延长到四小时
2021-02-26 13:14:55 +08:00
122cygf 46f09836f3 下载链接有效期延长到四小时 2021-02-26 12:37:44 +08:00
微凉 e146054679 📝 add notes 2021-02-04 10:02:34 +08:00
微凉 3b2a729dc6 🔧 修改配置文件 2021-01-22 14:27:03 +08:00
微凉 d18a752732 ✨ 添加了office接口 2021-01-19 17:20:14 +08:00
微凉 b9676182c9 🌿 优化了一些代码 2021-01-19 17:19:48 +08:00
46 changed files with 1608 additions and 762 deletions
+13 -2
View File
@@ -11,7 +11,7 @@ jobs:
build:
strategy:
matrix:
platform: [ubuntu-latest]
platform: [ubuntu-16.04]
go-version: [1.15]
name: Build
runs-on: ${{ matrix.platform }}
@@ -46,6 +46,11 @@ jobs:
run: |
CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o alist_windows_amd64.exe alist.go
- name: Build linux_386
run: |
sudo apt-get -y install libc6-dev-i386
CC=gcc CGO_ENABLED=1 GOOS=linux GOARCH=386 go build -o alist_linux_386 alist.go
- name: Upload artifacts linux_amd64
uses: actions/upload-artifact@v2
with:
@@ -68,4 +73,10 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: alist_windows_amd64
path: alist_windows_amd64.exe
path: alist_windows_amd64.exe
- name: Upload artifacts linux_386
uses: actions/upload-artifact@v2
with:
name: alist_linux_386
path: alist_linux_386
+122 -16
View File
@@ -5,24 +5,130 @@ on:
- '*'
jobs:
goreleaser:
runs-on: ubuntu-latest
release:
strategy:
matrix:
platform: [ ubuntu-16.04 ]
go-version: [ 1.15 ]
name: Build
runs-on: ${{ matrix.platform }}
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
go-version: ${{ matrix.go-version }}
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
sudo apt-get update
sudo apt-get -y install gcc-mingw-w64-x86-64
sudo apt-get -y install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
sudo apt-get -y install gcc-aarch64-linux-gnu libc6-dev-arm64-cross
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build linux
run: |
CC=gcc CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o linux_amd64/alist alist.go
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -o linux_arm64/alist alist.go
CC=arm-linux-gnueabihf-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm go build -o linux_arm/alist alist.go
- name: Build windows
run: |
CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o windows_amd64/alist.exe alist.go
- name: Build linux_386
run: |
sudo apt-get -y install libc6-dev-i386
CC=gcc CGO_ENABLED=1 GOOS=linux GOARCH=386 go build -o linux_386/alist alist.go
- name: compress
run: |
tar -czvf alist_linux_amd64.tar.gz linux_amd64/alist conf.yml.example
tar -czvf alist_linux_arm64.tar.gz linux_arm64/alist conf.yml.example
tar -czvf alist_linux_arm.tar.gz linux_arm/alist conf.yml.example
tar -czvf alist_linux_386.tar.gz linux_386/alist conf.yml.example
zip alist_windows_amd64.zip windows_amd64/alist.exe conf.yml.example
- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: ${{steps.github_release.outputs.changelog}}
draft: false
prerelease: false
- name: Upload alist_linux_amd64
id: upload-release-linux-amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: alist_linux_amd64.tar.gz
asset_name: alist_${{ steps.get_version.outputs.VERSION }}_linux_amd64.tar.gz
asset_content_type: application/gzip
- name: Upload alist_linux_arm64
id: upload-release-linux-arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: alist_linux_arm64.tar.gz
asset_name: alist_${{ steps.get_version.outputs.VERSION }}_linux_arm64.tar.gz
asset_content_type: application/gzip
- name: Upload alist_linux_arm
id: upload-release-linux-arm
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: alist_linux_arm.tar.gz
asset_name: alist_${{ steps.get_version.outputs.VERSION }}_linux_arm.tar.gz
asset_content_type: application/gzip
- name: Upload alist_linux_386
id: upload-release-linux-386
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: alist_linux_386.tar.gz
asset_name: alist_${{ steps.get_version.outputs.VERSION }}_linux_386.tar.gz
asset_content_type: application/gzip
- name: Upload alist_windows_amd64
id: upload-release-windows-amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: alist_windows_amd64.zip
asset_name: alist_${{ steps.get_version.outputs.VERSION }}_windows_amd64.zip
asset_content_type: application/zip
+8 -6
View File
@@ -2,12 +2,12 @@
<img src="https://img.oez.cc/2020/12/24/1fb16bc25a4f6.png" alt="AList Logo" width=200/>
</p>
<p align="center">
<a href="https://github.com/Xhofe/alist/releases"><img src="https://img.shields.io/github/release/Xhofe/alist" alt="Release version"></a>
<a href="https://github.com/Xhofe/alist/actions?query=workflow%3ABuild"><img src="https://github.com/Xhofe/alist/workflows/build/badge.svg" alt="Build status"></a>
<a href="https://github.com/Xhofe/alist/releases"><img src="https://img.shields.io/github/downloads/Xhofe/alist/latest/total" alt="Downloads"></a>
<a href="https://github.com/Xhofe/alist/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Xhofe/alist" alt="License"></a>
<a href="https://github.com/Xhofe/alist/releases"><img src="https://img.shields.io/github/release/Xhofe/alist?style=flat-square" alt="Release version"></a>
<a href="https://github.com/Xhofe/alist/actions?query=workflow%3ABuild"><img src="https://img.shields.io/github/workflow/status/Xhofe/alist/build?style=flat-square" alt="Build status"></a>
<a href="https://github.com/Xhofe/alist/releases"><img src="https://img.shields.io/github/downloads/Xhofe/alist/total?style=flat-square" alt="Downloads"></a>
<a href="https://github.com/Xhofe/alist/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Xhofe/alist?style=flat-square" alt="License"></a>
<a href="https://pay.xhofe.top">
<img src="https://img.shields.io/badge/%24-donate-ff69b4.svg" alt="donate">
<img src="https://img.shields.io/badge/%24-donate-ff69b4.svg?style=flat-square" alt="donate">
</a>
</p>
@@ -23,7 +23,9 @@
### 演示地址
- https://alist.nn.ci
- https://alist.nn.ci (稳定版本)
- https://alist.now.sh (开发版本)
- https://alist-plyr.now.sh (plyr分支版本)
### 预览
+33 -59
View File
@@ -2,74 +2,48 @@ package alidrive
import (
"encoding/json"
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/utils"
log "github.com/sirupsen/logrus"
)
func TokenLogin() (*TokenLoginResp, error) {
log.Infof("尝试使用token登录...")
url:="https://auth.aliyundrive.com/v2/oauth/token_login"
req:=TokenLoginReq{Token:conf.Conf.AliDrive.LoginToken}
log.Debugf("token_login_req:%+v",req)
var tokenLogin TokenLoginResp
if body, err := DoPost(url, req,false); err != nil {
log.Errorf("tokenLogin-doPost出错:%s",err.Error())
return nil,err
}else {
if err = json.Unmarshal(body,&tokenLogin);err!=nil {
log.Errorf("解析json[%s]出错:%s",string(body),err.Error())
return nil,err
}
}
if tokenLogin.IsAvailable() {
return &tokenLogin,nil
}
return nil,fmt.Errorf("登录token失效,请更换:%s",tokenLogin.Message)
}
func GetToken(tokenLogin *TokenLoginResp) (*TokenResp,error) {
log.Infof("获取API token...")
url:="https://websv.aliyundrive.com/token/get"
code:=utils.GetCode(tokenLogin.Goto)
if code == "" {
return nil,fmt.Errorf("获取code出错")
}
req:=GetTokenReq{Code:code}
// refresh access_token token by refresh_token
func RefreshToken(drive *conf.Drive) bool {
log.Infof("刷新[%s]token...", drive.Name)
url := "https://auth.aliyundrive.com/v2/account/token"
req := RefreshTokenReq{RefreshToken: drive.RefreshToken , GrantType: "refresh_token"}
var token TokenResp
if body, err := DoPost(url, req,false); err != nil {
log.Errorf("tokenLogin-doPost出错:%s",err.Error())
return nil,err
}else {
if err = json.Unmarshal(body,&token);err!=nil {
log.Errorf("解析json[%s]出错:%s",string(body),err.Error())
log.Errorf("此处json解析失败应该是code失效")
return nil,fmt.Errorf("code失效")
}
}
return &token,nil
}
func RefreshToken() bool {
log.Infof("刷新token...")
url:="https://websv.aliyundrive.com/token/refresh"
req:=RefreshTokenReq{RefreshToken:conf.Conf.AliDrive.RefreshToken}
var token TokenResp
if body, err := DoPost(url, req,false); err != nil {
log.Errorf("tokenLogin-doPost出错:%s",err.Error())
if body, err := DoPost(url, req, ""); err != nil {
log.Errorf("tokenLogin-doPost出错:%s", err.Error())
return false
}else {
if err = json.Unmarshal(body,&token);err!=nil {
log.Errorf("解析json[%s]出错:%s",string(body),err.Error())
log.Errorf("此处json解析失败应该是refresh_token失效")
} else {
if err = json.Unmarshal(body, &token); err != nil {
log.Errorf("解析json[%s]出错:%s", string(body), err.Error())
log.Errorf("此处json解析失败应该是[%s]refresh_token失效", drive.Name)
return false
}
}
//刷新成功 更新token并写入文件
conf.Conf.AliDrive.AccessToken=token.AccessToken
conf.Conf.AliDrive.RefreshToken=token.RefreshToken
conf.Authorization=token.TokenType+"\t"+token.AccessToken
utils.WriteToYml(conf.Con,conf.Conf)
if token.Code != "" {
log.Errorf("盘[%s]刷新token出错:%s", drive.Name, token.Message)
return false
}
//刷新成功 更新token
drive.AccessToken = token.AccessToken
drive.RefreshToken = token.RefreshToken
return true
}
func RefreshTokenAll() string {
log.Infof("刷新所有token...")
res := ""
for i, drive := range conf.Conf.AliDrive.Drives {
if !RefreshToken(&conf.Conf.AliDrive.Drives[i]) {
res = res + drive.Name + ","
}
}
utils.WriteToYml(conf.ConfigFile, conf.Conf)
if res != "" {
return res[:len(res)-1]
}
return ""
}
-5
View File
@@ -1,5 +0,0 @@
package alidrive
var (
User *UserInfo
)
+80
View File
@@ -0,0 +1,80 @@
package alidrive
import (
"bytes"
"encoding/json"
"fmt"
"github.com/Xhofe/alist/conf"
log "github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
"strings"
"time"
)
// convert body to json
func BodyToJson(url string, req interface{}, resp RespHandle, drive *conf.Drive) error {
if body, err := DoPost(url, req, drive.AccessToken); err != nil {
log.Errorf("doPost出错:%s", err.Error())
return err
} else {
if err = json.Unmarshal(body, &resp); err != nil {
log.Errorf("解析json[%s]出错:%s", string(body), err.Error())
return err
}
}
if resp.IsAvailable() {
return nil
}
if resp.GetCode() == conf.AccessTokenInvalid {
resp.SetCode("")
if RefreshToken(drive) {
return BodyToJson(url, req, resp, drive)
}
}
return fmt.Errorf(resp.GetMessage())
}
// do post request
func DoPost(url string, request interface{}, auth string) (body []byte, err error) {
var (
resp *http.Response
)
requestBody := new(bytes.Buffer)
err = json.NewEncoder(requestBody).Encode(request)
if err != nil {
log.Errorf("创建requestBody出错:%s", err.Error())
}
req, err := http.NewRequest("POST", url, requestBody)
log.Debugf("do_post_req:%+v", req)
if err != nil {
log.Errorf("创建request出错:%s", err.Error())
return
}
if auth != "" {
req.Header.Set("authorization", conf.Bearer+auth)
}
req.Header.Add("content-type", "application/json")
req.Header.Add("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")
req.Header.Add("origin", "https://aliyundrive.com")
req.Header.Add("accept", "*/*")
req.Header.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
req.Header.Add("Connection", "keep-alive")
for retryCount := 3; retryCount >= 0; retryCount-- {
if resp, err = conf.Client.Do(req); err != nil && strings.Contains(err.Error(), "timeout") {
<-time.After(time.Second)
} else {
break
}
}
if err != nil {
log.Errorf("请求阿里云盘api时出错:%s", err.Error())
return
}
if body, err = ioutil.ReadAll(resp.Body); err != nil {
log.Errorf("读取api返回内容失败")
}
log.Debugf("请求返回信息:%s", string(body))
return
}
+54 -25
View File
@@ -1,46 +1,75 @@
package alidrive
// ListReq list request bean
type ListReq struct {
DriveId string `json:"drive_id"`
Fields string `json:"fields"`
ImageThumbnailProcess string `json:"image_thumbnail_process"`
ImageUrlProcess string `json:"image_url_process"`
Limit int `json:"limit"`
Marker string `json:"marker"`
OrderBy string `json:"order_by"`
OrderDirection string `json:"order_direction"`
ParentFileId string `json:"parent_file_id"`
VideoThumbnailProcess string `json:"video_thumbnail_process"`
DriveId string `json:"drive_id"`
Fields string `json:"fields"`
ImageThumbnailProcess string `json:"image_thumbnail_process"`
ImageUrlProcess string `json:"image_url_process"`
Limit int `json:"limit"`
Marker string `json:"marker"`
OrderBy string `json:"order_by"`
OrderDirection string `json:"order_direction"`
ParentFileId string `json:"parent_file_id"`
VideoThumbnailProcess string `json:"video_thumbnail_process"`
}
// GetReq get request bean
type GetReq struct {
DriveId string `json:"drive_id"`
FileId string `json:"file_id"`
ImageThumbnailProcess string `json:"image_thumbnail_process"`
VideoThumbnailProcess string `json:"video_thumbnail_process"`
DriveId string `json:"drive_id"`
FileId string `json:"file_id"`
ImageThumbnailProcess string `json:"image_thumbnail_process"`
VideoThumbnailProcess string `json:"video_thumbnail_process"`
}
// DownloadReq download request bean
type DownloadReq struct {
DriveId string `json:"drive_id"`
FileId string `json:"file_id"`
ExpireSec int `json:"expire_sec"`
FileName string `json:"file_name"`
}
// SearchReq search request bean
type SearchReq struct {
DriveId string `json:"drive_id"`
ImageThumbnailProcess string `json:"image_thumbnail_process"`
ImageUrlProcess string `json:"image_url_process"`
Limit int `json:"limit"`
Marker string `json:"marker"`
OrderBy string `json:"order_by"`//"type ASC,updated_at DESC"
DriveId string `json:"drive_id"`
ImageThumbnailProcess string `json:"image_thumbnail_process"`
ImageUrlProcess string `json:"image_url_process"`
Limit int `json:"limit"`
Marker string `json:"marker"`
OrderBy string `json:"order_by"` //"type ASC,updated_at DESC"
Query string `json:"query"`// "name match '测试文件'"
Query string `json:"query"` // "name match '测试文件'"
VideoThumbnailProcess string `json:"video_thumbnail_process"`
VideoThumbnailProcess string `json:"video_thumbnail_process"`
}
// TokenLoginReq token_login request bean
type TokenLoginReq struct {
Token string `json:"token"`
Token string `json:"token"`
}
// GetTokenReq get_token request bean
type GetTokenReq struct {
Code string `json:"code"`
Code string `json:"code"`
}
// RefreshTokenReq refresh_token request bean
type RefreshTokenReq struct {
RefreshToken string `json:"refresh_token"`
RefreshToken string `json:"refresh_token"`
GrantType string `json:"grant_type"`
}
// OfficePreviewUrlReq office_preview_url request bean
type OfficePreviewUrlReq struct {
AccessToken string `json:"access_token"`
DriveId string `json:"drive_id"`
FileId string `json:"file_id"`
}
// VideoPreviewUrlReq video preview url request bean
type VideoPreviewUrlReq struct {
DriveId string `json:"drive_id"`
FileId string `json:"file_id"`
ExpireSec int `json:"expire_sec"`
}
+77 -154
View File
File diff suppressed because it is too large Load Diff
+64 -36
View File
@@ -1,18 +1,40 @@
package alidrive
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
"strings"
"time"
)
// response bean methods
type RespHandle interface {
IsAvailable() bool // check available
GetCode() string // get err code
GetMessage() string // get err message
SetCode(code string) // set err code
}
// common response bean
type RespError struct {
Code string `json:"code"`
Message string `json:"message"`
}
func (resp *RespError) IsAvailable() bool {
return resp.Code == ""
}
func (resp *RespError) GetCode() string {
return resp.Code
}
func (resp *RespError) GetMessage() string {
return resp.Message
}
func (resp *RespError) SetCode(code string) {
resp.Code = code
}
// user_info response bean
type UserInfo struct {
RespError
DomainId string `json:"domain_id"`
@@ -31,19 +53,30 @@ type UserInfo struct {
UserData map[string]interface{} `json:"user_data"`
}
// folder files response bean
type Files struct {
RespError
Items []File `json:"items"`
NextMarker string `json:"next_marker"`
Readme string `json:"readme"`
Paths []Path `json:"paths"`
Readme string `json:"readme"` // Deprecated
Paths []Path `json:"paths"`
}
// path bean
type Path struct {
Name string `json:"name"`
FileId string `json:"file_id"`
}
/** 秒传
{
"name":"mikuclub.mp4",
"content_hash":"C733AC50D1F964C0398D0E403F3A30C37EFC2ADD",
"size":1141068377,
"content_type":"video/mp4"
}
*/
// file response bean
type File struct {
RespError
DriveId string `json:"drive_id"`
@@ -72,18 +105,28 @@ type File struct {
Url string `json:"url"`
ImageMediaMetadata map[string]interface{} `json:"image_media_metadata"`
Paths []Path `json:"paths"`
Paths []Path `json:"paths"`
}
func (resp *RespError) IsAvailable() bool {
return resp.Code == ""
type DownloadResp struct {
RespError
Expiration string `json:"expiration"`
Method string `json:"method"`
Size int64 `json:"size"`
Url string `json:"url"`
//RateLimit struct{
// PartSize int `json:"part_size"`
// PartSpeed int `json:"part_speed"`
//} `json:"rate_limit"`//rate limit
}
// token_login response bean
type TokenLoginResp struct {
RespError
Goto string `json:"goto"`
}
// token response bean
type TokenResp struct {
RespError
AccessToken string `json:"access_token"`
@@ -104,33 +147,18 @@ type TokenResp struct {
DeviceId string `json:"device_id"`
}
func HasPassword(files *Files) string {
fileList := files.Items
for i, file := range fileList {
if strings.HasPrefix(file.Name, ".password-") {
files.Items=fileList[:i+copy(fileList[i:],fileList[i+1:])]
return file.Name[10:]
}
}
return ""
// office_preview_url response bean
type OfficePreviewUrlResp struct {
RespError
PreviewUrl string `json:"preview_url"`
AccessToken string `json:"access_token"`
}
func HasReadme(files *Files) string {
fileList := files.Items
for _, file := range fileList {
if file.Name == "Readme.md" {
resp, err := http.Get(file.Url)
if err != nil {
log.Errorf("Get Readme出错:%s", err.Error())
return ""
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Errorf("读取 Readme出错:%s", err.Error())
return ""
}
return string(data)
}
}
return ""
type VideoPreviewUrlResp struct {
RespError
TemplateList []struct {
TemplateId string `json:"template_id"`
Status string `json:"status"`
Url string `json:"url"`
} `json:"template_list"`
}
+41
View File
@@ -0,0 +1,41 @@
package alidrive
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
"strings"
)
// check password
func HasPassword(files *Files) string {
fileList := files.Items
for i, file := range fileList {
if strings.HasPrefix(file.Name, ".password-") {
files.Items = fileList[:i+copy(fileList[i:], fileList[i+1:])]
return file.Name[10:]
}
}
return ""
}
// Deprecated: check readme, implemented by the front end now
func HasReadme(files *Files) string {
fileList := files.Items
for _, file := range fileList {
if file.Name == "Readme.md" {
resp, err := http.Get(file.Url)
if err != nil {
log.Errorf("Get Readme出错:%s", err.Error())
return ""
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Errorf("读取 Readme出错:%s", err.Error())
return ""
}
return string(data)
}
}
return ""
}
+1
View File
@@ -2,6 +2,7 @@ package main
import "github.com/Xhofe/alist/bootstrap"
// main function
func main() {
bootstrap.Run()
}
+18 -21
View File
@@ -6,31 +6,28 @@ import (
log "github.com/sirupsen/logrus"
)
// init aliyun drive
func InitAliDrive() bool {
log.Infof("初始化阿里云盘...")
//首先token_login
if conf.Conf.AliDrive.RefreshToken == "" {
tokenLogin,err:=alidrive.TokenLogin()
if err!=nil {
log.Errorf("登录失败:%s",err.Error())
return false
}
//然后get_token
token,err:=alidrive.GetToken(tokenLogin)
if err!=nil {
return false
}
conf.Authorization=token.TokenType+"\t"+token.AccessToken
}else {
conf.Authorization=conf.Bearer+conf.Conf.AliDrive.AccessToken
res := alidrive.RefreshTokenAll()
if res != "" {
log.Errorf("盘[%s]refresh_token失效,请检查", res)
}
log.Debugf("token:%s",conf.Authorization)
user,err:=alidrive.GetUserInfo()
if err != nil {
log.Errorf("初始化用户失败:%s",err.Error())
return false
log.Debugf("config:%+v", conf.Conf)
for i, _ := range conf.Conf.AliDrive.Drives {
InitDriveId(&conf.Conf.AliDrive.Drives[i])
}
log.Infof("当前用户信息:%+v",user)
alidrive.User=user
return true
}
func InitDriveId(drive *conf.Drive) bool {
user, err := alidrive.GetUserInfo(drive)
if err != nil {
log.Errorf("初始化盘[%s]失败:%s", drive.Name, err.Error())
return false
}
drive.DefaultDriveId = user.DefaultDriveId
log.Infof("初始化盘[%s]成功:%+v", drive.Name, user)
return true
}
-15
View File
@@ -1,15 +0,0 @@
package bootstrap
import (
"github.com/Xhofe/alist/conf"
"github.com/patrickmn/go-cache"
log "github.com/sirupsen/logrus"
"time"
)
func InitCache() {
if conf.Conf.Cache.Enable {
log.Infof("初始化缓存...")
conf.Cache=cache.New(time.Duration(conf.Conf.Cache.Expiration)*time.Minute,time.Duration(conf.Conf.Cache.CleanupInterval)*time.Minute)
}
}
+8 -3
View File
@@ -1,12 +1,17 @@
package bootstrap
import (
"crypto/tls"
"github.com/Xhofe/alist/conf"
log "github.com/sirupsen/logrus"
"net/http"
)
func InitClient() {
// init request client
func InitClient() {
log.Infof("初始化client...")
conf.Client=&http.Client{}
}
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
conf.Client = &http.Client{Transport: tr}
}
+32 -15
View File
@@ -2,6 +2,8 @@ package bootstrap
import (
"flag"
"fmt"
"github.com/Xhofe/alist/conf"
serv "github.com/Xhofe/alist/server"
"github.com/gin-gonic/gin"
@@ -9,21 +11,29 @@ import (
)
func init() {
flag.BoolVar(&conf.Debug,"debug",false,"use debug mode")
flag.BoolVar(&conf.Help,"help",false,"show usage help")
flag.StringVar(&conf.Con,"conf","conf.yml","config file")
flag.BoolVar(&conf.Debug, "debug", false, "use debug mode")
flag.BoolVar(&conf.Help, "help", false, "show usage help")
flag.BoolVar(&conf.Version, "version", false, "show version info")
flag.StringVar(&conf.ConfigFile, "conf", "conf.yml", "config file")
flag.BoolVar(&conf.SkipUpdate, "skip-update", false, "skip update")
}
func Run() {
// bootstrap run
func Run() {
flag.Parse()
if conf.Help {
flag.Usage()
return
}
if conf.Version {
fmt.Println("Current version:" + conf.VERSION)
return
}
start()
}
func printASC() {
// print asc
func printASC() {
log.Info(`
________ ___ ___ ________ _________
|\ __ \|\ \ |\ \|\ ____\|\___ ___\
@@ -36,11 +46,14 @@ func printASC() {
`)
}
// start server
func start() {
InitLog()
printASC()
CheckUpdate()
if !ReadConf(conf.Con) {
if !conf.SkipUpdate {
CheckUpdate()
}
if !ReadConf(conf.ConfigFile) {
log.Errorf("读取配置文件时出现错误,启动失败.")
return
}
@@ -49,18 +62,22 @@ func start() {
log.Errorf("初始化阿里云盘出现错误,启动失败.")
return
}
InitCache()
if !InitModel() {
log.Errorf("初始化数据库出现错误,启动失败.")
return
}
InitCron()
server()
}
// start http server
func server() {
baseServer:="0.0.0.0:"+conf.Conf.Server.Port
r:=gin.Default()
baseServer := conf.Conf.Server.Address + ":" + conf.Conf.Server.Port
r := gin.Default()
serv.InitRouter(r)
log.Infof("Starting server @ %s",baseServer)
err:=r.Run(baseServer)
if err!=nil {
log.Errorf("Server failed start:%s",err.Error())
log.Infof("Starting server @ %s", baseServer)
err := r.Run(baseServer)
if err != nil {
log.Errorf("Server failed start:%s", err.Error())
}
}
}
+63 -10
View File
@@ -9,23 +9,76 @@ import (
"strings"
)
// read config file
func ReadConf(config string) bool {
log.Infof("读取配置文件...")
if !utils.Exists(config) {
log.Infof("找不到配置文件:%s",config)
return false
log.Infof("找不到配置文件:%s", config)
if !Write(config) {
return false
}
}
confFile,err:=ioutil.ReadFile(config)
if err !=nil {
log.Errorf("读取配置文件时发生错误:%s",err.Error())
confFile, err := ioutil.ReadFile(config)
if err != nil {
log.Errorf("读取配置文件时发生错误:%s", err.Error())
return false
}
err = yaml.Unmarshal(confFile, conf.Conf)
if err !=nil {
log.Errorf("加载配置文件时发生错误:%s",err.Error())
if err != nil {
log.Errorf("加载配置文件时发生错误:%s", err.Error())
return false
}
log.Debugf("config:%+v",conf.Conf)
conf.Origins = strings.Split(conf.Conf.Server.SiteUrl,",")
log.Debugf("config:%+v", conf.Conf)
conf.Conf.Info.Roots = utils.GetNames()
conf.Origins = strings.Split(conf.Conf.Server.SiteUrl, ",")
return true
}
}
func Write(path string) bool {
log.Infof("创建默认配置文件")
file, err := utils.CreatNestedFile(path)
if err != nil {
log.Errorf("无法创建配置文件, %s", err)
return false
}
defer func() {
_ = file.Close()
}()
str := `
info:
title: AList #标题
logo: "" #网站logo 如果填写,则会替换掉默认的
footer_text: Xhofe's Blog #网页底部文字
footer_url: https://www.nn.ci #网页底部文字链接
music_img: https://img.xhofe.top/2020/12/19/0f8b57866bdb5.gif #预览音乐文件时的图片
check_update: true #前端是否显示更新
script: #自定义脚本,可以是脚本的链接,也可以直接是脚本内容
autoplay: true #视频是否自动播放
preview:
text: [txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp] #要预览的文本文件的后缀,可以自行添加
server:
address: "0.0.0.0"
port: "5244"
search: true
static: dist
site_url: '*'
password: password #用于重建目录
ali_drive:
api_url: https://api.aliyundrive.com/v2
max_files_count: 100
drives:
- refresh_token: xxx #refresh_token
root_folder: root #根目录的file_id
name: drive0 #盘名,多个盘不可重复,这里只是示例,不是一定要叫这个名字,可随意修改
password: pass #该盘密码,空('')则不设密码,修改需要重建生效
hide: false #是否在主页隐藏该盘,不可全部隐藏,至少暴露一个
database:
type: sqlite3
dBFile: alist.db
`
_, err = file.WriteString(str)
if err != nil {
log.Errorf("无法写入配置文件, %s", err)
return false
}
return true
}
+9 -7
View File
@@ -8,16 +8,18 @@ import (
var Cron *cron.Cron
func refreshToken() {
alidrive.RefreshToken()
// refresh token func for cron
func refreshToken() {
alidrive.RefreshTokenAll()
}
// init cron jobs
func InitCron() {
log.Infof("初始化定时任务:刷新token")
Cron=cron.New()
_,err:=Cron.AddFunc("@every 2h",refreshToken)
if err!=nil {
log.Errorf("添加启动任务失败:%s",err.Error())
Cron = cron.New()
_, err := Cron.AddFunc("@every 2h", refreshToken)
if err != nil {
log.Errorf("添加启动任务失败:%s", err.Error())
}
Cron.Start()
}
}
+7 -6
View File
@@ -6,16 +6,17 @@ import (
log "github.com/sirupsen/logrus"
)
// init logrus
func InitLog() {
if conf.Debug {
log.SetLevel(log.DebugLevel)
}else {
} else {
gin.SetMode(gin.ReleaseMode)
}
log.SetFormatter(&log.TextFormatter{
ForceColors:true,
EnvironmentOverrideColors:true,
TimestampFormat:"2006-01-02 15:04:05",
FullTimestamp:true,
ForceColors: true,
EnvironmentOverrideColors: true,
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
})
}
}
+74
View File
@@ -0,0 +1,74 @@
package bootstrap
import (
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/server/models"
"github.com/Xhofe/alist/utils"
log "github.com/sirupsen/logrus"
"gorm.io/driver/mysql"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"strings"
)
func InitModel() bool {
log.Infof("初始化数据库...")
dbConfig := conf.Conf.Database
switch dbConfig.Type {
case "sqlite3":
{
if !(strings.HasSuffix(dbConfig.DBFile, ".db") && len(dbConfig.DBFile) > 3) {
log.Errorf("db名称不正确.")
return false
}
needMigrate := !utils.Exists(dbConfig.DBFile)
db, err := gorm.Open(sqlite.Open(dbConfig.DBFile), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
TablePrefix: dbConfig.TablePrefix,
},
})
if err != nil {
log.Errorf("连接数据库出现错误:%s", err.Error())
return false
}
conf.DB = db
if needMigrate {
log.Infof("迁移数据库...")
err = conf.DB.AutoMigrate(&models.File{})
if err != nil {
log.Errorf("数据库迁移失败:%s", err.Error())
return false
}
//models.BuildTreeAll()
}
return true
}
case "mysql":
{
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
dbConfig.User, dbConfig.Password, dbConfig.Host, dbConfig.Port, dbConfig.Name)
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
TablePrefix: dbConfig.TablePrefix,
},
})
if err != nil {
log.Errorf("连接数据库出现错误:%s", err.Error())
return false
}
conf.DB = db
log.Infof("迁移数据库...")
err = conf.DB.AutoMigrate(&models.File{})
if err != nil {
log.Errorf("数据库迁移失败:%s", err.Error())
return false
}
return true
}
default:
log.Errorf("不支持的数据库类型:%s", dbConfig.Type)
return false
}
}
+23 -21
View File
@@ -9,37 +9,39 @@ import (
"net/http"
)
// github release response bean
type GithubRelease struct {
TagName string `json:"tag_name"`
HtmlUrl string `json:"html_url"`
Body string `json:"body"`
TagName string `json:"tag_name"`
HtmlUrl string `json:"html_url"`
Body string `json:"body"`
}
// check update
func CheckUpdate() {
log.Infof("检查更新...")
url:="https://api.github.com/repos/Xhofe/alist/releases/latest"
resp,err:=http.Get(url)
if err!=nil {
log.Warnf("检查更新失败:%s",err.Error())
url := "https://api.github.com/repos/Xhofe/alist/releases/latest"
resp, err := http.Get(url)
if err != nil {
log.Warnf("检查更新失败:%s", err.Error())
return
}
body,err:=ioutil.ReadAll(resp.Body)
if err!=nil {
log.Warnf("读取更新内容失败:%s",err.Error())
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Warnf("读取更新内容失败:%s", err.Error())
return
}
var release GithubRelease
err = json.Unmarshal(body,&release)
if err!=nil {
log.Warnf("解析更新失败:%s",err.Error())
err = json.Unmarshal(body, &release)
if err != nil {
log.Warnf("解析更新失败:%s", err.Error())
return
}
lasted:=release.TagName[1:]
now:=conf.VERSION[1:]
if utils.VersionCompare(lasted,now) != 1 {
log.Infof("当前已是最新版本:%s",conf.VERSION)
}else {
log.Infof("发现新版本:%s",release.TagName)
log.Infof("请至'%s'获取更新.",release.HtmlUrl)
lasted := release.TagName[1:]
now := conf.VERSION[1:]
if utils.VersionCompare(lasted, now) != 1 {
log.Infof("当前已是最新版本:%s", conf.VERSION)
} else {
log.Infof("发现新版本:%s", release.TagName)
log.Infof("请至'%s'获取更新.", release.HtmlUrl)
}
}
}

Some files were not shown because too many files have changed in this diff Show More