Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
f0013320a6 | |||
974caf74d9 | |||
0bb02664c7 | |||
6c5a0cba6e | |||
7e21e12e11 | |||
11489d8856 | |||
6d824a4ee9 | |||
8d74d070d4 | |||
77aae6660e | |||
76081a81a6 | |||
8760ab283d | |||
61ab27398c | |||
2e64df7e3d | |||
9561f0c951 | |||
03f5a54764 |
13
.github/workflows/build.yml
vendored
13
.github/workflows/build.yml
vendored
@ -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
|
||||
|
17
.github/workflows/release.yml
vendored
17
.github/workflows/release.yml
vendored
@ -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
|
||||
|
@ -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
80
alidrive/post_json.go
Normal 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
|
||||
}
|
@ -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"`
|
||||
}
|
||||
|
@ -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
|
||||
}
|
@ -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
41
alidrive/utils.go
Normal 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,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}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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"`
|
||||
|
@ -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"
|
||||
|
@ -31,3 +31,4 @@ func OfficePreview(c *gin.Context) {
|
||||
}
|
||||
c.JSON(200, DataResponse(preview))
|
||||
}
|
||||
|
||||
|
33
server/controllers/video_preview.go
Normal file
33
server/controllers/video_preview.go
Normal 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))
|
||||
}
|
@ -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)
|
||||
|
Reference in New Issue
Block a user