precompress embedded frontend. import mholt/archiver.

This commit is contained in:
Weidi Deng
2022-04-20 19:56:00 +08:00
parent d34cb3e5d3
commit 7a3d44451b
7 changed files with 60 additions and 11 deletions

22
main.go
View File

@ -1,13 +1,18 @@
package main
import (
"embed"
_ "embed"
"flag"
"io"
"io/fs"
"strings"
"github.com/cloudreve/Cloudreve/v3/bootstrap"
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
"github.com/cloudreve/Cloudreve/v3/pkg/util"
"github.com/cloudreve/Cloudreve/v3/routers"
"github.com/mholt/archiver/v4"
)
var (
@ -16,21 +21,28 @@ var (
scriptName string
)
//go:embed assets/build
var staticEmbed embed.FS
//go:embed assets.zip
var staticZip string
var staticFS fs.FS
func init() {
flag.StringVar(&confPath, "c", util.RelativePath("conf.ini"), "配置文件路径")
flag.BoolVar(&isEject, "eject", false, "导出内置静态资源")
flag.StringVar(&scriptName, "database-script", "", "运行内置数据库助手脚本")
flag.Parse()
bootstrap.Init(confPath, staticEmbed)
staticFS = archiver.ArchiveFS{
Stream: io.NewSectionReader(strings.NewReader(staticZip), 0, int64(len(staticZip))),
Format: archiver.Zip{},
}
bootstrap.Init(confPath, staticFS)
}
func main() {
if isEject {
// 开始导出内置静态资源文件
bootstrap.Eject(staticEmbed)
bootstrap.Eject(staticFS)
return
}