Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
02e665ae37 | |||
bacbf7bc1b | |||
4af469efed | |||
52cddc431a |
71
.github/workflows/build.yml
vendored
Normal file
71
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
platform: [ubuntu-latest]
|
||||||
|
go-version: [1.15]
|
||||||
|
name: Build
|
||||||
|
runs-on: ${{ matrix.platform }}
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go-version }}
|
||||||
|
|
||||||
|
- 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 alist_linux_amd64 alist.go
|
||||||
|
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -o alist_linux_arm64 alist.go
|
||||||
|
CC=arm-linux-gnueabihf-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm go build -o alist_linux_arm alist.go
|
||||||
|
|
||||||
|
- name: Build windows
|
||||||
|
run: |
|
||||||
|
CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o alist_windows_amd64.exe alist.go
|
||||||
|
|
||||||
|
- name: Upload artifacts linux_amd64
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: alist_linux_amd64
|
||||||
|
path: alist_linux_amd64
|
||||||
|
|
||||||
|
- name: Upload artifacts linux_arm64
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: alist_linux_arm64
|
||||||
|
path: alist_linux_arm64
|
||||||
|
|
||||||
|
- name: Upload artifacts linux_arm
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: alist_linux_arm
|
||||||
|
path: alist_linux_arm
|
||||||
|
|
||||||
|
- name: Upload artifacts windows_amd64
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: alist_windows_amd64
|
||||||
|
path: alist_windows_amd64.exe
|
10
README.md
10
README.md
@ -1,15 +1,16 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://img.oez.cc/2020/12/24/1fb16bc25a4f6.png" alt="RenewalManage Logo" width=200/>
|
<img src="https://img.oez.cc/2020/12/24/1fb16bc25a4f6.png" alt="AList Logo" width=200/>
|
||||||
</p>
|
</p>
|
||||||
<p align="center">
|
<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/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%3ARelease"><img src="https://github.com/Xhofe/alist/workflows/Release/badge.svg" alt="Release status"></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/RenewalManage/releases"><img src="https://img.shields.io/github/downloads/Xhofe/alist/latest/total" alt="Downloads"></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/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Xhofe/alist" alt="License"></a>
|
||||||
<a href="https://pay.xhofe.top">
|
<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" alt="donate">
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 这是什么?
|
### 这是什么?
|
||||||
@ -35,6 +36,7 @@
|
|||||||
- 目录加密
|
- 目录加密
|
||||||
- `Readme`渲染
|
- `Readme`渲染
|
||||||
- 自定义根目录
|
- 自定义根目录
|
||||||
|
- 文件直链下载
|
||||||
- …
|
- …
|
||||||
|
|
||||||
#### TODO
|
#### TODO
|
||||||
@ -54,7 +56,7 @@
|
|||||||
|
|
||||||
### 如何使用
|
### 如何使用
|
||||||
|
|
||||||
正在写……
|
- https://www.nn.ci/archives/alist.html
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
|
@ -175,6 +175,7 @@ func DoPost(url string,request interface{},auth bool) (body []byte, err error) {
|
|||||||
if body, err = ioutil.ReadAll(resp.Body); err != nil {
|
if body, err = ioutil.ReadAll(resp.Body); err != nil {
|
||||||
log.Errorf("读取api返回内容失败")
|
log.Errorf("读取api返回内容失败")
|
||||||
}
|
}
|
||||||
|
log.Debugf("请求返回信息:%s",string(body))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ type UserInfo struct {
|
|||||||
DomainId string `json:"domain_id"`
|
DomainId string `json:"domain_id"`
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
CreatedAt int `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
UpdatedAt int `json:"updated_at"`
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
NickName string `json:"nick_name"`
|
NickName string `json:"nick_name"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
@ -66,8 +66,8 @@ type File struct {
|
|||||||
ContentType string `json:"content_type"`
|
ContentType string `json:"content_type"`
|
||||||
Crc64Hash string `json:"crc_64_hash"`
|
Crc64Hash string `json:"crc_64_hash"`
|
||||||
DownloadUrl string `json:"download_url"`
|
DownloadUrl string `json:"download_url"`
|
||||||
PunishFlag int `json:"punish_flag"`
|
PunishFlag int64 `json:"punish_flag"`
|
||||||
Size int `json:"size"`
|
Size int64 `json:"size"`
|
||||||
Thumbnail string `json:"thumbnail"`
|
Thumbnail string `json:"thumbnail"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
ImageMediaMetadata map[string]interface{} `json:"image_media_metadata"`
|
ImageMediaMetadata map[string]interface{} `json:"image_media_metadata"`
|
||||||
@ -106,8 +106,9 @@ type TokenResp struct {
|
|||||||
|
|
||||||
func HasPassword(files *Files) string {
|
func HasPassword(files *Files) string {
|
||||||
fileList := files.Items
|
fileList := files.Items
|
||||||
for _, file := range fileList {
|
for i, file := range fileList {
|
||||||
if strings.HasPrefix(file.Name, ".password-") {
|
if strings.HasPrefix(file.Name, ".password-") {
|
||||||
|
files.Items=fileList[:i+copy(fileList[i:],fileList[i+1:])]
|
||||||
return file.Name[10:]
|
return file.Name[10:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func InitAliDrive() bool {
|
func InitAliDrive() bool {
|
||||||
|
log.Infof("初始化阿里云盘...")
|
||||||
//首先token_login
|
//首先token_login
|
||||||
if conf.Conf.AliDrive.RefreshToken == "" {
|
if conf.Conf.AliDrive.RefreshToken == "" {
|
||||||
tokenLogin,err:=alidrive.TokenLogin()
|
tokenLogin,err:=alidrive.TokenLogin()
|
||||||
@ -19,9 +20,10 @@ func InitAliDrive() bool {
|
|||||||
if err!=nil {
|
if err!=nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
conf.Authorization=token.TokenType+" "+token.AccessToken
|
conf.Authorization=token.TokenType+"\t"+token.AccessToken
|
||||||
|
}else {
|
||||||
|
conf.Authorization=conf.Bearer+conf.Conf.AliDrive.AccessToken
|
||||||
}
|
}
|
||||||
conf.Authorization=conf.Bearer+conf.Conf.AliDrive.AccessToken
|
|
||||||
log.Infof("token:%s",conf.Authorization)
|
log.Infof("token:%s",conf.Authorization)
|
||||||
user,err:=alidrive.GetUserInfo()
|
user,err:=alidrive.GetUserInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2,9 +2,11 @@ package bootstrap
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitClient() {
|
func InitClient() {
|
||||||
|
log.Infof("初始化client...")
|
||||||
conf.Client=&http.Client{}
|
conf.Client=&http.Client{}
|
||||||
}
|
}
|
@ -39,11 +39,11 @@ func printASC() {
|
|||||||
func start() {
|
func start() {
|
||||||
InitLog()
|
InitLog()
|
||||||
printASC()
|
printASC()
|
||||||
InitClient()
|
|
||||||
if !ReadConf(conf.Con) {
|
if !ReadConf(conf.Con) {
|
||||||
log.Errorf("读取配置文件时出现错误,启动失败.")
|
log.Errorf("读取配置文件时出现错误,启动失败.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
InitClient()
|
||||||
if !InitAliDrive() {
|
if !InitAliDrive() {
|
||||||
log.Errorf("初始化阿里云盘出现错误,启动失败.")
|
log.Errorf("初始化阿里云盘出现错误,启动失败.")
|
||||||
return
|
return
|
||||||
@ -54,9 +54,9 @@ func start() {
|
|||||||
|
|
||||||
func server() {
|
func server() {
|
||||||
baseServer:="0.0.0.0:"+conf.Conf.Server.Port
|
baseServer:="0.0.0.0:"+conf.Conf.Server.Port
|
||||||
log.Infof("Starting server @ %s",baseServer)
|
|
||||||
r:=gin.Default()
|
r:=gin.Default()
|
||||||
serv.InitRouter(r)
|
serv.InitRouter(r)
|
||||||
|
log.Infof("Starting server @ %s",baseServer)
|
||||||
err:=r.Run(baseServer)
|
err:=r.Run(baseServer)
|
||||||
if err!=nil {
|
if err!=nil {
|
||||||
log.Errorf("Server failed start:%s",err.Error())
|
log.Errorf("Server failed start:%s",err.Error())
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ReadConf(config string) bool {
|
func ReadConf(config string) bool {
|
||||||
|
log.Infof("读取配置文件...")
|
||||||
if !utils.Exists(config) {
|
if !utils.Exists(config) {
|
||||||
log.Infof("找不到配置文件:%s",config)
|
log.Infof("找不到配置文件:%s",config)
|
||||||
return false
|
return false
|
||||||
|
@ -4,7 +4,11 @@ type Config struct {
|
|||||||
Info struct{
|
Info struct{
|
||||||
Title string `yaml:"title" json:"title"`
|
Title string `yaml:"title" json:"title"`
|
||||||
SiteUrl string `yaml:"site_url" json:"site_url"`//网站url
|
SiteUrl string `yaml:"site_url" json:"site_url"`//网站url
|
||||||
|
BackendUrl string `yaml:"backend_url" json:"backend_url"`//后端地址
|
||||||
Logo string `yaml:"logo" json:"logo"`
|
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"`
|
} `yaml:"info"`
|
||||||
Server struct{
|
Server struct{
|
||||||
Port string `yaml:"port"`//端口
|
Port string `yaml:"port"`//端口
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Info(c *gin.Context) {
|
func Info(c *gin.Context) {
|
||||||
@ -101,4 +102,17 @@ func Search(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(200,dataResponse(files))
|
c.JSON(200,dataResponse(files))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Down(c *gin.Context) {
|
||||||
|
fileIdParam:=c.Param("file_id")
|
||||||
|
log.Debugf("down:%s",fileIdParam)
|
||||||
|
fileId:=strings.Split(fileIdParam,"/")[1]
|
||||||
|
file,err:=alidrive.GetFile(fileId)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200,metaResponse(500,err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Redirect(301,file.DownloadUrl)
|
||||||
|
return
|
||||||
}
|
}
|
@ -4,9 +4,11 @@ import (
|
|||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/gin-contrib/static"
|
"github.com/gin-contrib/static"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitRouter(engine *gin.Engine) {
|
func InitRouter(engine *gin.Engine) {
|
||||||
|
log.Infof("初始化路由...")
|
||||||
engine.Use(CrosHandler())
|
engine.Use(CrosHandler())
|
||||||
InitApiRouter(engine)
|
InitApiRouter(engine)
|
||||||
}
|
}
|
||||||
@ -23,4 +25,5 @@ func InitApiRouter(engine *gin.Engine) {
|
|||||||
v2.POST("/list",List)
|
v2.POST("/list",List)
|
||||||
v2.POST("/search",Search)
|
v2.POST("/search",Search)
|
||||||
}
|
}
|
||||||
|
engine.GET("/d/*file_id",Down)
|
||||||
}
|
}
|
@ -5,10 +5,11 @@ import (
|
|||||||
"github.com/Xhofe/alist/alidrive"
|
"github.com/Xhofe/alist/alidrive"
|
||||||
"github.com/Xhofe/alist/bootstrap"
|
"github.com/Xhofe/alist/bootstrap"
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func setup() {
|
||||||
bootstrap.InitLog()
|
bootstrap.InitLog()
|
||||||
bootstrap.ReadConf("../conf.yml")
|
bootstrap.ReadConf("../conf.yml")
|
||||||
bootstrap.InitClient()
|
bootstrap.InitClient()
|
||||||
@ -37,4 +38,10 @@ func TestGet(t *testing.T) {
|
|||||||
file,err:=alidrive.GetFile("5fb7c80e85e4f335cd344008be1b1b5349f74414")
|
file,err:=alidrive.GetFile("5fb7c80e85e4f335cd344008be1b1b5349f74414")
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
fmt.Println(file)
|
fmt.Println(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
setup()
|
||||||
|
code:=m.Run()
|
||||||
|
os.Exit(code)
|
||||||
}
|
}
|
13
test/string_test.go
Normal file
13
test/string_test.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSplit(t *testing.T) {
|
||||||
|
drive_id:="/123/456"
|
||||||
|
strs:=strings.Split(drive_id,"/")
|
||||||
|
fmt.Println(strs)
|
||||||
|
}
|
Reference in New Issue
Block a user