Compare commits

...

9 Commits
3.3.1 ... 3.3.2

15 changed files with 70 additions and 62 deletions

2
assets

Submodule assets updated: 522a75c750...59890e6b22

View File

@@ -18,10 +18,10 @@ type Download struct {
DownloadedSize uint64 // 文件大小
GID string `gorm:"size:32,index:gid"` // 任务ID
Speed int // 下载速度
Parent string `gorm:"type:text"` // 存储目录
Attrs string `gorm:"size:65535"` // 任务状态属性
Error string `gorm:"type:text"` // 错误描述
Dst string `gorm:"type:text"` // 用户文件系统存储父目录路径
Parent string `gorm:"type:text"` // 存储目录
Attrs string `gorm:"size:4294967295"` // 任务状态属性
Error string `gorm:"type:text"` // 错误描述
Dst string `gorm:"type:text"` // 用户文件系统存储父目录路径
UserID uint // 发起者UID
TaskID uint // 对应的转存任务ID

View File

@@ -9,7 +9,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mssql"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
@@ -33,16 +35,14 @@ func Init() {
case "UNSET", "sqlite", "sqlite3":
// 未指定数据库或者明确指定为 sqlite 时,使用 SQLite3 数据库
db, err = gorm.Open("sqlite3", util.RelativePath(conf.DatabaseConfig.DBFile))
case "mysql":
// 当前只支持 sqlite3 与 mysql 数据库
// TODO: import 其他 gorm 支持的主流数据库?否则直接 Open 没有任何意义。
// TODO: 数据库连接其他参数允许用户自定义?譬如编码更换为 utf8mb4 以支持表情。
db, err = gorm.Open("mysql", fmt.Sprintf("%s:%s@(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",
case "mysql", "postgres", "mssql":
db, err = gorm.Open(conf.DatabaseConfig.Type, fmt.Sprintf("%s:%s@(%s:%d)/%s?charset=%s&parseTime=True&loc=Local",
conf.DatabaseConfig.User,
conf.DatabaseConfig.Password,
conf.DatabaseConfig.Host,
conf.DatabaseConfig.Port,
conf.DatabaseConfig.Name))
conf.DatabaseConfig.Name,
conf.DatabaseConfig.Charset))
default:
util.Log().Panic("不支持数据库类型: %s", conf.DatabaseConfig.Type)
}

View File

@@ -16,6 +16,7 @@ type database struct {
TablePrefix string
DBFile string
Port int
Charset string
}
// system 系统通用配置

View File

@@ -12,9 +12,10 @@ var RedisConfig = &redis{
// DatabaseConfig 数据库配置
var DatabaseConfig = &database{
Type: "UNSET",
DBFile: "cloudreve.db",
Port: 3306,
Type: "UNSET",
Charset: "utf8",
DBFile: "cloudreve.db",
Port: 3306,
}
// SystemConfig 系统公用配置
@@ -68,5 +69,5 @@ var SSLConfig = &ssl{
}
var UnixConfig = &unix{
Listen: "",
Listen: "",
}

View File

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

View File

@@ -77,11 +77,12 @@ func (client *SMTP) Init() {
d := mail.NewDialer(client.Config.Host, client.Config.Port, client.Config.User, client.Config.Password)
d.Timeout = time.Duration(client.Config.Keepalive+5) * time.Second
client.chOpen = true
// 是否启用 SSL
d.SSL = false
if client.Config.Encryption {
d.SSL = true
}
d.StartTLSPolicy = mail.OpportunisticStartTLS
var s mail.SendCloser
var err error

View File

@@ -344,7 +344,6 @@ func (handler Driver) Token(ctx context.Context, TTL int64, key string) (seriali
map[string]string{"bucket": handler.Policy.BucketName},
[]string{"starts-with", "$key", savePath},
[]string{"starts-with", "$success_action_redirect", apiURL.String()},
[]string{"starts-with", "$name", ""},
[]string{"starts-with", "$Content-Type", ""},
map[string]string{"x-amz-algorithm": "AWS4-HMAC-SHA256"},
},

View File

@@ -105,9 +105,6 @@ func (handler Driver) List(ctx context.Context, base string, recursive bool) ([]
// Get 获取文件
func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser, error) {
// 给文件名加上随机参数以强制拉取
path = fmt.Sprintf("%s?v=%d", path, time.Now().UnixNano())
// 获取文件源地址
downloadURL, err := handler.Source(
ctx,

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"path"
"strings"
"time"
model "github.com/cloudreve/Cloudreve/v3/models"
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/fsctx"
@@ -20,14 +21,14 @@ import (
// Object 文件或者目录
type Object struct {
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Pic string `json:"pic"`
Size uint64 `json:"size"`
Type string `json:"type"`
Date string `json:"date"`
Key string `json:"key,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Pic string `json:"pic"`
Size uint64 `json:"size"`
Type string `json:"type"`
Date time.Time `json:"date"`
Key string `json:"key,omitempty"`
}
// Rename 重命名对象
@@ -349,7 +350,7 @@ func (fs *FileSystem) listObjects(ctx context.Context, parent string, files []mo
Pic: "",
Size: 0,
Type: "dir",
Date: subFolder.CreatedAt.Format("2006-01-02 15:04:05"),
Date: subFolder.CreatedAt,
})
}
@@ -369,7 +370,7 @@ func (fs *FileSystem) listObjects(ctx context.Context, parent string, files []mo
Pic: file.PicInfo,
Size: file.Size,
Type: "file",
Date: file.CreatedAt.Format("2006-01-02 15:04:05"),
Date: file.CreatedAt,
}
if shareKey != "" {
newFile.Key = shareKey

View File

@@ -2,6 +2,7 @@ package serializer
import (
"path"
"time"
model "github.com/cloudreve/Cloudreve/v3/models"
"github.com/cloudreve/Cloudreve/v3/pkg/aria2/rpc"
@@ -9,7 +10,7 @@ import (
// DownloadListResponse 下载列表响应条目
type DownloadListResponse struct {
UpdateTime int64 `json:"update"`
UpdateTime time.Time `json:"update"`
UpdateInterval int `json:"interval"`
Name string `json:"name"`
Status int `json:"status"`
@@ -31,8 +32,8 @@ type FinishedListResponse struct {
Files []rpc.FileInfo `json:"files"`
TaskStatus int `json:"task_status"`
TaskError string `json:"task_error"`
CreateTime string `json:"create"`
UpdateTime string `json:"update"`
CreateTime time.Time `json:"create"`
UpdateTime time.Time `json:"update"`
}
// BuildFinishedListResponse 构建已完成任务条目
@@ -59,8 +60,8 @@ func BuildFinishedListResponse(tasks []model.Download) Response {
Total: tasks[i].TotalSize,
Files: tasks[i].StatusInfo.Files,
TaskStatus: -1,
UpdateTime: tasks[i].UpdatedAt.Format("2006-01-02 15:04:05"),
CreateTime: tasks[i].CreatedAt.Format("2006-01-02 15:04:05"),
UpdateTime: tasks[i].UpdatedAt,
CreateTime: tasks[i].CreatedAt,
}
if tasks[i].Task != nil {
@@ -92,7 +93,7 @@ func BuildDownloadingResponse(tasks []model.Download) Response {
}
resp = append(resp, DownloadListResponse{
UpdateTime: tasks[i].UpdatedAt.Unix(),
UpdateTime: tasks[i].UpdatedAt,
UpdateInterval: interval,
Name: fileName,
Status: tasks[i].Status,

View File

@@ -1,6 +1,9 @@
package serializer
import model "github.com/cloudreve/Cloudreve/v3/models"
import (
model "github.com/cloudreve/Cloudreve/v3/models"
"time"
)
// SiteConfig 站点全局设置序列
type SiteConfig struct {
@@ -19,14 +22,15 @@ type SiteConfig struct {
ReCaptchaKey string `json:"captcha_ReCaptchaKey"`
CaptchaType string `json:"captcha_type"`
TCaptchaCaptchaAppId string `json:"tcaptcha_captcha_app_id"`
RegisterEnabled bool `json:"registerEnabled"`
}
type task struct {
Status int `json:"status"`
Type int `json:"type"`
CreateDate string `json:"create_date"`
Progress int `json:"progress"`
Error string `json:"error"`
Status int `json:"status"`
Type int `json:"type"`
CreateDate time.Time `json:"create_date"`
Progress int `json:"progress"`
Error string `json:"error"`
}
// BuildTaskList 构建任务列表响应
@@ -36,7 +40,7 @@ func BuildTaskList(tasks []model.Task, total int) Response {
res = append(res, task{
Status: t.Status,
Type: t.Type,
CreateDate: t.CreatedAt.Format("2006-01-02 15:04:05"),
CreateDate: t.CreatedAt,
Progress: t.Progress,
Error: t.Error,
})
@@ -80,6 +84,7 @@ func BuildSiteConfig(settings map[string]string, user *model.User) Response {
ReCaptchaKey: checkSettingValue(settings, "captcha_ReCaptchaKey"),
CaptchaType: checkSettingValue(settings, "captcha_type"),
TCaptchaCaptchaAppId: checkSettingValue(settings, "captcha_TCaptcha_CaptchaAppId"),
RegisterEnabled: model.IsTrueVal(checkSettingValue(settings, "register_enabled")),
}}
return res
}

View File

@@ -12,7 +12,7 @@ type Share struct {
Key string `json:"key"`
Locked bool `json:"locked"`
IsDir bool `json:"is_dir"`
CreateDate string `json:"create_date,omitempty"`
CreateDate time.Time `json:"create_date,omitempty"`
Downloads int `json:"downloads"`
Views int `json:"views"`
Expire int64 `json:"expire"`
@@ -37,7 +37,7 @@ type myShareItem struct {
Key string `json:"key"`
IsDir bool `json:"is_dir"`
Password string `json:"password"`
CreateDate string `json:"create_date,omitempty"`
CreateDate time.Time `json:"create_date,omitempty"`
Downloads int `json:"downloads"`
RemainDownloads int `json:"remain_downloads"`
Views int `json:"views"`
@@ -55,7 +55,7 @@ func BuildShareList(shares []model.Share, total int) Response {
Key: hashid.HashID(shares[i].ID, hashid.ShareID),
IsDir: shares[i].IsDir,
Password: shares[i].Password,
CreateDate: shares[i].CreatedAt.Format("2006-01-02 15:04:05"),
CreateDate: shares[i].CreatedAt,
Downloads: shares[i].Downloads,
Views: shares[i].Views,
Preview: shares[i].PreviewEnabled,
@@ -99,7 +99,7 @@ func BuildShareResponse(share *model.Share, unlocked bool) Share {
Nick: creator.Nick,
GroupName: creator.Group.Name,
},
CreateDate: share.CreatedAt.Format("2006-01-02 15:04:05"),
CreateDate: share.CreatedAt,
}
// 未解锁时只返回基本信息

View File

@@ -6,6 +6,7 @@ import (
model "github.com/cloudreve/Cloudreve/v3/models"
"github.com/cloudreve/Cloudreve/v3/pkg/hashid"
"github.com/duo-labs/webauthn/webauthn"
"time"
)
// CheckLogin 检查登录
@@ -18,17 +19,17 @@ func CheckLogin() Response {
// User 用户序列化器
type User struct {
ID string `json:"id"`
Email string `json:"user_name"`
Nickname string `json:"nickname"`
Status int `json:"status"`
Avatar string `json:"avatar"`
CreatedAt int64 `json:"created_at"`
PreferredTheme string `json:"preferred_theme"`
Anonymous bool `json:"anonymous"`
Policy policy `json:"policy"`
Group group `json:"group"`
Tags []tag `json:"tags"`
ID string `json:"id"`
Email string `json:"user_name"`
Nickname string `json:"nickname"`
Status int `json:"status"`
Avatar string `json:"avatar"`
CreatedAt time.Time `json:"created_at"`
PreferredTheme string `json:"preferred_theme"`
Anonymous bool `json:"anonymous"`
Policy policy `json:"policy"`
Group group `json:"group"`
Tags []tag `json:"tags"`
}
type policy struct {
@@ -94,7 +95,7 @@ func BuildUser(user model.User) User {
Nickname: user.Nick,
Status: user.Status,
Avatar: user.Avatar,
CreatedAt: user.CreatedAt.Unix(),
CreatedAt: user.CreatedAt,
PreferredTheme: user.OptionsSerialized.PreferredTheme,
Anonymous: user.IsAnonymous(),
Policy: policy{

View File

@@ -27,6 +27,7 @@ func SiteConfig(c *gin.Context) {
"captcha_ReCaptchaKey",
"captcha_type",
"captcha_TCaptcha_CaptchaAppId",
"register_enabled",
)
// 如果已登录,则同时返回用户信息和标签