Compare commits

..

104 Commits

Author SHA1 Message Date
微凉 1d7d37e642 :bug: fix onedrive sort 2021-12-01 11:25:33 +08:00
微凉 b62a716267 ✨ remove onedrive empty cache 2021-12-01 11:25:04 +08:00
微凉 944941db10 🎇 support https 2021-12-01 00:19:06 +08:00
微凉 bd91acc5d0 :bug: fix lanzou webdav time error 2021-12-01 00:15:34 +08:00
微凉 cd50227835 🎇 support lanzou 2021-11-30 21:30:50 +08:00
微凉 50226f66e3 ✨ google default root folder 2021-11-30 19:10:27 +08:00
微凉 9dcaa9b07a 🎨 add types 2021-11-30 18:53:37 +08:00
微凉 fa6c0f78bc :bug: fix windows sharepoint path error 2021-11-30 16:45:08 +08:00
微凉 7f35dc6ade ✨ add onedrive thumbnail 2021-11-30 16:27:23 +08:00
微凉 5d6463b75a 🎨 move code 2021-11-30 10:00:06 +08:00
微凉 733b38b435 🎨 improve code structure 2021-11-30 09:37:51 +08:00
微凉 50a02a7af7 :fire: remove useless code 2021-11-29 21:30:52 +08:00
微凉 71b1517de7 :bug: fix windows check parent password 2021-11-29 21:09:16 +08:00
微凉 ffdd88ec66 ✨ webdav proxy 2021-11-29 16:42:46 +08:00
微凉 4ff2756572 :bug: fix 123pan webdav can't get 2021-11-29 16:06:49 +08:00
微凉 d955038ebc ✨ delete useless path unescape 2021-11-29 16:05:58 +08:00
微凉 72d5e4e691 ✨ delete useless log 2021-11-29 16:05:14 +08:00
微凉 b1e662cd34 :bug: fix onedrive slow response 2021-11-28 17:01:27 +08:00
微凉 0f0e1104a4 ✨ WebDAV auth 2021-11-28 16:18:09 +08:00
微凉 3041da35ab :bug: fix webdav proxy link auth 2021-11-28 16:05:41 +08:00
微凉 9eab54a7c8 ✨ webdav(view only) 2021-11-28 15:10:48 +08:00
微凉 0b8d3a0a2c :bug: fix can't get file 2021-11-28 15:10:06 +08:00
微凉 f9945a14a8 🎇 webdav unfinished 2021-11-28 00:12:04 +08:00
微凉 c39752ceb4 🎇 optimization googledrive 2021-11-27 20:40:03 +08:00
微凉 53b383d2cf 🔨 refactor driver: onedrive 2021-11-27 20:20:14 +08:00
微凉 e76fc3e616 🔨 refactor driver: native 2021-11-27 20:07:32 +08:00
微凉 eb21b87020 🔨 refactor driver: google 2021-11-27 19:52:38 +08:00
微凉 f577d82242 🔨 refactor driver: ali 2021-11-27 19:40:36 +08:00
微凉 98691b2aa8 🔨 refactor driver(123 and 189) 2021-11-27 18:55:09 +08:00
微凉 4fe6ed6c3e :bug: fix log 2021-11-26 20:23:33 +08:00
微凉 fe73ece57d ✨ change log 2021-11-26 20:20:32 +08:00
微凉 59b8f1084a :bug: fixed checking the parent folder when checked the password of the current folder 2021-11-25 16:24:39 +08:00
微凉 2f669ac45c 📝 update doc 2021-11-24 18:58:17 +08:00
微凉 d03d91d518 :bug: fix google drive root folder label 2021-11-24 13:34:15 +08:00
微凉 fe981f67ec :bug: fix windows check parent 2021-11-23 16:22:23 +08:00
微凉 8cfabfd0f5 ✨ resolved #170 native driver sort 2021-11-23 16:09:42 +08:00
微凉 163ee1159e ✨ change path interface 2021-11-23 15:58:03 +08:00
微凉 e31402e94f ✨ resolved #169 2021-11-23 15:46:10 +08:00
微凉 5500980d63 :bug: fix onedrive get files 2021-11-23 15:39:09 +08:00
微凉 b1695445e0 :bug: index add write header now 2021-11-22 18:10:09 +08:00
微凉 5db1ad4adf 🎇 resolved #160 2021-11-17 22:19:11 +08:00
微凉 725f5b0c55 ✨ support 123pan 2021-11-17 22:17:04 +08:00
微凉 87a74394b3 ✨ google client retry 2021-11-17 20:40:42 +08:00
微凉 a41c820525 :bug: fix debug output 2021-11-17 20:29:01 +08:00
微凉 cd53dc6d24 📝 update readme 2021-11-17 17:37:41 +08:00
微凉 cfe16b5ed2 ✨ add GoogleDrive 2021-11-17 17:21:11 +08:00
微凉 3d9746485d ✨ change proxy setting 2021-11-17 17:20:57 +08:00
微凉 0b7f2fee7d ✨ proxy add account 2021-11-17 16:37:12 +08:00
微凉 36d52e0b75 ✨ delete cache file 2021-11-17 16:25:32 +08:00
微凉 e4d254e4b0 ✨ simplify delete account when change name 2021-11-17 15:25:31 +08:00
微凉 e8d27a30b4 :bug: fix delete account when change name 2021-11-17 15:21:51 +08:00
微凉 69514668cc 🎇 replace title 2021-11-16 22:32:05 +08:00
微凉 e5f8f59c87 :bug: fix native account status 2021-11-16 18:23:59 +08:00
微凉 f87ee1ed9e :bug: fix 189 account status 2021-11-16 15:08:55 +08:00
微凉 07155cfd01 ✨ add show current password 2021-11-16 15:00:56 +08:00
微凉 5e982980dc :bug: fix determine gbk 2021-11-16 00:03:49 +08:00
微凉 8987958e26 :bug: fix 189 size and time 2021-11-15 20:31:44 +08:00
微凉 4466cb19a5 🎇 get 189 redirect url 2021-11-15 20:15:25 +08:00
微凉 da74e29b26 :bug: fix gbk garbled 2021-11-15 19:20:39 +08:00
微凉 82272fcbf5 :bug: fix windows onedrive path 2021-11-15 19:07:04 +08:00
微凉 74d86f8cc4 🎇 delete useless cookieJar 2021-11-15 19:06:44 +08:00
微凉 c03646dedf :bug: change text proxy 2021-11-15 19:06:10 +08:00
微凉 c0d1888e25 ✨ support 189cloud(login refer to PanIndex) 2021-11-15 18:00:43 +08:00
微凉 f4942e89bd :bug: fix account status 2021-11-15 15:01:14 +08:00
微凉 27e61c9eb8 :bug: fix change name error 2021-11-15 14:54:22 +08:00
微凉 aeb72320ca :bug: fix get error account 2021-11-15 14:53:32 +08:00
微凉 caddba05e9 💚 remove ppc64le docker 2021-11-14 14:53:23 +08:00
微凉 0dffb9aaa1 ✨ add customize style / script 2021-11-14 14:37:26 +08:00
微凉 0f93d2bfed :bug: fix version type 2021-11-14 00:30:15 +08:00
微凉 b785945210 :bug: fix add account 2021-11-13 19:31:35 +08:00
微凉 48a65784c7 :bug: fix can't delete and get meta 2021-11-13 17:10:44 +08:00
微凉 5f34b8ab80 ✨ account and meta add id 2021-11-13 16:49:03 +08:00
微凉 959ef620fb ✨ check parent folder password 2021-11-13 16:12:12 +08:00
微凉 a73501463f ✨ fix proxy 2021-11-13 16:02:19 +08:00
微凉 cf07b3921c 🔨 switch fiber to gin 2021-11-13 15:53:26 +08:00
微凉 65ec4e3611 ✨ dockerfile volume 2021-11-13 14:23:41 +08:00
微凉 7799c1f3bc 🎇 change default setting 2021-11-12 23:03:39 +08:00
微凉 e902c2ded7 ✨ add settings 2021-11-12 22:56:30 +08:00
微凉 2c675ae909 ✨ change settings 2021-11-12 19:39:01 +08:00
微凉 98c017730f ✨ resolved #155 2021-11-11 19:51:25 +08:00
微凉 f4affb2c69 ✨ add go proxy 2021-11-09 21:36:27 +08:00
微凉 17af21079f 💚 fix web path 2021-11-09 19:35:46 +08:00
微凉 f7d35ec925 💚 fix dockerfile 2021-11-09 18:12:36 +08:00
微凉 a8730e82b5 💚 fix dockerfile 2021-11-09 18:02:15 +08:00
微凉 6275e27d1b 💚 fix dockerfile 2021-11-09 17:54:38 +08:00
微凉 e70353704f 💚 fix dockerfile 2021-11-09 17:22:58 +08:00
微凉 be5b1e42d4 💚 fix dockerfile 2021-11-09 16:51:30 +08:00
微凉 7d08cbc4a9 🚧 build docker 2021-11-09 16:46:03 +08:00
微凉 1542878d66 🎨 format code 2021-11-09 16:03:04 +08:00
微凉 ac8f5d5737 :bug: file name contains + 2021-11-07 23:05:50 +08:00
微凉 9ed5b6e581 :bug: file name contains + 2021-11-07 22:12:52 +08:00
微凉 db7bff2d61 :bug: fix: #151 2021-11-07 14:04:54 +08:00
微凉 7970e737f0 ✨ add markdown theme setting 2021-11-06 17:33:00 +08:00
微凉 d4523d52ee :bug: delete timed task 2021-11-06 17:25:07 +08:00
微凉 ac8476702c :bug: refer to https://github.com/ad-m/github-push-action/issues/44#issuecomment-581706892 2021-11-05 20:52:50 +08:00
微凉 12f68eaed9 💚 fix upload asserts 2021-11-05 19:47:02 +08:00
微凉 6a51f02845 💚 mv build.sh 2021-11-05 19:11:39 +08:00
微凉 e7071e1093 ✨ release asserts files cdn 2021-11-05 19:03:54 +08:00
微凉 11b141b190 ✨ update onedrive account status 2021-11-05 16:32:20 +08:00
微凉 7e099b39cf ✨ cache len(files)=0: request 2021-11-05 16:30:50 +08:00
微凉 b46bf0dfc9 :bug: delete beta1 meta 2021-11-04 23:25:53 +08:00
微凉 91f64161b2 💚 change back to ubuntu 2021-11-04 22:38:08 +08:00
微凉 8255ef4346 💚 print md5 2021-11-04 21:34:52 +08:00
微凉 254b6c6f79 ✨ print build version 2021-11-04 18:42:27 +08:00
63 changed files with 10320 additions and 941 deletions
+5 -13
View File
@@ -10,7 +10,7 @@ jobs:
build:
strategy:
matrix:
platform: [macos-latest]
platform: [ubuntu-latest]
go-version: [1.17]
name: Build
runs-on: ${{ matrix.platform }}
@@ -25,8 +25,8 @@ jobs:
with:
node-version: '16'
- name: Setup docker
uses: docker-practice/actions-setup-docker@master
# - name: Setup docker
# uses: docker-practice/actions-setup-docker@master
- name: Checkout
uses: actions/checkout@v2
@@ -45,20 +45,12 @@ jobs:
run: |
docker pull techknowlogick/xgo:latest
go install src.techknowlogick.com/xgo@latest
brew install upx
- name: Build web
run: |
cd alist-web
yarn
yarn build
cd ..
sudo apt install upx
- name: Build
run: |
cd alist
mv alist/build.sh .
bash build.sh
cd ..
- name: Upload artifact
uses: actions/upload-artifact@v2
+48
View File
@@ -0,0 +1,48 @@
name: docker
on:
push:
branches:
- 'v2'
tags:
- 'v*'
pull_request:
branches:
- 'v2'
jobs:
docker:
name: Docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: xhofe/alist
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Build web
run: bash build.sh web
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: xhofe
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x
+17 -13
View File
@@ -9,7 +9,7 @@ jobs:
release:
strategy:
matrix:
platform: [macos-latest]
platform: [ubuntu-latest]
go-version: [1.17]
name: Release
runs-on: ${{ matrix.platform }}
@@ -19,8 +19,8 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Setup docker
uses: docker-practice/actions-setup-docker@master
# - name: Setup docker
# uses: docker-practice/actions-setup-docker@master
- name: Setup Node
uses: actions/setup-node@v2
@@ -32,6 +32,8 @@ jobs:
with:
ref: v2
path: alist
persist-credentials: false
fetch-depth: 0
- name: Checkout web repo
uses: actions/checkout@v2
@@ -39,25 +41,27 @@ jobs:
repository: Xhofe/alist-web
ref: v2
path: alist-web
persist-credentials: false
fetch-depth: 0
- name: Set up xgo
run: |
docker pull techknowlogick/xgo:latest
go install src.techknowlogick.com/xgo@latest
brew install upx
- name: Build web
run: |
cd alist-web
yarn
yarn build
cd ..
sudo apt install upx
- name: Build
run: |
cd alist
mv alist/build.sh .
bash build.sh release
cd ..
- name: Upload asserts files
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.MY_TOKEN }}
branch: cdn
directory: alist-web
repository: Xhofe/alist-web
- name: Release
uses: softprops/action-gh-release@v1
+2 -1
View File
@@ -24,4 +24,5 @@ bin/*
alist
*.json
public/index.html
public/assets/
public/assets/
data/
+14
View File
@@ -0,0 +1,14 @@
FROM alpine:edge as builder
LABEL stage=go-builder
WORKDIR /app/
COPY ./ ./
RUN apk add --no-cache bash git go gcc musl-dev; \
sh build.sh docker
FROM alpine:edge
LABEL MAINTAINER="i@nn.ci"
VOLUME /opt/alist/data/
WORKDIR /opt/alist/
COPY --from=builder /app/bin/alist ./
EXPOSE 5244
CMD [ "./alist" ]
+6 -3
View File
@@ -13,7 +13,7 @@
### 这是什么?
一款支持多种存储的目录文件列表程序,后端基于`go-fiber`,前端使用`react`。
一款支持多种存储的目录文件列表程序,后端基于`gin`,前端使用`react`。
### 前端项目地址
@@ -31,12 +31,15 @@
- 本地存储
- 阿里云盘
- Onedrive
- Onedrive/世纪互联
- 天翼云盘
- GoogleDrive
- 123pan
- ...
### 如何使用
- https://www.nn.ci/archives/alist.html
- https://alist-doc.nn.ci/
### License
+34 -16
View File
@@ -5,43 +5,61 @@ import (
"fmt"
"github.com/Xhofe/alist/bootstrap"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/public"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/server"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"net/http"
)
func init() {
flag.StringVar(&conf.ConfigFile, "conf", "config.json", "config file")
flag.StringVar(&conf.ConfigFile, "conf", "data/config.json", "config file")
flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode")
flag.BoolVar(&conf.Version, "version", false, "print version info")
flag.BoolVar(&conf.Password, "password", false, "print current password")
flag.Parse()
}
func Init() {
func Init() bool {
bootstrap.InitLog()
bootstrap.InitConf()
bootstrap.InitCron()
bootstrap.InitModel()
if conf.Password {
pass, err := model.GetSettingByKey("password")
if err != nil {
log.Errorf(err.Error())
return false
}
log.Infof("current password: %s", pass.Value)
return false
}
bootstrap.InitSettings()
bootstrap.InitAccounts()
bootstrap.InitCache()
return true
}
func main() {
if conf.Version {
fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion:%s\n", conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.GitTag)
fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion: %s\n", conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.GitTag)
return
}
Init()
app := fiber.New()
server.InitApiRouter(app)
app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(public.Public),
NotFoundFile: "index.html",
}))
log.Info("starting server")
err := app.Listen(fmt.Sprintf(":%d", conf.Conf.Port))
if !Init() {
return
}
if !conf.Debug {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()
server.InitApiRouter(r)
base := fmt.Sprintf("%s:%d", conf.Conf.Address, conf.Conf.Port)
log.Infof("start server @ %s", base)
var err error
if conf.Conf.Https {
err = r.RunTLS(base, conf.Conf.CertFile, conf.Conf.KeyFile)
} else {
err = r.Run(base)
}
if err != nil {
log.Errorf("failed to start: %s", err.Error())
}
+30
View File
@@ -0,0 +1,30 @@
package bootstrap
import (
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/model"
log "github.com/sirupsen/logrus"
)
func InitAccounts() {
log.Infof("init accounts...")
var accounts []model.Account
if err := conf.DB.Find(&accounts).Error; err != nil {
log.Fatalf("failed sync init accounts")
}
for i, account := range accounts {
model.RegisterAccount(account)
driver, ok := drivers.GetDriver(account.Type)
if !ok {
log.Errorf("no [%s] driver", account.Type)
} else {
err := driver.Save(&accounts[i], nil)
if err != nil {
log.Errorf("init account [%s] error:[%s]", account.Name, err.Error())
} else {
log.Infof("success init account: %s, type: %s", account.Name, account.Type)
}
}
}
}
+4
View File
@@ -13,6 +13,10 @@ func InitConf() {
log.Infof("reading config file: %s", conf.ConfigFile)
if !utils.Exists(conf.ConfigFile) {
log.Infof("config file not exists, creating default config file")
_, err := utils.CreatNestedFile(conf.ConfigFile)
if err != nil {
log.Fatalf("failed to create config file")
}
conf.Conf = conf.DefaultConfig()
if !utils.WriteToJson(conf.ConfigFile, conf.Conf) {
log.Fatalf("failed to create default config file")
+2 -1
View File
@@ -5,7 +5,7 @@ import (
log "github.com/sirupsen/logrus"
)
// initLog init log
// InitLog init log
func InitLog() {
if conf.Debug {
log.SetLevel(log.DebugLevel)
@@ -18,4 +18,5 @@ func InitLog() {
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
})
log.Infof("init log...")
}
+1 -109
View File
@@ -3,7 +3,6 @@ package bootstrap
import (
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/model"
log "github.com/sirupsen/logrus"
"gorm.io/driver/mysql"
@@ -72,117 +71,10 @@ func InitModel() {
default:
log.Fatalf("not supported database type: %s", databaseConfig.Type)
}
log.Infof("auto migrate model")
log.Infof("auto migrate model...")
err := conf.DB.AutoMigrate(&model.SettingItem{}, &model.Account{}, &model.Meta{})
if err != nil {
log.Fatalf("failed to auto migrate")
}
// TODO init filetype
initAccounts()
initSettings()
}
func initAccounts() {
log.Infof("init accounts...")
var accounts []model.Account
if err := conf.DB.Find(&accounts).Error; err != nil {
log.Fatalf("failed sync init accounts")
}
for _, account := range accounts {
model.RegisterAccount(account)
driver, ok := drivers.GetDriver(account.Type)
if !ok {
log.Errorf("no [%s] driver", driver)
} else {
err := driver.Save(&account, nil)
if err != nil {
log.Errorf("init account [%s] error:[%s]", account.Name, err.Error())
}
}
}
}
func initSettings() {
log.Infof("init settings...")
version := model.SettingItem{
Key: "version",
Value: conf.GitTag,
Description: "version",
Group: model.CONST,
}
_ = model.SaveSetting(version)
settings := []model.SettingItem{
{
Key: "title",
Value: "Alist",
Description: "title",
Group: model.PUBLIC,
},
{
Key: "password",
Value: "alist",
Description: "password",
Group: model.PRIVATE,
},
{
Key: "logo",
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Description: "logo",
Group: model.PUBLIC,
},
{
Key: "favicon",
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Description: "favicon",
Group: model.PUBLIC,
},
{
Key: "icon color",
Value: "teal.300",
Description: "icon's color",
Group: model.PUBLIC,
},
{
Key: "text types",
Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp",
Description: "text type extensions",
},
{
Key: "readme file",
Value: "hide",
Description: "hide readme file? (show/hide)",
},
{
Key: "music cover",
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Description: "music cover image",
Group: model.PUBLIC,
},
{
Key: "site beian",
Description: "chinese beian info",
Group: model.PUBLIC,
},
{
Key: "home readme url",
Description: "when have multiple, the readme file to show",
Group: model.PUBLIC,
},
}
for _, v := range settings {
_, err := model.GetSettingByKey(v.Key)
if err == gorm.ErrRecordNotFound {
err = model.SaveSetting(v)
if err != nil {
log.Fatalf("failed write setting: %s", err.Error())
}
}
}
textTypes, err := model.GetSettingByKey("text types")
if err == nil {
conf.TextTypes = strings.Split(textTypes.Value, ",")
}
}
+169
View File
@@ -0,0 +1,169 @@
package bootstrap
import (
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/model"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
)
func InitSettings() {
log.Infof("init settings...")
version := model.SettingItem{
Key: "version",
Value: conf.GitTag,
Description: "version",
Type: "string",
Group: model.CONST,
}
_ = model.SaveSetting(version)
settings := []model.SettingItem{
{
Key: "title",
Value: "Alist",
Description: "title",
Type: "string",
Group: model.PUBLIC,
},
{
Key: "password",
Value: "alist",
Description: "password",
Type: "string",
Group: model.PRIVATE,
},
{
Key: "logo",
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Description: "logo",
Type: "string",
Group: model.PUBLIC,
},
{
Key: "favicon",
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Description: "favicon",
Type: "string",
Group: model.PUBLIC,
},
{
Key: "icon color",
Value: "teal.300",
Description: "icon's color",
Type: "string",
Group: model.PUBLIC,
},
{
Key: "text types",
Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp,tsx",
Type: "string",
Description: "text type extensions",
},
{
Key: "hide readme file",
Value: "true",
Type: "bool",
Description: "hide readme file? ",
},
{
Key: "music cover",
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Description: "music cover image",
Type: "string",
Group: model.PUBLIC,
},
{
Key: "site beian",
Description: "chinese beian info",
Type: "string",
Group: model.PUBLIC,
},
{
Key: "home readme url",
Description: "when have multiple, the readme file to show",
Type: "string",
Group: model.PUBLIC,
},
{
Key: "markdown theme",
Value: "vuepress",
Description: "default | github | vuepress",
Group: model.PUBLIC,
Type: "select",
Values: "default,github,vuepress",
},
{
Key: "autoplay video",
Value: "false",
Type: "bool",
Group: model.PUBLIC,
},
{
Key: "autoplay audio",
Value: "false",
Type: "bool",
Group: model.PUBLIC,
},
{
Key: "check parent folder",
Value: "false",
Type: "bool",
Description: "check parent folder password",
Group: model.PRIVATE,
},
{
Key: "customize style",
Value: "",
Type: "text",
Description: "customize style, don't need add <style></style>",
Group: model.PRIVATE,
},
{
Key: "customize script",
Value: "",
Type: "text",
Description: "customize script, don't need add <script></script>",
Group: model.PRIVATE,
},
{
Key: "animation",
Value: "true",
Type: "bool",
Description: "when there are a lot of files, the animation will freeze when opening",
Group: model.PUBLIC,
},
{
Key: "check down link",
Value: "false",
Type: "bool",
Description: "check down link password, your link will be 'https://alist.com/d/filename?pw=xxx'",
Group: model.PUBLIC,
},
{
Key: "WebDAV username",
Value: "alist",
Description: "WebDAV username",
Type: "string",
Group: model.PRIVATE,
},
{
Key: "WebDAV password",
Value: "alist",
Description: "WebDAV password",
Type: "string",
Group: model.PRIVATE,
},
}
for _, v := range settings {
_, err := model.GetSettingByKey(v.Key)
if err == gorm.ErrRecordNotFound {
err = model.SaveSetting(v)
if err != nil {
log.Fatalf("failed write setting: %s", err.Error())
}
}
}
model.LoadSettings()
}
+60 -7
View File
@@ -1,16 +1,56 @@
#!/bin/bash
if [ "$1" == "web" ]; then
git clone https://github.com/Xhofe/alist-web.git
cd alist-web || exit
yarn
yarn build
mv dist/* ../public
cd ..
exit 0
fi
go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,https://goproxy.io,direct
if [ "$1" == "docker" ]; then
appName="alist"
builtAt="$(date +'%F %T %z')"
goVersion=$(go version | sed 's/go version //')
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1)
gitTag=$(git describe --long --tags --dirty --always)
ldflags="\
-w -s \
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
"
go build -o ./bin/alist -ldflags="$ldflags" alist.go
exit 0
fi
cd alist-web || exit
webCommit=$(git log --pretty=format:"%h" -1)
echo "web commit id: $webCommit"
yarn
if [ "$1" == "release" ]; then
yarn build --base="https://cdn.jsdelivr.net/gh/Xhofe/alist-web@cdn/v2/$webCommit"
mv dist/assets ..
else
yarn build
fi
cd ..
cd alist
appName="alist"
builtAt="$(date +'%F %T %z')"
goVersion=$(go version | sed 's/go version //')
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1)
gitTag=$(git describe --long --tags --dirty --always)
if [ "$1" == "release" ]; then
gitTag=$(git describe --abbrev=0 --tags)
else
gitTag=$(git describe --abbrev=0 --tags)-next
fi
echo "build version: $gitTag"
ldflags="\
-w -s \
@@ -26,14 +66,14 @@ cp -R ../alist-web/dist/* public
if [ "$1" == "release" ]; then
xgo -out alist -ldflags="$ldflags" .
else
xgo -targets=linux/amd64,windows/amd64,darwin/amd64 -out alist -ldflags="$ldflags" .
xgo -targets=linux/amd64,windows/amd64 -out alist -ldflags="$ldflags" .
fi
mkdir "build"
mv alist-* build
cd build || exit
upx -9 ./*
find . -type f -print0 | xargs -0 md5sum > md5.txt
cat md5.txt
# compress file (release)
if [ "$1" == "release" ]; then
mkdir compress
@@ -50,4 +90,17 @@ if [ "$1" == "release" ]; then
do
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
done
fi
cd ../..
if [ "$1" == "release" ]; then
cd alist-web
git checkout cdn
mkdir "v2/$webCommit"
mv ../assets/ v2/$webCommit
git add .
git config --local user.email "i@nn.ci"
git config --local user.name "Xhofe"
git commit --allow-empty -m "upload $webCommit assets files" -a
cd ..
fi
+4 -5
View File
@@ -14,6 +14,9 @@ type Config struct {
Address string `json:"address"`
Port int `json:"port"`
Database Database `json:"database"`
Https bool `json:"https"`
CertFile string `json:"cert_file"`
KeyFile string `json:"key_file"`
}
func DefaultConfig() *Config {
@@ -22,13 +25,9 @@ func DefaultConfig() *Config {
Port: 5244,
Database: Database{
Type: "sqlite3",
User: "",
Password: "",
Host: "",
Port: 0,
Name: "",
TablePrefix: "x_",
DBFile: "data.db",
DBFile: "data/data.db",
},
}
}
+16 -1
View File
@@ -20,6 +20,7 @@ var (
Conf *Config
Debug bool
Version bool
Password bool
DB *gorm.DB
Cache *cache.Cache
@@ -31,6 +32,20 @@ var (
TextTypes = []string{"txt", "go", "md"}
OfficeTypes = []string{"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"}
VideoTypes = []string{"mp4", "mkv", "avi", "mov", "rmvb"}
AudioTypes = []string{"mp3", "flac", "ogg"}
AudioTypes = []string{"mp3", "flac", "ogg", "m4a"}
ImageTypes = []string{"jpg", "tiff", "jpeg", "png", "gif", "bmp", "svg"}
)
// settings
var (
RawIndexHtml string
IndexHtml string
CheckParent bool
//CustomizeStyle string
//CustomizeScript string
//Favicon string
CheckDown bool
DavUsername string
DavPassword string
)
+148
View File
@@ -0,0 +1,148 @@
package drivers
import (
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2"
"path/filepath"
"strconv"
"time"
)
var pan123Client = resty.New()
type Pan123TokenResp struct {
Code int `json:"code"`
Data struct {
Token string `json:"token"`
} `json:"data"`
Message string `json:"message"`
}
type Pan123File struct {
FileName string `json:"FileName"`
Size int64 `json:"Size"`
UpdateAt *time.Time `json:"UpdateAt"`
FileId int64 `json:"FileId"`
Type int `json:"Type"`
Etag string `json:"Etag"`
S3KeyFlag string `json:"S3KeyFlag"`
}
type Pan123Files struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
InfoList []Pan123File `json:"InfoList"`
Next string `json:"Next"`
} `json:"data"`
}
type Pan123DownResp struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
DownloadUrl string `json:"DownloadUrl"`
} `json:"data"`
}
func (driver Pan123) Login(account *model.Account) error {
var resp Pan123TokenResp
_, err := pan123Client.R().
SetResult(&resp).
SetBody(Json{
"passport": account.Username,
"password": account.Password,
}).Post("https://www.123pan.com/api/user/sign_in")
if err != nil {
return err
}
if resp.Code != 200 {
err = fmt.Errorf(resp.Message)
account.Status = resp.Message
} else {
account.Status = "work"
account.AccessToken = resp.Data.Token
}
_ = model.SaveAccount(account)
return err
}
func (driver Pan123) FormatFile(file *Pan123File) *model.File {
f := &model.File{
Id: strconv.FormatInt(file.FileId, 10),
Name: file.FileName,
Size: file.Size,
Driver: driver.Config().Name,
UpdatedAt: file.UpdateAt,
}
if file.Type == 1 {
f.Type = conf.FOLDER
} else {
f.Type = utils.GetFileType(filepath.Ext(file.FileName))
}
return f
}
func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]Pan123File, error) {
next := "0"
res := make([]Pan123File, 0)
for next != "-1" {
var resp Pan123Files
_, err := pan123Client.R().SetResult(&resp).
SetHeader("authorization", "Bearer "+account.AccessToken).
SetQueryParams(map[string]string{
"driveId": "0",
"limit": "100",
"next": next,
"orderBy": account.OrderBy,
"orderDirection": account.OrderDirection,
"parentFileId": parentId,
"trashed": "false",
}).Get("https://www.123pan.com/api/file/list")
if err != nil {
return nil, err
}
if resp.Code != 0 {
if resp.Code == 401 {
err := driver.Login(account)
if err != nil {
return nil, err
}
return driver.GetFiles(parentId, account)
}
return nil, fmt.Errorf(resp.Message)
}
next = resp.Data.Next
res = append(res, resp.Data.InfoList...)
}
return res, nil
}
func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File, error) {
dir, name := filepath.Split(path)
dir = utils.ParsePath(dir)
_, err := driver.Files(dir, account)
if err != nil {
return nil, err
}
parentFiles_, _ := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, dir))
parentFiles, _ := parentFiles_.([]Pan123File)
for _, file := range parentFiles {
if file.FileName == name {
if file.Type != conf.FOLDER {
return &file, err
} else {
return nil, NotFile
}
}
}
return nil, PathNotFound
}
func init() {
RegisterDriver(&Pan123{})
pan123Client.SetRetryCount(3)
}
+192
View File
@@ -0,0 +1,192 @@
package drivers
import (
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
url "net/url"
"path/filepath"
)
type Pan123 struct {}
func (driver Pan123) Config() DriverConfig {
return DriverConfig{
Name: "123Pan",
OnlyProxy: false,
}
}
func (driver Pan123) Items() []Item {
return []Item{
{
Name: "username",
Label: "username",
Type: "string",
Required: true,
Description: "account username/phone number",
},
{
Name: "password",
Label: "password",
Type: "string",
Required: true,
Description: "account password",
},
{
Name: "root_folder",
Label: "root folder file_id",
Type: "string",
Required: false,
},
{
Name: "order_by",
Label: "order_by",
Type: "select",
Values: "name,fileId,updateAt,createAt",
Required: true,
},
{
Name: "order_direction",
Label: "order_direction",
Type: "select",
Values: "asc,desc",
Required: true,
},
}
}
func (driver Pan123) Save(account *model.Account, old *model.Account) error {
if account.RootFolder == "" {
account.RootFolder = "0"
}
err := driver.Login(account)
return err
}
func (driver Pan123) File(path string, account *model.Account) (*model.File, error) {
path = utils.ParsePath(path)
if path == "/" {
return &model.File{
Id: account.RootFolder,
Name: account.Name,
Size: 0,
Type: conf.FOLDER,
Driver: driver.Config().Name,
UpdatedAt: account.UpdatedAt,
}, nil
}
dir, name := filepath.Split(path)
files, err := driver.Files(dir, account)
if err != nil {
return nil, err
}
for _, file := range files {
if file.Name == name {
return &file, nil
}
}
return nil, PathNotFound
}
func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) {
path = utils.ParsePath(path)
var rawFiles []Pan123File
cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path))
if err == nil {
rawFiles, _ = cache.([]Pan123File)
} else {
file, err := driver.File(path, account)
if err != nil {
return nil, err
}
rawFiles, err = driver.GetFiles(file.Id, account)
if err != nil {
return nil, err
}
if len(rawFiles) > 0 {
_ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), rawFiles, nil)
}
}
files := make([]model.File, 0)
for _, file := range rawFiles {
files = append(files, *driver.FormatFile(&file))
}
return files, nil
}
func (driver Pan123) Link(path string, account *model.Account) (string, error) {
file, err := driver.GetFile(utils.ParsePath(path), account)
if err != nil {
return "", err
}
var resp Pan123DownResp
_, err = pan123Client.R().SetResult(&resp).SetHeader("authorization", "Bearer "+account.AccessToken).
SetBody(Json{
"driveId": 0,
"etag": file.Etag,
"fileId": file.FileId,
"fileName": file.FileName,
"s3keyFlag": file.S3KeyFlag,
"size": file.Size,
"type": file.Type,
}).Post("https://www.123pan.com/api/file/download_info")
if err != nil {
return "", err
}
if resp.Code != 0 {
if resp.Code == 401 {
err := driver.Login(account)
if err != nil {
return "", err
}
return driver.Link(path, account)
}
return "", fmt.Errorf(resp.Message)
}
u,err := url.Parse(resp.Data.DownloadUrl)
if err != nil {
return "", err
}
u_ := fmt.Sprintf("https://%s%s",u.Host,u.Path)
res, err := NoRedirectClient.R().SetQueryParamsFromValues(u.Query()).Get(u_)
if err != nil {
return "", err
}
log.Debug(res.String())
if res.StatusCode() == 302 {
return res.Header().Get("location"), nil
}
return resp.Data.DownloadUrl, nil
}
func (driver Pan123) Path(path string, account *model.Account) (*model.File, []model.File, error) {
path = utils.ParsePath(path)
log.Debugf("pan123 path: %s", path)
file, err := driver.File(path, account)
if err != nil {
return nil, nil, err
}
if file.Type != conf.FOLDER {
file.Url, _ = driver.Link(path, account)
return file, nil, nil
}
files, err := driver.Files(path, account)
if err != nil {
return nil, nil, err
}
return nil, files, nil
}
func (driver Pan123) Proxy(c *gin.Context, account *model.Account) {
c.Request.Header.Del("origin")
}
func (driver Pan123) Preview(path string, account *model.Account) (interface{}, error) {
return nil, NotSupport
}
var _ Driver = (*Pan123)(nil)
+317
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff

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