From a5000c0621149f54e79e7ac3df2a7b8e15975f11 Mon Sep 17 00:00:00 2001 From: hiCasper Date: Wed, 20 May 2020 11:48:00 +0800 Subject: [PATCH 1/7] Modify: update actions (#398) --- .github/workflows/build.yml | 26 ++++++++++++++++++++++---- build.sh | 7 ++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index adb64286..7a42eae1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,8 +63,26 @@ jobs: chmod +x ./build.sh ./build.sh -r b - - name: Upload binary files - uses: actions/upload-artifact@v1 + - name: Upload binary files (windows_amd64) + uses: actions/upload-artifact@v2 with: - name: release - path: release/ + name: cloudreve_windows_amd64 + path: release/cloudreve*windows_amd64.* + + - name: Upload binary files (linux_amd64) + uses: actions/upload-artifact@v2 + with: + name: cloudreve_linux_amd64 + path: release/cloudreve*linux_amd64.* + + - name: Upload binary files (linux_arm) + uses: actions/upload-artifact@v2 + with: + name: cloudreve_linux_arm + path: release/cloudreve*linux_arm.* + + - name: Upload binary files (linux_arm64) + uses: actions/upload-artifact@v2 + with: + name: cloudreve_linux_arm64 + path: release/cloudreve*linux_arm64.* diff --git a/build.sh b/build.sh index 5ebd3da2..ea7e1010 100755 --- a/build.sh +++ b/build.sh @@ -55,7 +55,12 @@ _build() { export CC=$gcc export CGO_ENABLED=1 - out="release/cloudreve_${VERSION}_${os}_${arch}" + if [ -n "$VERSION" ]; then + out="release/cloudreve_${VERSION}_${os}_${arch}" + else + out="release/cloudreve_${COMMIT_SHA}_${os}_${arch}" + fi + go build -a -o "${out}" -ldflags " -X 'github.com/HFO4/cloudreve/pkg/conf.BackendVersion=$VERSION' -X 'github.com/HFO4/cloudreve/pkg/conf.LastCommit=$COMMIT_SHA'" if [ "$os" = "windows" ]; then From bfb5b34edcfdd6aadfcf927273af13aecaf438ed Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sat, 23 May 2020 13:17:48 +0800 Subject: [PATCH 2/7] Fix: concurrent logging lock / Feat: listen SSL (#287) --- bootstrap/app.go | 2 ++ main.go | 12 ++++++++++++ pkg/conf/conf.go | 7 +++++++ pkg/conf/defaults.go | 6 ++++++ pkg/util/logger.go | 6 ++++++ 5 files changed, 33 insertions(+) diff --git a/bootstrap/app.go b/bootstrap/app.go index 616c8026..ccb4fdcc 100644 --- a/bootstrap/app.go +++ b/bootstrap/app.go @@ -37,11 +37,13 @@ func CheckUpdate() { res, err := client.Request("GET", "https://api.github.com/repos/cloudreve/cloudreve/releases", nil).GetResponse() if err != nil { util.Log().Warning("更新检查失败, %s", err) + return } var list []GitHubRelease if err := json.Unmarshal([]byte(res), &list); err != nil { util.Log().Warning("更新检查失败, %s", err) + return } if len(list) > 0 { diff --git a/main.go b/main.go index a05bd5a4..d65ff07d 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,18 @@ func init() { func main() { api := routers.InitRouter() + + // 如果启用了SSL + if conf.SSLConfig.CertPath != "" { + go func() { + util.Log().Info("开始监听 %s", conf.SSLConfig.Listen) + if err := api.RunTLS(conf.SSLConfig.Listen, + conf.SSLConfig.CertPath, conf.SSLConfig.KeyPath); err != nil { + util.Log().Error("无法监听[%s],%s", conf.SSLConfig.Listen, err) + } + }() + } + util.Log().Info("开始监听 %s", conf.SystemConfig.Listen) if err := api.Run(conf.SystemConfig.Listen); err != nil { util.Log().Error("无法监听[%s],%s", conf.SystemConfig.Listen, err) diff --git a/pkg/conf/conf.go b/pkg/conf/conf.go index d28d0434..a19110b1 100644 --- a/pkg/conf/conf.go +++ b/pkg/conf/conf.go @@ -27,6 +27,12 @@ type system struct { HashIDSalt string } +type ssl struct { + CertPath string `validate:"omitempty,required"` + KeyPath string `validate:"omitempty,required"` + Listen string `validate:"required"` +} + // slave 作为slave存储端配置 type slave struct { Secret string `validate:"omitempty,gte=64"` @@ -113,6 +119,7 @@ func Init(path string) { sections := map[string]interface{}{ "Database": DatabaseConfig, "System": SystemConfig, + "SSL": SSLConfig, "Captcha": CaptchaConfig, "Redis": RedisConfig, "Thumbnail": ThumbConfig, diff --git a/pkg/conf/defaults.go b/pkg/conf/defaults.go index f4ff903f..406a2030 100644 --- a/pkg/conf/defaults.go +++ b/pkg/conf/defaults.go @@ -59,3 +59,9 @@ var SlaveConfig = &slave{ CallbackTimeout: 20, SignatureTTL: 60, } + +var SSLConfig = &ssl{ + Listen: ":443", + CertPath: "", + KeyPath: "", +} diff --git a/pkg/util/logger.go b/pkg/util/logger.go index 81e36528..107ec718 100644 --- a/pkg/util/logger.go +++ b/pkg/util/logger.go @@ -3,6 +3,7 @@ package util import ( "fmt" "github.com/fatih/color" + "sync" "time" ) @@ -23,6 +24,7 @@ var Level = LevelDebug // Logger 日志 type Logger struct { level int + mu sync.Mutex } // 日志颜色 @@ -49,6 +51,10 @@ func (ll *Logger) Println(prefix string, msg string) { // color.NoColor = false c := color.New() + + ll.mu.Lock() + defer ll.mu.Unlock() + _, _ = c.Printf( "%s%s %s %s\n", colors[prefix]("["+prefix+"]"), From ee0f8e964ddae189915f19905a864d6a1aa8a59a Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sat, 23 May 2020 13:57:02 +0800 Subject: [PATCH 3/7] Feat: eject internal static files --- assets | 2 +- bootstrap/static.go | 68 ++++++++++++++++++++++++++++++++++++++++++++- main.go | 12 +++++++- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/assets b/assets index b44dc051..c2b69970 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit b44dc0514520580fc284937400743123bbb2c6d4 +Subproject commit c2b69970cb2405307e5dceb45297bc7afa756092 diff --git a/bootstrap/static.go b/bootstrap/static.go index e22ebd0a..d3f89679 100644 --- a/bootstrap/static.go +++ b/bootstrap/static.go @@ -7,10 +7,14 @@ import ( _ "github.com/HFO4/cloudreve/statik" "github.com/gin-contrib/static" "github.com/rakyll/statik/fs" + "io" "io/ioutil" "net/http" + "path" ) +const StaticFolder = "statics" + type GinFS struct { FS http.FileSystem } @@ -42,7 +46,7 @@ func (b *GinFS) Exists(prefix string, filepath string) bool { func InitStatic() { var err error - if util.Exists(util.RelativePath("statics")) { + if util.Exists(util.RelativePath(StaticFolder)) { util.Log().Info("检测到 statics 目录存在,将使用此目录下的静态资源文件") StaticFS = static.LocalFile(util.RelativePath("statics"), false) @@ -89,3 +93,65 @@ func InitStatic() { } } + +// Eject 抽离内置静态资源 +func Eject() { + staticFS, err := fs.New() + if err != nil { + util.Log().Panic("无法初始化静态资源, %s", err) + } + + root, err := staticFS.Open("/") + if err != nil { + util.Log().Panic("根目录不存在, %s", err) + } + + var walk func(relPath string, object http.File) + walk = func(relPath string, object http.File) { + stat, err := object.Stat() + if err != nil { + util.Log().Error("无法获取[%s]的信息, %s, 跳过...", relPath, err) + return + } + + if !stat.IsDir() { + // 写入文件 + out, err := util.CreatNestedFile(util.RelativePath(StaticFolder + relPath)) + defer out.Close() + + if err != nil { + util.Log().Error("无法创建文件[%s], %s, 跳过...", relPath, err) + return + } + + util.Log().Info("导出 [%s]...", relPath) + if _, err := io.Copy(out, object); err != nil { + util.Log().Error("无法写入文件[%s], %s, 跳过...", relPath, err) + return + } + } else { + // 列出目录 + objects, err := object.Readdir(0) + if err != nil { + util.Log().Error("无法步入子目录[%s], %s, 跳过...", relPath, err) + return + } + + // 递归遍历子目录 + for _, newObject := range objects { + newPath := path.Join(relPath, newObject.Name()) + newRoot, err := staticFS.Open(newPath) + if err != nil { + util.Log().Error("无法打开对象[%s], %s, 跳过...", newPath, err) + continue + } + walk(newPath, newRoot) + } + + } + } + + util.Log().Info("开始导出内置静态资源...") + walk("/", root) + util.Log().Info("内置静态资源导出完成") +} diff --git a/main.go b/main.go index d65ff07d..de6bce01 100644 --- a/main.go +++ b/main.go @@ -8,15 +8,25 @@ import ( "github.com/HFO4/cloudreve/routers" ) -var confPath string +var ( + isEject bool + confPath string +) func init() { flag.StringVar(&confPath, "c", util.RelativePath("conf.ini"), "配置文件路径") + flag.BoolVar(&isEject, "eject", false, "导出内置静态资源") flag.Parse() bootstrap.Init(confPath) } func main() { + if isEject { + // 开始导出内置静态资源文件 + bootstrap.Eject() + return + } + api := routers.InitRouter() // 如果启用了SSL From aa3e8913abaf2788d680d8ce81739286f54983b8 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 24 May 2020 10:36:26 +0800 Subject: [PATCH 4/7] Feat: add ".zip" suffix if not specified while creating compressed file --- service/explorer/objects.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/service/explorer/objects.go b/service/explorer/objects.go index 4944551b..62751368 100644 --- a/service/explorer/objects.go +++ b/service/explorer/objects.go @@ -146,6 +146,11 @@ func (service *ItemCompressService) CreateCompressTask(c *gin.Context) serialize return serializer.Err(serializer.CodeGroupNotAllowed, "当前用户组无法进行此操作", nil) } + // 补齐压缩文件扩展名(如果没有) + if !strings.HasSuffix(service.Name, ".zip") { + service.Name += ".zip" + } + // 存放目录是否存在,是否重名 if exist, _ := fs.IsPathExist(service.Dst); !exist { return serializer.Err(serializer.CodeNotFound, "存放路径不存在", nil) From acc5d53bab5d04aac9c4a6ef96cf16b196ab3b37 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 24 May 2020 10:36:48 +0800 Subject: [PATCH 5/7] Update: submodules --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index c2b69970..bd1cb9cc 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit c2b69970cb2405307e5dceb45297bc7afa756092 +Subproject commit bd1cb9cc99ab11ca13180ba5934b802058b6b308 From e6073112684d53fbbbb1ed7127dd196caf20b633 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 24 May 2020 10:47:30 +0800 Subject: [PATCH 6/7] Update: version number for 3.1.0 --- assets | 2 +- pkg/conf/version.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/assets b/assets index bd1cb9cc..54f4e608 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit bd1cb9cc99ab11ca13180ba5934b802058b6b308 +Subproject commit 54f4e608bd4a91ef5ed81b2f8e5778f4bf8632c5 diff --git a/pkg/conf/version.go b/pkg/conf/version.go index 280ed728..f4b5bf8a 100644 --- a/pkg/conf/version.go +++ b/pkg/conf/version.go @@ -1,13 +1,13 @@ package conf // BackendVersion 当前后端版本号 -var BackendVersion = "3.0.0-beta1" +var BackendVersion = "3.1.0" // RequiredDBVersion 与当前版本匹配的数据库版本 -var RequiredDBVersion = "3.0.0-33-g5885661" +var RequiredDBVersion = "3.1.0" // RequiredStaticVersion 与当前版本匹配的静态资源版本 -var RequiredStaticVersion = "3.0.0" +var RequiredStaticVersion = "3.1.0" // IsPro 是否为Pro版本 var IsPro = "false" From 14f5982b477356dd48bdb2a96f40a8c5c6bcfb1b Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 24 May 2020 11:31:00 +0800 Subject: [PATCH 7/7] Modify: set node_js version to node_js in travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 13916689..8e6abe8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: go go: - 1.13.x +node_js: + - 12.16.3 git: depth: 1 install: