mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 21:13:10 +08:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d19b49a8d | |||
| 4fa11879f2 | |||
| abe9d9237a | |||
| e4d206d59c | |||
| 8636014397 | |||
| c0f50ffeff | |||
| b677d6ad21 | |||
| 443067b80f | |||
| 3138e031f5 | |||
| d137ef8759 | |||
| 389226662c | |||
| 9cb548d4f7 | |||
| 0e7083a713 | |||
| 46f09836f3 | |||
| e146054679 | |||
| 3b2a729dc6 | |||
| d18a752732 | |||
| b9676182c9 | |||
| 434eb25408 | |||
| 858291876b | |||
| dcebf5257f | |||
| 0cd4624a36 | |||
| fcd9c59089 | |||
| b394711859 | |||
| 495c3f25e9 | |||
| d5e3527bfb | |||
| ba7c33a2bb | |||
| bf3f741b22 |
@@ -1,4 +1,4 @@
|
||||
name: Build
|
||||
name: build
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Release
|
||||
name: release
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
|
||||
@@ -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分支版本)
|
||||
|
||||
### 预览
|
||||
|
||||
@@ -42,17 +44,16 @@
|
||||
#### TODO
|
||||
|
||||
- [x] 排序
|
||||
- [ ] 文件预览
|
||||
- [x] 文件预览
|
||||
- [x] 图片
|
||||
- [x] 视频
|
||||
- [x] 音频
|
||||
- [ ] 文档
|
||||
- [x] `Readme`渲染
|
||||
- [x] 密码加密
|
||||
- [ ] 搜索与翻页
|
||||
- [ ] 文件直链
|
||||
- [x] 文件直链
|
||||
- [ ] 路径优化
|
||||
- [ ] 缓存
|
||||
- [x] 缓存
|
||||
|
||||
### 如何使用
|
||||
|
||||
|
||||
+39
-36
@@ -8,68 +8,71 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// use token login
|
||||
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)
|
||||
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 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 &tokenLogin, nil
|
||||
}
|
||||
return nil,fmt.Errorf("登录token失效,请更换:%s",tokenLogin.Message)
|
||||
return nil, fmt.Errorf("登录token失效,请更换:%s", tokenLogin.Message)
|
||||
}
|
||||
|
||||
func GetToken(tokenLogin *TokenLoginResp) (*TokenResp,error) {
|
||||
// get access token
|
||||
func GetToken(tokenLogin *TokenLoginResp) (*TokenResp, error) {
|
||||
log.Infof("获取API token...")
|
||||
url:="https://websv.aliyundrive.com/token/get"
|
||||
code:=utils.GetCode(tokenLogin.Goto)
|
||||
url := "https://websv.aliyundrive.com/token/get"
|
||||
code := utils.GetCode(tokenLogin.Goto)
|
||||
if code == "" {
|
||||
return nil,fmt.Errorf("获取code出错")
|
||||
return nil, fmt.Errorf("获取code出错")
|
||||
}
|
||||
req:=GetTokenReq{Code:code}
|
||||
req := GetTokenReq{Code: code}
|
||||
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())
|
||||
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 nil, fmt.Errorf("code失效")
|
||||
}
|
||||
}
|
||||
return &token,nil
|
||||
return &token, nil
|
||||
}
|
||||
|
||||
// refresh access_token token by refresh_token
|
||||
func RefreshToken() bool {
|
||||
log.Infof("刷新token...")
|
||||
url:="https://websv.aliyundrive.com/token/refresh"
|
||||
req:=RefreshTokenReq{RefreshToken:conf.Conf.AliDrive.RefreshToken}
|
||||
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, false); 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())
|
||||
} else {
|
||||
if err = json.Unmarshal(body, &token); err != nil {
|
||||
log.Errorf("解析json[%s]出错:%s", string(body), err.Error())
|
||||
log.Errorf("此处json解析失败应该是refresh_token失效")
|
||||
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)
|
||||
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)
|
||||
return true
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package alidrive
|
||||
|
||||
var (
|
||||
User *UserInfo
|
||||
User *UserInfo
|
||||
)
|
||||
|
||||
+47
-26
@@ -1,46 +1,67 @@
|
||||
package alidrive
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// token_login request bean
|
||||
type TokenLoginReq struct {
|
||||
Token string `json:"token"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
// get_token request bean
|
||||
type GetTokenReq struct {
|
||||
Code string `json:"code"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
// refresh_token request bean
|
||||
type RefreshTokenReq struct {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
|
||||
// office_preview_url request bean
|
||||
type OfficePreviewUrlReq struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
DriveId string `json:"drive_id"`
|
||||
FileId string `json:"file_id"`
|
||||
}
|
||||
|
||||
+118
-115
File diff suppressed because it is too large
Load Diff
+54
-6
@@ -8,11 +8,37 @@ import (
|
||||
"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 +57,22 @@ 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"`
|
||||
}
|
||||
|
||||
// file response bean
|
||||
type File struct {
|
||||
RespError
|
||||
DriveId string `json:"drive_id"`
|
||||
@@ -72,18 +101,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,17 +143,26 @@ type TokenResp struct {
|
||||
DeviceId string `json:"device_id"`
|
||||
}
|
||||
|
||||
// office_preview_url response bean
|
||||
type OfficePreviewUrlResp struct {
|
||||
RespError
|
||||
PreviewUrl string `json:"preview_url"`
|
||||
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:])]
|
||||
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 {
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import "github.com/Xhofe/alist/bootstrap"
|
||||
|
||||
// main function
|
||||
func main() {
|
||||
bootstrap.Run()
|
||||
}
|
||||
+14
-13
@@ -6,31 +6,32 @@ 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())
|
||||
tokenLogin, err := alidrive.TokenLogin()
|
||||
if err != nil {
|
||||
log.Errorf("登录失败:%s", err.Error())
|
||||
return false
|
||||
}
|
||||
//然后get_token
|
||||
token,err:=alidrive.GetToken(tokenLogin)
|
||||
if err!=nil {
|
||||
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
|
||||
conf.Authorization = token.TokenType + "\t" + token.AccessToken
|
||||
} else {
|
||||
conf.Authorization = conf.Bearer + conf.Conf.AliDrive.AccessToken
|
||||
}
|
||||
log.Infof("token:%s",conf.Authorization)
|
||||
user,err:=alidrive.GetUserInfo()
|
||||
log.Debugf("token:%s", conf.Authorization)
|
||||
user, err := alidrive.GetUserInfo()
|
||||
if err != nil {
|
||||
log.Errorf("初始化用户失败:%s",err.Error())
|
||||
log.Errorf("初始化用户失败:%s", err.Error())
|
||||
return false
|
||||
}
|
||||
log.Infof("当前用户信息:%v",user)
|
||||
alidrive.User=user
|
||||
log.Infof("当前用户信息:%+v", user)
|
||||
alidrive.User = user
|
||||
return true
|
||||
}
|
||||
|
||||
+4
-3
@@ -6,7 +6,8 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func InitClient() {
|
||||
// init request client
|
||||
func InitClient() {
|
||||
log.Infof("初始化client...")
|
||||
conf.Client=&http.Client{}
|
||||
}
|
||||
conf.Client = &http.Client{}
|
||||
}
|
||||
|
||||
+30
-12
@@ -2,6 +2,7 @@ package bootstrap
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
serv "github.com/Xhofe/alist/server"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -9,21 +10,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.Con, "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,9 +45,13 @@ func printASC() {
|
||||
`)
|
||||
}
|
||||
|
||||
// start server
|
||||
func start() {
|
||||
InitLog()
|
||||
printASC()
|
||||
if !conf.SkipUpdate {
|
||||
CheckUpdate()
|
||||
}
|
||||
if !ReadConf(conf.Con) {
|
||||
log.Errorf("读取配置文件时出现错误,启动失败.")
|
||||
return
|
||||
@@ -48,17 +61,22 @@ func start() {
|
||||
log.Errorf("初始化阿里云盘出现错误,启动失败.")
|
||||
return
|
||||
}
|
||||
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 := "0.0.0.0:" + 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-8
@@ -6,24 +6,27 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// read config file
|
||||
func ReadConf(config string) bool {
|
||||
log.Infof("读取配置文件...")
|
||||
if !utils.Exists(config) {
|
||||
log.Infof("找不到配置文件:%s",config)
|
||||
log.Infof("找不到配置文件:%s", 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)
|
||||
log.Debugf("config:%+v", conf.Conf)
|
||||
conf.Origins = strings.Split(conf.Conf.Server.SiteUrl, ",")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
+8
-6
@@ -8,16 +8,18 @@ import (
|
||||
|
||||
var Cron *cron.Cron
|
||||
|
||||
func refreshToken() {
|
||||
// refresh token func for cron
|
||||
func refreshToken() {
|
||||
alidrive.RefreshToken()
|
||||
}
|
||||
|
||||
// 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
@@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/server/models"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func InitModel() bool {
|
||||
log.Infof("初始化数据库...")
|
||||
switch conf.Conf.Database.Type {
|
||||
case "sqlite3":
|
||||
{
|
||||
if !(strings.HasSuffix(conf.Conf.Database.DBFile, ".db") && len(conf.Conf.Database.DBFile) > 3) {
|
||||
log.Errorf("db名称不正确.")
|
||||
return false
|
||||
}
|
||||
needMigrate := !utils.Exists(conf.Conf.Database.DBFile)
|
||||
db, err := gorm.Open(sqlite.Open(conf.Conf.Database.DBFile), &gorm.Config{})
|
||||
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
|
||||
}
|
||||
if err := models.BuildTree(); err != nil {
|
||||
log.Errorf("构建目录树失败:%s", err.Error())
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
default:
|
||||
log.Errorf("不支持的数据库类型:%s", conf.Conf.Database.Type)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// github release response bean
|
||||
type GithubRelease struct {
|
||||
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())
|
||||
return
|
||||
}
|
||||
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())
|
||||
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)
|
||||
}
|
||||
}
|
||||
+26
-11
@@ -1,15 +1,30 @@
|
||||
info:
|
||||
title: AList
|
||||
site_url: http://localhost
|
||||
logo:
|
||||
title: AList #标题
|
||||
logo: "" #网站logo 如果填写,则会替换掉默认的
|
||||
footer_text: Xhofe's Blog #网页底部文字
|
||||
footer_url: https://www.nn.ci #网页底部文字链接
|
||||
music_img: https://img.oez.cc/2020/12/19/0f8b57866bdb5.gif #预览音乐文件时的图片
|
||||
check_update: true #前端是否显示更新
|
||||
script: #自定义脚本,可以是脚本的链接,也可以直接是脚本内容,如document.querySelector('body').style="background-image:url('https://api.mtyqx.cn/api/random.php');background-attachment:fixed"
|
||||
autoplay: true #视频是否自动播放
|
||||
preview:
|
||||
url: https://view.alist.nn.ci/onlinePreview?url= #extensions中包含的后缀名预览的地址,默认使用了kkFileView,可以自行搭建
|
||||
pre_process: [base64,encodeURIComponent] #对地址的处理,支持base64,encodeURIComponent,encodeURI
|
||||
extensions: [zip,rar,jar,tar,gzip] #使用上面的url预览的文件后缀,这是只是示例
|
||||
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] #要预览的文本文件的后缀,可以自行添加
|
||||
max_size: 5242880
|
||||
server:
|
||||
port: "5244"
|
||||
search: true
|
||||
static: dist
|
||||
port: "5244" #程序监听端口
|
||||
search: true #是否开启搜索接口,开启搜索之后密码和根目录都会失效,所以前端暂时不做搜索
|
||||
static: dist #前端文件目录
|
||||
site_url: '*' #建议直接填*,若有信任域名要求,可填写其他,逗号分割
|
||||
cache:
|
||||
enable: true #是否开启缓存
|
||||
expiration: 60 #缓存失效时间(单位:分钟)
|
||||
cleanup_interval: 120 #清理失效缓存间隔
|
||||
refresh_password: password #手动清理缓存密码
|
||||
ali_drive:
|
||||
api_url: https://api.aliyundrive.com/v2
|
||||
root_folder: root
|
||||
token:
|
||||
access_token:
|
||||
api_url: https://api.aliyundrive.com/v2 #阿里云盘api,无需修改
|
||||
root_folder: root #根目录
|
||||
refresh_token: need
|
||||
max_files_count: 3000
|
||||
max_files_count: 3000
|
||||
|
||||
+44
-23
@@ -1,27 +1,48 @@
|
||||
package conf
|
||||
|
||||
// config struct
|
||||
type Config struct {
|
||||
Info struct{
|
||||
Title string `yaml:"title" json:"title"`
|
||||
SiteUrl string `yaml:"site_url" json:"site_url"`//网站url
|
||||
BackendUrl string `yaml:"backend_url" json:"backend_url"`//后端地址
|
||||
Logo string `yaml:"logo" json:"logo"`
|
||||
FooterText string `yaml:"footer_text" json:"footer_text"`
|
||||
FooterUrl string `yaml:"footer_url" json:"footer_url"`
|
||||
MusicImg string `yaml:"music_img" json:"music_img"`
|
||||
} `yaml:"info"`
|
||||
Server struct{
|
||||
Port string `yaml:"port"`//端口
|
||||
Search bool `yaml:"search" json:"search"`//允许搜索
|
||||
Static string `yaml:"static"`
|
||||
} `yaml:"server"`
|
||||
AliDrive struct{
|
||||
ApiUrl string `yaml:"api_url"`//阿里云盘api
|
||||
RootFolder string `yaml:"root_folder"`//根目录id
|
||||
Info struct {
|
||||
Title string `yaml:"title" json:"title"`
|
||||
Logo string `yaml:"logo" json:"logo"`
|
||||
FooterText string `yaml:"footer_text" json:"footer_text"`
|
||||
FooterUrl string `yaml:"footer_url" json:"footer_url"`
|
||||
MusicImg string `yaml:"music_img" json:"music_img"`
|
||||
CheckUpdate bool `yaml:"check_update" json:"check_update"`
|
||||
Script string `yaml:"script" json:"script"`
|
||||
Autoplay bool `yaml:"autoplay" json:"autoplay"`
|
||||
Preview struct {
|
||||
Url string `yaml:"url" json:"url"`
|
||||
PreProcess []string `yaml:"pre_process" json:"pre_process"`
|
||||
Extensions []string `yaml:"extensions" json:"extensions"`
|
||||
Text []string `yaml:"text" json:"text"`
|
||||
MaxSize int `yaml:"max_size" json:"max_size"`
|
||||
} `yaml:"preview" json:"preview"`
|
||||
} `yaml:"info"`
|
||||
Server struct {
|
||||
Port string `yaml:"port"` //端口
|
||||
Search bool `yaml:"search"` //允许搜索
|
||||
Static string `yaml:"static"`
|
||||
SiteUrl string `yaml:"site_url"` //网站url
|
||||
Password string `yaml:"password"`
|
||||
} `yaml:"server"`
|
||||
AliDrive struct {
|
||||
ApiUrl string `yaml:"api_url"` //阿里云盘api
|
||||
RootFolder string `yaml:"root_folder"` //根目录id
|
||||
//Authorization string `yaml:"authorization"`//授权token
|
||||
LoginToken string `yaml:"login_token"`
|
||||
AccessToken string `yaml:"access_token"`
|
||||
RefreshToken string `yaml:"refresh_token"`
|
||||
MaxFilesCount int `yaml:"max_files_count"`
|
||||
} `yaml:"ali_drive"`
|
||||
}
|
||||
LoginToken string `yaml:"login_token"`
|
||||
AccessToken string `yaml:"access_token"`
|
||||
RefreshToken string `yaml:"refresh_token"`
|
||||
MaxFilesCount int `yaml:"max_files_count"`
|
||||
} `yaml:"ali_drive"`
|
||||
Database struct {
|
||||
Type string `yaml:"type"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
Name string `yaml:"name"`
|
||||
TablePrefix string `yaml:"tablePrefix"`
|
||||
DBFile string `yaml:"dBFile"`
|
||||
} `yaml:"database"`
|
||||
}
|
||||
|
||||
+28
-20
@@ -1,32 +1,40 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var(
|
||||
Debug bool
|
||||
Help bool
|
||||
Con string
|
||||
Client *http.Client
|
||||
Authorization string
|
||||
var (
|
||||
Debug bool // is debug command
|
||||
Help bool // is help command
|
||||
Version bool // is print version command
|
||||
Con string // config file
|
||||
SkipUpdate bool // skip update
|
||||
|
||||
Client *http.Client // request client
|
||||
Authorization string // authorization string
|
||||
|
||||
DB *gorm.DB
|
||||
|
||||
Origins []string // allow origins
|
||||
)
|
||||
|
||||
var Conf = new(Config)
|
||||
|
||||
const (
|
||||
VERSION="0.1.0"
|
||||
VERSION = "v1.0.0"
|
||||
|
||||
ImageThumbnailProcess="image/resize,w_50"
|
||||
VideoThumbnailProcess="video/snapshot,t_0,f_jpg,w_50"
|
||||
ImageUrlProcess="image/resize,w_1920/format,jpeg"
|
||||
ASC="ASC"
|
||||
DESC="DESC"
|
||||
OrderUpdatedAt="updated_at"
|
||||
OrderCreatedAt="created_at"
|
||||
OrderSize="size"
|
||||
OrderName="name"
|
||||
OrderSearch="type ASC,updated_at DESC"
|
||||
AccessTokenInvalid="AccessTokenInvalid"
|
||||
Bearer="Bearer\t"
|
||||
)
|
||||
ImageThumbnailProcess = "image/resize,w_50"
|
||||
VideoThumbnailProcess = "video/snapshot,t_0,f_jpg,w_50"
|
||||
ImageUrlProcess = "image/resize,w_1920/format,jpeg"
|
||||
ASC = "ASC"
|
||||
DESC = "DESC"
|
||||
OrderUpdatedAt = "updated_at"
|
||||
OrderCreatedAt = "created_at"
|
||||
OrderSize = "size"
|
||||
OrderName = "name"
|
||||
OrderSearch = "type ASC,updated_at DESC"
|
||||
AccessTokenInvalid = "AccessTokenInvalid"
|
||||
Bearer = "Bearer\t"
|
||||
)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user