diff --git a/alist.go b/alist.go index e43f4b9d..9ad4601f 100644 --- a/alist.go +++ b/alist.go @@ -34,7 +34,8 @@ func Init() bool { 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\nWebVersion: %s\n", + conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.GitTag, conf.WebTag) return } if !Init() { diff --git a/build.sh b/build.sh index 5db501f8..a1b80f14 100644 --- a/build.sh +++ b/build.sh @@ -4,8 +4,9 @@ BUILD_WEB() { git clone https://github.com/alist-org/alist-web.git cd alist-web + sed -i -e "s/\/CDN_URL\//\//g" index.html yarn - yarn build + yarn build --base="/" mv dist .. cd .. rm -rf alist-web @@ -25,6 +26,7 @@ BUILD_DOCKER() { gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD) gitCommit=$(git log --pretty=format:"%h" -1) gitTag=$(git describe --long --tags --dirty --always) + webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') ldflags="\ -w -s \ -X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \ @@ -32,6 +34,7 @@ BUILD_DOCKER() { -X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \ -X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \ -X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \ +-X 'github.com/Xhofe/alist/conf.WebTag=$webTag' \ " go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter alist.go } @@ -44,6 +47,7 @@ BUILD() { gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD) gitCommit=$(git log --pretty=format:"%h" -1) gitTag=$(git describe --long --tags --dirty --always) + webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') echo "build version: $gitTag" ldflags="\ -w -s \ @@ -52,6 +56,7 @@ BUILD() { -X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \ -X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \ -X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \ +-X 'github.com/Xhofe/alist/conf.WebTag=$webTag' \ " if [ "$1" == "release" ]; then @@ -86,6 +91,7 @@ BUILD_MUSL() { gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD) gitCommit=$(git log --pretty=format:"%h" -1) gitTag=$(git describe --long --tags --dirty --always) + webTag=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') ldflags="\ -w -s \ -X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \ @@ -93,6 +99,7 @@ BUILD_MUSL() { -X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \ -X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \ -X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \ +-X 'github.com/Xhofe/alist/conf.WebTag=$webTag' \ " OS_ARCHES=(linux-musl-amd64 linux-musl-arm64 linux-musl-arm linux-musl-mips linux-musl-mips64 linux-musl-mips64le linux-musl-mipsle linux-musl-ppc64le linux-musl-s390x) CGO_ARGS=(x86_64-linux-musl-gcc aarch64-linux-musl-gcc arm-linux-musleabihf-gcc mips-linux-musl-gcc mips64-linux-musl-gcc mips64el-linux-musl-gcc mipsel-linux-musl-gcc powerpc64le-linux-musl-gcc s390x-linux-musl-gcc) diff --git a/conf/config.go b/conf/config.go index 6910937a..36e63766 100644 --- a/conf/config.go +++ b/conf/config.go @@ -37,7 +37,7 @@ func DefaultConfig() *Config { return &Config{ Address: "0.0.0.0", Port: 5244, - Assets: "jsdelivr", + Assets: "https://npm.elemecdn.com/alist-web@$version", TempDir: "data/temp", Database: Database{ Type: "sqlite3", diff --git a/conf/var.go b/conf/var.go index 56c43e86..2c564baa 100644 --- a/conf/var.go +++ b/conf/var.go @@ -14,6 +14,7 @@ var ( GitAuthor string GitCommit string GitTag string = "dev" + WebTag string ) var ( diff --git a/server/static.go b/server/static.go index 3e19564a..1cc2bfce 100644 --- a/server/static.go +++ b/server/static.go @@ -1,7 +1,6 @@ package server import ( - "fmt" "github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/public" "github.com/gin-gonic/gin" @@ -15,24 +14,18 @@ import ( func InitIndex() { var index fs.File var err error - //if conf.Conf.Local { - // index, err = public.Public.Open("local.html") - //} else { - // index, err = public.Public.Open("index.html") - //} - if conf.Conf.Assets == "" { + if !strings.Contains(conf.Conf.Assets, "/") { conf.Conf.Assets = conf.DefaultConfig().Assets } - index, err = public.Public.Open(fmt.Sprintf("%s.html", conf.Conf.Assets)) + index, err = public.Public.Open("index.html") if err != nil { - log.Error(err.Error()) - index, err = public.Public.Open("index.html") - if err != nil { - log.Fatal(err.Error()) - } + log.Fatal(err.Error()) } data, _ := ioutil.ReadAll(index) + cdnUrl := strings.ReplaceAll(conf.Conf.Assets, "$version", conf.WebTag) + cdnUrl = strings.TrimRight(cdnUrl, "/") conf.RawIndexHtml = string(data) + conf.RawIndexHtml = strings.ReplaceAll(conf.RawIndexHtml, "/CDN_URL", cdnUrl) } func Static(r *gin.Engine) {