Merge pull request #3 from cloudreve/master

合并
pull/521/head
Lones 5 years ago committed by GitHub
commit e206c59f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -63,8 +63,26 @@ jobs:
chmod +x ./build.sh chmod +x ./build.sh
./build.sh -r b ./build.sh -r b
- name: Upload binary files - name: Upload binary files (windows_amd64)
uses: actions/upload-artifact@v1 uses: actions/upload-artifact@v2
with: with:
name: release name: cloudreve_windows_amd64
path: release/ 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.*

@ -1,6 +1,8 @@
language: go language: go
go: go:
- 1.13.x - 1.13.x
node_js:
- 12.16.3
git: git:
depth: 1 depth: 1
install: install:

@ -1 +1 @@
Subproject commit b44dc0514520580fc284937400743123bbb2c6d4 Subproject commit 54f4e608bd4a91ef5ed81b2f8e5778f4bf8632c5

@ -37,11 +37,13 @@ func CheckUpdate() {
res, err := client.Request("GET", "https://api.github.com/repos/cloudreve/cloudreve/releases", nil).GetResponse() res, err := client.Request("GET", "https://api.github.com/repos/cloudreve/cloudreve/releases", nil).GetResponse()
if err != nil { if err != nil {
util.Log().Warning("更新检查失败, %s", err) util.Log().Warning("更新检查失败, %s", err)
return
} }
var list []GitHubRelease var list []GitHubRelease
if err := json.Unmarshal([]byte(res), &list); err != nil { if err := json.Unmarshal([]byte(res), &list); err != nil {
util.Log().Warning("更新检查失败, %s", err) util.Log().Warning("更新检查失败, %s", err)
return
} }
if len(list) > 0 { if len(list) > 0 {

@ -7,10 +7,14 @@ import (
_ "github.com/HFO4/cloudreve/statik" _ "github.com/HFO4/cloudreve/statik"
"github.com/gin-contrib/static" "github.com/gin-contrib/static"
"github.com/rakyll/statik/fs" "github.com/rakyll/statik/fs"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"path"
) )
const StaticFolder = "statics"
type GinFS struct { type GinFS struct {
FS http.FileSystem FS http.FileSystem
} }
@ -42,7 +46,7 @@ func (b *GinFS) Exists(prefix string, filepath string) bool {
func InitStatic() { func InitStatic() {
var err error var err error
if util.Exists(util.RelativePath("statics")) { if util.Exists(util.RelativePath(StaticFolder)) {
util.Log().Info("检测到 statics 目录存在,将使用此目录下的静态资源文件") util.Log().Info("检测到 statics 目录存在,将使用此目录下的静态资源文件")
StaticFS = static.LocalFile(util.RelativePath("statics"), false) 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("内置静态资源导出完成")
}

@ -55,7 +55,12 @@ _build() {
export CC=$gcc export CC=$gcc
export CGO_ENABLED=1 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'" 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 if [ "$os" = "windows" ]; then

@ -8,16 +8,38 @@ import (
"github.com/HFO4/cloudreve/routers" "github.com/HFO4/cloudreve/routers"
) )
var confPath string var (
isEject bool
confPath string
)
func init() { func init() {
flag.StringVar(&confPath, "c", util.RelativePath("conf.ini"), "配置文件路径") flag.StringVar(&confPath, "c", util.RelativePath("conf.ini"), "配置文件路径")
flag.BoolVar(&isEject, "eject", false, "导出内置静态资源")
flag.Parse() flag.Parse()
bootstrap.Init(confPath) bootstrap.Init(confPath)
} }
func main() { func main() {
if isEject {
// 开始导出内置静态资源文件
bootstrap.Eject()
return
}
api := routers.InitRouter() 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) util.Log().Info("开始监听 %s", conf.SystemConfig.Listen)
if err := api.Run(conf.SystemConfig.Listen); err != nil { if err := api.Run(conf.SystemConfig.Listen); err != nil {
util.Log().Error("无法监听[%s]%s", conf.SystemConfig.Listen, err) util.Log().Error("无法监听[%s]%s", conf.SystemConfig.Listen, err)

@ -27,6 +27,12 @@ type system struct {
HashIDSalt string HashIDSalt string
} }
type ssl struct {
CertPath string `validate:"omitempty,required"`
KeyPath string `validate:"omitempty,required"`
Listen string `validate:"required"`
}
// slave 作为slave存储端配置 // slave 作为slave存储端配置
type slave struct { type slave struct {
Secret string `validate:"omitempty,gte=64"` Secret string `validate:"omitempty,gte=64"`
@ -113,6 +119,7 @@ func Init(path string) {
sections := map[string]interface{}{ sections := map[string]interface{}{
"Database": DatabaseConfig, "Database": DatabaseConfig,
"System": SystemConfig, "System": SystemConfig,
"SSL": SSLConfig,
"Captcha": CaptchaConfig, "Captcha": CaptchaConfig,
"Redis": RedisConfig, "Redis": RedisConfig,
"Thumbnail": ThumbConfig, "Thumbnail": ThumbConfig,

@ -59,3 +59,9 @@ var SlaveConfig = &slave{
CallbackTimeout: 20, CallbackTimeout: 20,
SignatureTTL: 60, SignatureTTL: 60,
} }
var SSLConfig = &ssl{
Listen: ":443",
CertPath: "",
KeyPath: "",
}

@ -1,13 +1,13 @@
package conf package conf
// BackendVersion 当前后端版本号 // BackendVersion 当前后端版本号
var BackendVersion = "3.0.0-beta1" var BackendVersion = "3.1.0"
// RequiredDBVersion 与当前版本匹配的数据库版本 // RequiredDBVersion 与当前版本匹配的数据库版本
var RequiredDBVersion = "3.0.0-33-g5885661" var RequiredDBVersion = "3.1.0"
// RequiredStaticVersion 与当前版本匹配的静态资源版本 // RequiredStaticVersion 与当前版本匹配的静态资源版本
var RequiredStaticVersion = "3.0.0" var RequiredStaticVersion = "3.1.0"
// IsPro 是否为Pro版本 // IsPro 是否为Pro版本
var IsPro = "false" var IsPro = "false"

@ -3,6 +3,7 @@ package util
import ( import (
"fmt" "fmt"
"github.com/fatih/color" "github.com/fatih/color"
"sync"
"time" "time"
) )
@ -23,6 +24,7 @@ var Level = LevelDebug
// Logger 日志 // Logger 日志
type Logger struct { type Logger struct {
level int level int
mu sync.Mutex
} }
// 日志颜色 // 日志颜色
@ -49,6 +51,10 @@ func (ll *Logger) Println(prefix string, msg string) {
// color.NoColor = false // color.NoColor = false
c := color.New() c := color.New()
ll.mu.Lock()
defer ll.mu.Unlock()
_, _ = c.Printf( _, _ = c.Printf(
"%s%s %s %s\n", "%s%s %s %s\n",
colors[prefix]("["+prefix+"]"), colors[prefix]("["+prefix+"]"),

@ -146,6 +146,11 @@ func (service *ItemCompressService) CreateCompressTask(c *gin.Context) serialize
return serializer.Err(serializer.CodeGroupNotAllowed, "当前用户组无法进行此操作", nil) return serializer.Err(serializer.CodeGroupNotAllowed, "当前用户组无法进行此操作", nil)
} }
// 补齐压缩文件扩展名(如果没有)
if !strings.HasSuffix(service.Name, ".zip") {
service.Name += ".zip"
}
// 存放目录是否存在,是否重名 // 存放目录是否存在,是否重名
if exist, _ := fs.IsPathExist(service.Dst); !exist { if exist, _ := fs.IsPathExist(service.Dst); !exist {
return serializer.Err(serializer.CodeNotFound, "存放路径不存在", nil) return serializer.Err(serializer.CodeNotFound, "存放路径不存在", nil)

Loading…
Cancel
Save