Compare commits

...

15 Commits

Author SHA1 Message Date
f0013320a6 🔖 release v1.0.3 2021-04-09 10:45:16 +08:00
974caf74d9 🔥 只初始化一次client 2021-04-09 10:38:57 +08:00
0bb02664c7 🐛 fix: #85 修复 x509: certificate signed by unknown authority (#86)
* 修复 x509: certificate signed by unknown authority

* 添加忽略证书验证
2021-04-09 10:30:03 +08:00
6c5a0cba6e 🐛 修复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
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
9561f0c951 update conf.yml.example 2021-03-17 18:25:20 +08:00
03f5a54764 allow to set address in configuration file 2021-03-17 18:08:22 +08:00
16 changed files with 226 additions and 112 deletions

View File

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

View File

@ -47,11 +47,17 @@ jobs:
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
@ -105,6 +111,17 @@ jobs:
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

View File

@ -10,8 +10,8 @@ import (
// refresh access_token token by refresh_token
func RefreshToken(drive *conf.Drive) bool {
log.Infof("刷新[%s]token...", drive.Name)
url := "https://websv.aliyundrive.com/token/refresh"
req := RefreshTokenReq{RefreshToken: drive.RefreshToken}
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, ""); err != nil {
log.Errorf("tokenLogin-doPost出错:%s", err.Error())
@ -23,6 +23,10 @@ func RefreshToken(drive *conf.Drive) bool {
return false
}
}
if token.Code != "" {
log.Errorf("盘[%s]刷新token出错%s", drive.Name, token.Message)
return false
}
//刷新成功 更新token
drive.AccessToken = token.AccessToken
drive.RefreshToken = token.RefreshToken

80
alidrive/post_json.go Normal file
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
}

View File

@ -57,6 +57,7 @@ type GetTokenReq struct {
// refresh_token request bean
type RefreshTokenReq struct {
RefreshToken string `json:"refresh_token"`
GrantType string `json:"grant_type"`
}
// office_preview_url request bean
@ -65,3 +66,9 @@ type OfficePreviewUrlReq struct {
DriveId string `json:"drive_id"`
FileId string `json:"file_id"`
}
// video preview url request bean
type VideoPreviewUrlReq struct {
DriveId string `json:"drive_id"`
FileId string `json:"file_id"`
}

View File

@ -1,15 +1,8 @@
package alidrive
import (
"bytes"
"encoding/json"
"fmt"
"github.com/Xhofe/alist/conf"
log "github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
"strings"
"time"
)
// get file
@ -115,69 +108,16 @@ func GetOfficePreviewUrl(fileId string, drive *conf.Drive) (*OfficePreviewUrlRes
return &resp, nil
}
// 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
}
// get video preview url
func GetVideoPreviewUrl(fileId string, drive *conf.Drive) (*VideoPreviewUrlResp, error) {
url := conf.Conf.AliDrive.ApiUrl + "/databox/get_video_play_info"
req := VideoPreviewUrlReq{
DriveId: drive.DefaultDriveId,
FileId: fileId,
}
if resp.IsAvailable() {
return nil
var resp VideoPreviewUrlResp
if err := BodyToJson(url, req, &resp, drive); err != nil {
return nil, err
}
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
}
return &resp, nil
}

View File

@ -1,10 +1,6 @@
package alidrive
import (
log "github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
"strings"
"time"
)
@ -150,35 +146,11 @@ type OfficePreviewUrlResp struct {
AccessToken string `json:"access_token"`
}
// 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 ""
type VideoPreviewUrlResp struct {
RespError
TemplateList []struct {
TemplateId string `json:"template_id"`
Status string `json:"status"`
Url string `json:"url"`
} `json:"template_list"`
}

41
alidrive/utils.go Normal file
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 ""
}

View File

@ -1,6 +1,7 @@
package bootstrap
import (
"crypto/tls"
"github.com/Xhofe/alist/conf"
log "github.com/sirupsen/logrus"
"net/http"
@ -9,5 +10,8 @@ import (
// 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}
}

View File

@ -3,6 +3,7 @@ package bootstrap
import (
"flag"
"fmt"
"github.com/Xhofe/alist/conf"
serv "github.com/Xhofe/alist/server"
"github.com/gin-gonic/gin"
@ -71,7 +72,7 @@ func start() {
// start http server
func server() {
baseServer := "0.0.0.0:" + conf.Conf.Server.Port
baseServer := conf.Conf.Server.Address + ":" + conf.Conf.Server.Port
r := gin.Default()
serv.InitRouter(r)
log.Infof("Starting server @ %s", baseServer)

View File

@ -10,6 +10,7 @@ info:
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

View File

@ -31,6 +31,7 @@ type Config struct {
} `yaml:"preview" json:"preview"`
} `yaml:"info"`
Server struct {
Address string `yaml:"address"`
Port string `yaml:"port"` //端口
Search bool `yaml:"search"` //允许搜索
Static string `yaml:"static"`

View File

@ -22,7 +22,7 @@ var (
var Conf = new(Config)
const (
VERSION = "v1.0.1"
VERSION = "v1.0.3"
ImageThumbnailProcess = "image/resize,w_50"
VideoThumbnailProcess = "video/snapshot,t_0,f_jpg,w_50"

View File

@ -31,3 +31,4 @@ func OfficePreview(c *gin.Context) {
}
c.JSON(200, DataResponse(preview))
}

View File

@ -0,0 +1,33 @@
package controllers
import (
"github.com/Xhofe/alist/alidrive"
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
type VideoPreviewReq struct {
FileId string `json:"file_id" binding:"required"`
}
// handle video_preview request
func VideoPreview(c *gin.Context) {
drive := utils.GetDriveByName(c.Param("drive"))
if drive == nil {
c.JSON(200, MetaResponse(400, "drive isn't exist."))
return
}
var req VideoPreviewReq
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
return
}
log.Debugf("preview_req:%+v", req)
preview, err := alidrive.GetVideoPreviewUrl(req.FileId, drive)
if err != nil {
c.JSON(200, MetaResponse(500, err.Error()))
return
}
c.JSON(200, DataResponse(preview))
}

View File

@ -27,6 +27,7 @@ func InitApiRouter(engine *gin.Engine) {
apiV2.POST("/get", controllers.Get)
apiV2.POST("/path", controllers.Path)
apiV2.POST("/office_preview/:drive", controllers.OfficePreview)
apiV2.POST("/video_preview/:drive", controllers.VideoPreview)
apiV2.POST("/local_search", controllers.LocalSearch)
apiV2.POST("/global_search", controllers.GlobalSearch)
apiV2.GET("/rebuild/:drive/:password", controllers.RebuildTree)