i18n: logs in models

pull/1491/head
HFO4 2 years ago
parent db23f4061d
commit 7366ff534e

@ -11,9 +11,9 @@ var defaultSettings = []Setting{
{Name: "siteName", Value: `Cloudreve`, Type: "basic"}, {Name: "siteName", Value: `Cloudreve`, Type: "basic"},
{Name: "register_enabled", Value: `1`, Type: "register"}, {Name: "register_enabled", Value: `1`, Type: "register"},
{Name: "default_group", Value: `2`, Type: "register"}, {Name: "default_group", Value: `2`, Type: "register"},
{Name: "siteKeywords", Value: `网盘,网盘`, Type: "basic"}, {Name: "siteKeywords", Value: `Cloudreve, cloud storage`, Type: "basic"},
{Name: "siteDes", Value: `Cloudreve`, Type: "basic"}, {Name: "siteDes", Value: `Cloudreve`, Type: "basic"},
{Name: "siteTitle", Value: `平步云端`, Type: "basic"}, {Name: "siteTitle", Value: `Inclusive cloud storage for everyone`, Type: "basic"},
{Name: "siteScript", Value: ``, Type: "basic"}, {Name: "siteScript", Value: ``, Type: "basic"},
{Name: "siteID", Value: uuid.Must(uuid.NewV4()).String(), Type: "basic"}, {Name: "siteID", Value: uuid.Must(uuid.NewV4()).String(), Type: "basic"},
{Name: "fromName", Value: `Cloudreve`, Type: "mail"}, {Name: "fromName", Value: `Cloudreve`, Type: "mail"},

@ -60,7 +60,7 @@ func (task *Download) BeforeSave() (err error) {
// Create 创建离线下载记录 // Create 创建离线下载记录
func (task *Download) Create() (uint, error) { func (task *Download) Create() (uint, error) {
if err := DB.Create(task).Error; err != nil { if err := DB.Create(task).Error; err != nil {
util.Log().Warning("无法插入离线下载记录, %s", err) util.Log().Warning("Failed to insert download record: %s", err)
return 0, err return 0, err
} }
return task.ID, nil return task.ID, nil
@ -69,7 +69,7 @@ func (task *Download) Create() (uint, error) {
// Save 更新 // Save 更新
func (task *Download) Save() error { func (task *Download) Save() error {
if err := DB.Save(task).Error; err != nil { if err := DB.Save(task).Error; err != nil {
util.Log().Warning("无法更新离线下载记录, %s", err) util.Log().Warning("Failed to update download record: %s", err)
return err return err
} }
return nil return nil

@ -43,7 +43,7 @@ func (file *File) Create() error {
tx := DB.Begin() tx := DB.Begin()
if err := tx.Create(file).Error; err != nil { if err := tx.Create(file).Error; err != nil {
util.Log().Warning("无法插入文件记录, %s", err) util.Log().Warning("Failed to insert file record: %s", err)
tx.Rollback() tx.Rollback()
return err return err
} }

@ -161,7 +161,7 @@ func (folder *Folder) MoveOrCopyFileTo(files []uint, dstFolder *Folder, isCopy b
// 复制文件记录 // 复制文件记录
for _, oldFile := range originFiles { for _, oldFile := range originFiles {
if !oldFile.CanCopy() { if !oldFile.CanCopy() {
util.Log().Warning("无法复制正在上传中的文件 [%s] 跳过...", oldFile.Name) util.Log().Warning("Cannot copy file %q because it's being uploaded now, skipping...", oldFile.Name)
continue continue
} }
@ -224,8 +224,8 @@ func (folder *Folder) CopyFolderTo(folderID uint, dstFolder *Folder) (size uint6
} else if IDCache, ok := newIDCache[*folder.ParentID]; ok { } else if IDCache, ok := newIDCache[*folder.ParentID]; ok {
newID = IDCache newID = IDCache
} else { } else {
util.Log().Warning("无法取得新的父目录:%d", folder.ParentID) util.Log().Warning("Failed to get parent folder %q", folder.ParentID)
return size, errors.New("无法取得新的父目录") return size, errors.New("Failed to get parent folder")
} }
// 插入新的目录记录 // 插入新的目录记录
@ -254,7 +254,7 @@ func (folder *Folder) CopyFolderTo(folderID uint, dstFolder *Folder) (size uint6
// 复制文件记录 // 复制文件记录
for _, oldFile := range originFiles { for _, oldFile := range originFiles {
if !oldFile.CanCopy() { if !oldFile.CanCopy() {
util.Log().Warning("无法复制正在上传中的文件 [%s] 跳过...", oldFile.Name) util.Log().Warning("Cannot copy file %q because it's being uploaded now, skipping...", oldFile.Name)
continue continue
} }

@ -20,7 +20,7 @@ var DB *gorm.DB
// Init 初始化 MySQL 链接 // Init 初始化 MySQL 链接
func Init() { func Init() {
util.Log().Info("初始化数据库连接") util.Log().Info("Initializing database connection...")
var ( var (
db *gorm.DB db *gorm.DB
@ -51,13 +51,13 @@ func Init() {
conf.DatabaseConfig.Name, conf.DatabaseConfig.Name,
conf.DatabaseConfig.Charset)) conf.DatabaseConfig.Charset))
default: default:
util.Log().Panic("不支持数据库类型: %s", conf.DatabaseConfig.Type) util.Log().Panic("Unsupported database type %q.", conf.DatabaseConfig.Type)
} }
} }
//db.SetLogger(util.Log()) //db.SetLogger(util.Log())
if err != nil { if err != nil {
util.Log().Panic("连接数据库不成功, %s", err) util.Log().Panic("Failed to connect to database: %s", err)
} }
// 处理表前缀 // 处理表前缀

@ -23,12 +23,12 @@ func needMigration() bool {
func migration() { func migration() {
// 确认是否需要执行迁移 // 确认是否需要执行迁移
if !needMigration() { if !needMigration() {
util.Log().Info("数据库版本匹配,跳过数据库迁移") util.Log().Info("Database version fulfilled, skip schema migration.")
return return
} }
util.Log().Info("开始进行数据库初始化...") util.Log().Info("Start initializing database schema...")
// 清除所有缓存 // 清除所有缓存
if instance, ok := cache.Store.(*cache.RedisStore); ok { if instance, ok := cache.Store.(*cache.RedisStore); ok {
@ -61,7 +61,7 @@ func migration() {
// 执行数据库升级脚本 // 执行数据库升级脚本
execUpgradeScripts() execUpgradeScripts()
util.Log().Info("数据库初始化结束") util.Log().Info("Finish initializing database schema.")
} }
@ -70,7 +70,7 @@ func addDefaultPolicy() {
// 未找到初始存储策略时,则创建 // 未找到初始存储策略时,则创建
if gorm.IsRecordNotFoundError(err) { if gorm.IsRecordNotFoundError(err) {
defaultPolicy := Policy{ defaultPolicy := Policy{
Name: "默认存储策略", Name: "Default storage policy",
Type: "local", Type: "local",
MaxSize: 0, MaxSize: 0,
AutoRename: true, AutoRename: true,
@ -82,7 +82,7 @@ func addDefaultPolicy() {
}, },
} }
if err := DB.Create(&defaultPolicy).Error; err != nil { if err := DB.Create(&defaultPolicy).Error; err != nil {
util.Log().Panic("无法创建初始存储策略, %s", err) util.Log().Panic("Failed to create default storage policy: %s", err)
} }
} }
} }
@ -98,7 +98,7 @@ func addDefaultGroups() {
// 未找到初始管理组时,则创建 // 未找到初始管理组时,则创建
if gorm.IsRecordNotFoundError(err) { if gorm.IsRecordNotFoundError(err) {
defaultAdminGroup := Group{ defaultAdminGroup := Group{
Name: "管理员", Name: "Admin",
PolicyList: []uint{1}, PolicyList: []uint{1},
MaxStorage: 1 * 1024 * 1024 * 1024, MaxStorage: 1 * 1024 * 1024 * 1024,
ShareEnabled: true, ShareEnabled: true,
@ -113,7 +113,7 @@ func addDefaultGroups() {
}, },
} }
if err := DB.Create(&defaultAdminGroup).Error; err != nil { if err := DB.Create(&defaultAdminGroup).Error; err != nil {
util.Log().Panic("无法创建管理用户组, %s", err) util.Log().Panic("Failed to create admin user group: %s", err)
} }
} }
@ -122,7 +122,7 @@ func addDefaultGroups() {
// 未找到初始注册会员时,则创建 // 未找到初始注册会员时,则创建
if gorm.IsRecordNotFoundError(err) { if gorm.IsRecordNotFoundError(err) {
defaultAdminGroup := Group{ defaultAdminGroup := Group{
Name: "注册会员", Name: "User",
PolicyList: []uint{1}, PolicyList: []uint{1},
MaxStorage: 1 * 1024 * 1024 * 1024, MaxStorage: 1 * 1024 * 1024 * 1024,
ShareEnabled: true, ShareEnabled: true,
@ -134,7 +134,7 @@ func addDefaultGroups() {
}, },
} }
if err := DB.Create(&defaultAdminGroup).Error; err != nil { if err := DB.Create(&defaultAdminGroup).Error; err != nil {
util.Log().Panic("无法创建初始注册会员用户组, %s", err) util.Log().Panic("Failed to create initial user group: %s", err)
} }
} }
@ -143,7 +143,7 @@ func addDefaultGroups() {
// 未找到初始游客用户组时,则创建 // 未找到初始游客用户组时,则创建
if gorm.IsRecordNotFoundError(err) { if gorm.IsRecordNotFoundError(err) {
defaultAdminGroup := Group{ defaultAdminGroup := Group{
Name: "游客", Name: "Anonymous",
PolicyList: []uint{}, PolicyList: []uint{},
Policies: "[]", Policies: "[]",
OptionsSerialized: GroupOption{ OptionsSerialized: GroupOption{
@ -151,7 +151,7 @@ func addDefaultGroups() {
}, },
} }
if err := DB.Create(&defaultAdminGroup).Error; err != nil { if err := DB.Create(&defaultAdminGroup).Error; err != nil {
util.Log().Panic("无法创建初始游客用户组, %s", err) util.Log().Panic("Failed to create anonymous user group: %s", err)
} }
} }
} }
@ -169,15 +169,15 @@ func addDefaultUser() {
defaultUser.GroupID = 1 defaultUser.GroupID = 1
err := defaultUser.SetPassword(password) err := defaultUser.SetPassword(password)
if err != nil { if err != nil {
util.Log().Panic("无法创建密码, %s", err) util.Log().Panic("Failed to create password: %s", err)
} }
if err := DB.Create(&defaultUser).Error; err != nil { if err := DB.Create(&defaultUser).Error; err != nil {
util.Log().Panic("无法创建初始用户, %s", err) util.Log().Panic("Failed to create initial root user: %s", err)
} }
c := color.New(color.FgWhite).Add(color.BgBlack).Add(color.Bold) c := color.New(color.FgWhite).Add(color.BgBlack).Add(color.Bold)
util.Log().Info("初始管理员账号:" + c.Sprint("admin@cloudreve.org")) util.Log().Info("Admin user name: " + c.Sprint("admin@cloudreve.org"))
util.Log().Info("初始管理员密码:" + c.Sprint(password)) util.Log().Info("Admin password: " + c.Sprint(password))
} }
} }
@ -186,7 +186,7 @@ func addDefaultNode() {
if gorm.IsRecordNotFoundError(err) { if gorm.IsRecordNotFoundError(err) {
defaultAdminGroup := Node{ defaultAdminGroup := Node{
Name: "主机(本机)", Name: "Master (Local machine)",
Status: NodeActive, Status: NodeActive,
Type: MasterNodeType, Type: MasterNodeType,
Aria2OptionsSerialized: Aria2Option{ Aria2OptionsSerialized: Aria2Option{
@ -195,7 +195,7 @@ func addDefaultNode() {
}, },
} }
if err := DB.Create(&defaultAdminGroup).Error; err != nil { if err := DB.Create(&defaultAdminGroup).Error; err != nil {
util.Log().Panic("无法创建初始节点记录, %s", err) util.Log().Panic("Failed to create initial node: %s", err)
} }
} }
} }

@ -36,7 +36,7 @@ type Share struct {
// Create 创建分享 // Create 创建分享
func (share *Share) Create() (uint, error) { func (share *Share) Create() (uint, error) {
if err := DB.Create(share).Error; err != nil { if err := DB.Create(share).Error; err != nil {
util.Log().Warning("无法插入数据库记录, %s", err) util.Log().Warning("Failed to insert share record: %s", err)
return 0, err return 0, err
} }
return share.ID, nil return share.ID, nil
@ -131,9 +131,9 @@ func (share *Share) CanBeDownloadBy(user *User) error {
// 用户组权限 // 用户组权限
if !user.Group.OptionsSerialized.ShareDownload { if !user.Group.OptionsSerialized.ShareDownload {
if user.IsAnonymous() { if user.IsAnonymous() {
return errors.New("未登录用户无法下载") return errors.New("you must login to download")
} }
return errors.New("您当前的用户组无权下载") return errors.New("your group has no permission to download")
} }
return nil return nil
} }

@ -26,7 +26,7 @@ const (
// Create 创建标签记录 // Create 创建标签记录
func (tag *Tag) Create() (uint, error) { func (tag *Tag) Create() (uint, error) {
if err := DB.Create(tag).Error; err != nil { if err := DB.Create(tag).Error; err != nil {
util.Log().Warning("无法插入离线下载记录, %s", err) util.Log().Warning("Failed to insert tag record: %s", err)
return 0, err return 0, err
} }
return tag.ID, nil return tag.ID, nil

@ -19,7 +19,7 @@ type Task struct {
// Create 创建任务记录 // Create 创建任务记录
func (task *Task) Create() (uint, error) { func (task *Task) Create() (uint, error) {
if err := DB.Create(task).Error; err != nil { if err := DB.Create(task).Error; err != nil {
util.Log().Warning("无法插入任务记录, %s", err) util.Log().Warning("Failed to insert task record: %s", err)
return 0, err return 0, err
} }
return task.ID, nil return task.ID, nil

Loading…
Cancel
Save