Compare commits

...

24 Commits

Author SHA1 Message Date
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 🐛 file name contains + 2021-11-07 23:05:50 +08:00
9ed5b6e581 🐛 file name contains + 2021-11-07 22:12:52 +08:00
db7bff2d61 🐛 fix: #151 2021-11-07 14:04:54 +08:00
7970e737f0 add markdown theme setting 2021-11-06 17:33:00 +08:00
d4523d52ee 🐛 delete timed task 2021-11-06 17:25:07 +08:00
ac8476702c 🐛 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 🐛 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
13 changed files with 226 additions and 92 deletions

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
.github/workflows/docker.yml vendored Normal file
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/ppc64le,linux/s390x

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

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
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"
WORKDIR /opt/alist/
COPY --from=builder /app/bin/alist ./
EXPOSE 5244
CMD [ "./alist" ]

View File

@ -171,6 +171,12 @@ func initSettings() {
Description: "when have multiple, the readme file to show",
Group: model.PUBLIC,
},
{
Key: "markdown theme",
Value: "vuepress",
Description: "default | github | vuepress",
Group: model.PUBLIC,
},
}
for _, v := range settings {
_, err := model.GetSettingByKey(v.Key)

View File

@ -1,17 +1,57 @@
#!/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)
if [ "$1" == "release" ]; then
gitTag=$(git describe --abbrev=0 --tags)
else
gitTag=$(git describe --abbrev=0 --tags)-next
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)
echo "build version: $gitTag"
ldflags="\
-w -s \
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
@ -33,7 +73,7 @@ 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
@ -51,3 +91,16 @@ if [ "$1" == "release" ]; then
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

View File

@ -221,13 +221,16 @@ func (a AliDrive) Path(path string, account *model.Account) (*model.File, []*mod
return a.FormatFile(&file), nil, nil
} else {
files, _ := cache.([]AliFile)
if len(files) != 0 {
res := make([]*model.File, 0)
for _, file = range files {
res = append(res, a.FormatFile(&file))
}
return nil, res, nil
}
} else {
}
}
// no cache or len(files) == 0
fileId := account.RootFolder
if path != "/" {
dir, name := filepath.Split(path)
@ -270,7 +273,6 @@ func (a AliDrive) Path(path string, account *model.Account) (*model.File, []*mod
}
return nil, res, nil
}
}
func (a AliDrive) Link(path string, account *model.Account) (string, error) {
file, err := a.GetFile(utils.ParsePath(path), account)
@ -316,10 +318,12 @@ func (a AliDrive) RefreshToken(account *model.Account) error {
SetError(&e).
Post(url)
if err != nil {
account.Status = err.Error()
return err
}
log.Debugf("%+v,%+v", resp, e)
if e.Code != "" {
account.Status = e.Message
return fmt.Errorf("failed to refresh token: %s", e.Message)
}
account.RefreshToken, account.AccessToken = resp.RefreshToken, resp.AccessToken
@ -354,9 +358,6 @@ func (a AliDrive) Save(account *model.Account, old *model.Account) error {
return
}
err = a.RefreshToken(&newAccount)
if err != nil {
newAccount.Status = err.Error()
}
_ = model.SaveAccount(newAccount)
})
if err != nil {

View File

@ -146,9 +146,11 @@ func (o Onedrive) RefreshToken(account *model.Account) error {
"refresh_token": account.RefreshToken,
}).Post(url)
if err != nil {
account.Status = err.Error()
return err
}
if e.Error != "" {
account.Status = e.ErrorDescription
return fmt.Errorf("%s", e.ErrorDescription)
}
account.RefreshToken, account.AccessToken = resp.RefreshToken, resp.AccessToken
@ -280,9 +282,6 @@ func (o Onedrive) Save(account *model.Account, old *model.Account) error {
return
}
err = o.RefreshToken(&newAccount)
if err != nil {
newAccount.Status = err.Error()
}
_ = model.SaveAccount(newAccount)
})
if err != nil {

View File

@ -1,7 +1,9 @@
package model
import (
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/robfig/cron/v3"
"time"
)
@ -44,9 +46,11 @@ func SaveAccount(account Account) error {
}
func DeleteAccount(name string) error {
account := Account{
Name: name,
account, ok := GetAccount(name)
if !ok {
return fmt.Errorf("no [%s] account", name)
}
conf.Cron.Remove(cron.EntryID(account.CronId))
if err := conf.DB.Delete(&account).Error; err != nil {
return err
}

View File

@ -44,7 +44,7 @@ func GetSettings() (*[]SettingItem, error) {
func GetSettingByKey(key string) (*SettingItem, error) {
var items SettingItem
if err := conf.DB.Where("key = ?", key).First(&items).Error; err != nil {
if err := conf.DB.Where("`key` = ?", key).First(&items).Error; err != nil {
return nil, err
}
return &items, nil

View File

@ -12,7 +12,7 @@ import (
)
func Down(ctx *fiber.Ctx) error {
rawPath, err:= url.QueryUnescape(ctx.Params("*"))
rawPath, err := url.PathUnescape(ctx.Params("*"))
if err != nil {
return ErrorResp(ctx, err, 500)
}
@ -34,7 +34,7 @@ func Down(ctx *fiber.Ctx) error {
}
func Proxy(ctx *fiber.Ctx) error {
rawPath, err:= url.QueryUnescape(ctx.Params("*"))
rawPath, err := url.PathUnescape(ctx.Params("*"))
if err != nil {
return ErrorResp(ctx, err, 500)
}
@ -55,6 +55,20 @@ func Proxy(ctx *fiber.Ctx) error {
return ctx.SendFile(link)
} else {
driver.Proxy(ctx)
//ctx.Response().ImmediateHeaderFlush = true
//var ProxyNetHttp = fasthttpadaptor.NewFastHTTPHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// target, _ := url.Parse(link)
// protocol := "https://"
// if strings.HasPrefix(link, "http://") {
// protocol = "http://"
// }
// targetHost, _ := url.Parse(fmt.Sprintf("%s%s", protocol, target.Host))
// proxy := httputil.NewSingleHostReverseProxy(targetHost)
// r.URL = target
// r.Host = target.Host
// proxy.ServeHTTP(w, r)
//})
//ProxyNetHttp(ctx.Context())
if err := proxy.Do(ctx, link); err != nil {
log.Errorf("proxy error: %s", err)
return ErrorResp(ctx,err,500)

View File

@ -32,7 +32,7 @@ func SaveMeta(ctx *fiber.Ctx) error {
func DeleteMeta(ctx *fiber.Ctx) error {
path := ctx.Query("path")
path = utils.ParsePath(path)
//path = utils.ParsePath(path)
if err := model.DeleteMeta(path); err != nil {
return ErrorResp(ctx, err, 500)
}