Skip to content

Commit

Permalink
Merge branch 'main' into feat/driver-github-api
Browse files Browse the repository at this point in the history
  • Loading branch information
KirCute committed Dec 30, 2024
2 parents d07a7b9 + 7fd4ac7 commit 2e0227a
Show file tree
Hide file tree
Showing 25 changed files with 384 additions and 143 deletions.
116 changes: 60 additions & 56 deletions .github/workflows/release_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ on:
tags:
- 'v*'

env:
IMAGE_REGISTRY: 'xhofe/alist'
REGISTRY_USERNAME: 'xhofe'
REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
ARTIFACT_NAME: 'binaries_docker_release'
RELEASE_PLATFORMS: 'linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x,linux/ppc64le,linux/riscv64'

jobs:
release_docker:
name: Release Docker
build_binary:
name: Build Binaries for Docker Release
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -31,11 +38,45 @@ jobs:
- name: Build go binary
run: bash build.sh release docker-multiplatform

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
images: xhofe/alist
name: ${{ env.ARTIFACT_NAME }}
overwrite: true
path: |
build/
!build/*.tgz
!build/musl-libs/**
release_docker:
needs: build_binary
name: Release Docker image
runs-on: ubuntu-latest
strategy:
matrix:
image: ["latest", "ffmpeg", "aria2", "aio"]
include:
- image: "latest"
build_arg: ""
tag_favor: ""
- image: "ffmpeg"
build_arg: INSTALL_FFMPEG=true
tag_favor: "suffix=-ffmpeg,onlatest=true"
- image: "aria2"
build_arg: INSTALL_ARIA2=true
tag_favor: "suffix=-aria2,onlatest=true"
- image: "aio"
build_arg: |
INSTALL_FFMPEG=true
INSTALL_ARIA2=true
tag_favor: "suffix=-aio,onlatest=true"
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: 'build/'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -46,63 +87,26 @@ jobs:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: xhofe
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_PASSWORD }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.ci
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,linux/ppc64le,linux/riscv64

- name: Docker meta with ffmpeg
id: meta-ffmpeg
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: xhofe/alist
images: ${{ env.IMAGE_REGISTRY }}
flavor: |
latest=true
suffix=-ffmpeg,onlatest=true
- name: Build and push with ffmpeg
id: docker_build_ffmpeg
${{ matrix.tag_favor }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.ci
push: true
tags: ${{ steps.meta-ffmpeg.outputs.tags }}
labels: ${{ steps.meta-ffmpeg.outputs.labels }}
build-args: INSTALL_FFMPEG=true
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x,linux/ppc64le,linux/riscv64

release_docker_with_aria2:
needs: release_docker
name: Release docker with aria2
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
repository: alist-org/with_aria2
ref: main
persist-credentials: false
fetch-depth: 0

- name: Add tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "IlaBot"
git tag -a ${{ github.ref_name }} -m "release ${{ github.ref_name }}"
- name: Push tags
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.MY_TOKEN }}
branch: main
repository: alist-org/with_aria2
build-args: ${{ matrix.build_arg }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ env.RELEASE_PLATFORMS }}
17 changes: 15 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN bash build.sh release docker
FROM alpine:edge

ARG INSTALL_FFMPEG=false
ARG INSTALL_ARIA2=false
LABEL MAINTAINER="[email protected]"

WORKDIR /opt/alist/
Expand All @@ -18,13 +19,25 @@ RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache bash ca-certificates su-exec tzdata; \
[ "$INSTALL_FFMPEG" = "true" ] && apk add --no-cache ffmpeg; \
[ "$INSTALL_ARIA2" = "true" ] && apk add --no-cache curl aria2 && \
mkdir -p /opt/aria2/.aria2 && \
wget https://github.com/P3TERX/aria2.conf/archive/refs/heads/master.tar.gz -O /tmp/aria-conf.tar.gz && \
tar -zxvf /tmp/aria-conf.tar.gz -C /opt/aria2/.aria2 --strip-components=1 && rm -f /tmp/aria-conf.tar.gz && \
sed -i 's|rpc-secret|#rpc-secret|g' /opt/aria2/.aria2/aria2.conf && \
sed -i 's|/root/.aria2|/opt/aria2/.aria2|g' /opt/aria2/.aria2/aria2.conf && \
sed -i 's|/root/.aria2|/opt/aria2/.aria2|g' /opt/aria2/.aria2/script.conf && \
sed -i 's|/root|/opt/aria2|g' /opt/aria2/.aria2/aria2.conf && \
sed -i 's|/root|/opt/aria2|g' /opt/aria2/.aria2/script.conf && \
touch /opt/aria2/.aria2/aria2.session && \
/opt/aria2/.aria2/tracker.sh ; \
rm -rf /var/cache/apk/*

COPY --from=builder /app/bin/alist ./
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh && /entrypoint.sh version
RUN chmod +x /opt/alist/alist && \
chmod +x /entrypoint.sh && /entrypoint.sh version

ENV PUID=0 PGID=0 UMASK=022
ENV PUID=0 PGID=0 UMASK=022 RUN_ARIA2=${INSTALL_ARIA2}
VOLUME /opt/alist/data/
EXPOSE 5244 5245
CMD [ "/entrypoint.sh" ]
17 changes: 15 additions & 2 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM alpine:edge

ARG TARGETPLATFORM
ARG INSTALL_FFMPEG=false
ARG INSTALL_ARIA2=false
LABEL MAINTAINER="[email protected]"

WORKDIR /opt/alist/
Expand All @@ -10,13 +11,25 @@ RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache bash ca-certificates su-exec tzdata; \
[ "$INSTALL_FFMPEG" = "true" ] && apk add --no-cache ffmpeg; \
[ "$INSTALL_ARIA2" = "true" ] && apk add --no-cache curl aria2 && \
mkdir -p /opt/aria2/.aria2 && \
wget https://github.com/P3TERX/aria2.conf/archive/refs/heads/master.tar.gz -O /tmp/aria-conf.tar.gz && \
tar -zxvf /tmp/aria-conf.tar.gz -C /opt/aria2/.aria2 --strip-components=1 && rm -f /tmp/aria-conf.tar.gz && \
sed -i 's|rpc-secret|#rpc-secret|g' /opt/aria2/.aria2/aria2.conf && \
sed -i 's|/root/.aria2|/opt/aria2/.aria2|g' /opt/aria2/.aria2/aria2.conf && \
sed -i 's|/root/.aria2|/opt/aria2/.aria2|g' /opt/aria2/.aria2/script.conf && \
sed -i 's|/root|/opt/aria2|g' /opt/aria2/.aria2/aria2.conf && \
sed -i 's|/root|/opt/aria2|g' /opt/aria2/.aria2/script.conf && \
touch /opt/aria2/.aria2/aria2.session && \
/opt/aria2/.aria2/tracker.sh ; \
rm -rf /var/cache/apk/*

COPY /build/${TARGETPLATFORM}/alist ./
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh && /entrypoint.sh version
RUN chmod +x /opt/alist/alist && \
chmod +x /entrypoint.sh && /entrypoint.sh version

ENV PUID=0 PGID=0 UMASK=022
ENV PUID=0 PGID=0 UMASK=022 RUN_ARIA2=${INSTALL_ARIA2}
VOLUME /opt/alist/data/
EXPOSE 5244 5245
CMD [ "/entrypoint.sh" ]
2 changes: 1 addition & 1 deletion cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
func Init() {
bootstrap.InitConfig()
bootstrap.Log()
bootstrap.InitHostKey()
bootstrap.InitDB()
data.InitData()
bootstrap.InitIndex()
bootstrap.InitUpgradePatch()
}

func Release() {
Expand Down
2 changes: 1 addition & 1 deletion drivers/139/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (d *Yun139) familyGetFiles(catalogID string) ([]model.Obj, error) {
}
files = append(files, &f)
}
if 100*pageNum > resp.Data.TotalCount {
if resp.Data.TotalCount == 0 {
break
}
pageNum++
Expand Down
44 changes: 31 additions & 13 deletions drivers/lenovonas_share/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package LenovoNasShare
import (
"context"
"net/http"
"time"

"github.com/go-resty/resty/v2"

Expand All @@ -15,7 +16,8 @@ import (
type LenovoNasShare struct {
model.Storage
Addition
stoken string
stoken string
expireAt int64
}

func (d *LenovoNasShare) Config() driver.Config {
Expand All @@ -27,20 +29,9 @@ func (d *LenovoNasShare) GetAddition() driver.Additional {
}

func (d *LenovoNasShare) Init(ctx context.Context) error {
if d.Host == "" {
d.Host = "https://siot-share.lenovo.com.cn"
}
query := map[string]string{
"code": d.ShareId,
"password": d.SharePwd,
}
resp, err := d.request(d.Host+"/oneproxy/api/share/v1/access", http.MethodGet, func(req *resty.Request) {
req.SetQueryParams(query)
}, nil)
if err != nil {
if err := d.getStoken(); err != nil {
return err
}
d.stoken = utils.Json.Get(resp, "data", "stoken").ToString()
return nil
}

Expand All @@ -49,6 +40,7 @@ func (d *LenovoNasShare) Drop(ctx context.Context) error {
}

func (d *LenovoNasShare) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
d.checkStoken() // 检查stoken是否过期
files := make([]File, 0)

var resp Files
Expand All @@ -71,7 +63,33 @@ func (d *LenovoNasShare) List(ctx context.Context, dir model.Obj, args model.Lis
})
}

func (d *LenovoNasShare) checkStoken() { // 检查stoken是否过期
if d.expireAt < time.Now().Unix() {
d.getStoken()
}
}

func (d *LenovoNasShare) getStoken() error { // 获取stoken
if d.Host == "" {
d.Host = "https://siot-share.lenovo.com.cn"
}
query := map[string]string{
"code": d.ShareId,
"password": d.SharePwd,
}
resp, err := d.request(d.Host+"/oneproxy/api/share/v1/access", http.MethodGet, func(req *resty.Request) {
req.SetQueryParams(query)
}, nil)
if err != nil {
return err
}
d.stoken = utils.Json.Get(resp, "data", "stoken").ToString()
d.expireAt = utils.Json.Get(resp, "data", "expires_in").ToInt64() + time.Now().Unix() - 60
return nil
}

func (d *LenovoNasShare) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
d.checkStoken() // 检查stoken是否过期
query := map[string]string{
"code": d.ShareId,
"stoken": d.stoken,
Expand Down
12 changes: 10 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#!/bin/bash

chown -R ${PUID}:${PGID} /opt/alist/

umask ${UMASK}

if [ "$1" = "version" ]; then
./alist version
else
if [ "$RUN_ARIA2" = "true" ]; then
chown -R ${PUID}:${PGID} /opt/aria2/
exec su-exec ${PUID}:${PGID} nohup aria2c \
--enable-rpc \
--rpc-allow-origin-all \
--conf-path=/opt/aria2/.aria2/aria2.conf \
>/dev/null 2>&1 &
fi

chown -R ${PUID}:${PGID} /opt/alist/
exec su-exec ${PUID}:${PGID} ./alist server --no-prefix
fi
6 changes: 6 additions & 0 deletions internal/bootstrap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func InitConfig() {
log.Fatalf("failed to create config file: %+v", err)
}
conf.Conf = conf.DefaultConfig()
LastLaunchedVersion = conf.Version
conf.Conf.LastLaunchedVersion = conf.Version
if !utils.WriteJsonToFile(configPath, conf.Conf) {
log.Fatalf("failed to create default config file")
}
Expand All @@ -47,6 +49,10 @@ func InitConfig() {
if err != nil {
log.Fatalf("load config error: %+v", err)
}
LastLaunchedVersion = conf.Conf.LastLaunchedVersion
if conf.Version != "dev" || LastLaunchedVersion == "" {
conf.Conf.LastLaunchedVersion = conf.Version
}
// update config.json struct
confBody, err := utils.Json.MarshalIndent(conf.Conf, "", " ")
if err != nil {
Expand Down
Loading

0 comments on commit 2e0227a

Please sign in to comment.