i18n: logs in rest pkgs

pull/1503/head
HFO4 2 years ago
parent f2c53dda31
commit 644a326580

@ -1 +1 @@
Subproject commit 02d93206cc5b943c34b5f5ac86c23dd96f5ef603
Subproject commit 547078fa21bb5ff5109e40097103dd8090bba296

@ -99,6 +99,7 @@ require (
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/mattn/go-sqlite3 v1.14.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect

@ -35,9 +35,9 @@ 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.StringVar(&confPath, "c", util.RelativePath("conf.ini"), "Path to the config file.")
flag.BoolVar(&isEject, "eject", false, "Eject all embedded static files.")
flag.StringVar(&scriptName, "database-script", "", "Name of database util script.")
flag.Parse()
staticFS = archiver.ArchiveFS{
@ -71,7 +71,7 @@ func main() {
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
go func() {
sig := <-sigChan
util.Log().Info("收到信号 %s开始关闭 server", sig)
util.Log().Info("Signal %s received, shutting down server...", sig)
ctx := context.Background()
if conf.SystemConfig.GracePeriod != 0 {
var cancel context.CancelFunc
@ -81,16 +81,16 @@ func main() {
err := server.Shutdown(ctx)
if err != nil {
util.Log().Error("关闭 server 错误, %s", err)
util.Log().Error("Failed to shutdown server: %s", err)
}
}()
// 如果启用了SSL
if conf.SSLConfig.CertPath != "" {
util.Log().Info("开始监听 %s", conf.SSLConfig.Listen)
util.Log().Info("Listening to %q", conf.SSLConfig.Listen)
server.Addr = conf.SSLConfig.Listen
if err := server.ListenAndServeTLS(conf.SSLConfig.CertPath, conf.SSLConfig.KeyPath); err != nil {
util.Log().Error("无法监听[%s]%s", conf.SSLConfig.Listen, err)
util.Log().Error("Failed to listen to %q: %s", conf.SSLConfig.Listen, err)
return
}
}
@ -100,23 +100,23 @@ func main() {
// delete socket file before listening
if _, err := os.Stat(conf.UnixConfig.Listen); err == nil {
if err = os.Remove(conf.UnixConfig.Listen); err != nil {
util.Log().Error("删除 socket 文件错误, %s", err)
util.Log().Error("Failed to delete socket file: %s", err)
return
}
}
api.TrustedPlatform = conf.UnixConfig.ProxyHeader
util.Log().Info("开始监听 %s", conf.UnixConfig.Listen)
util.Log().Info("Listening to %q", conf.UnixConfig.Listen)
if err := RunUnix(server); err != nil {
util.Log().Error("无法监听[%s]%s", conf.UnixConfig.Listen, err)
util.Log().Error("Failed to listen to %q: %s", conf.UnixConfig.Listen, err)
}
return
}
util.Log().Info("开始监听 %s", conf.SystemConfig.Listen)
util.Log().Info("Listening to %q", conf.SystemConfig.Listen)
server.Addr = conf.SystemConfig.Listen
if err := server.ListenAndServe(); err != nil {
util.Log().Error("无法监听[%s]%s", conf.SystemConfig.Listen, err)
util.Log().Error("Failed to listen to %q: %s", conf.SystemConfig.Listen, err)
}
}

@ -19,7 +19,7 @@ const (
var (
// ErrTypeNotMatch ID类型不匹配
ErrTypeNotMatch = errors.New("ID类型不匹配")
ErrTypeNotMatch = errors.New("mismatched ID type.")
)
// HashEncode 对给定数据计算HashID

@ -179,7 +179,7 @@ func (resp *Response) DecodeResponse() (*serializer.Response, error) {
var res serializer.Response
err = json.Unmarshal([]byte(respString), &res)
if err != nil {
util.Log().Debug("无法解析回调服务端响应:%s", string(respString))
util.Log().Debug("Failed to parse response: %s", string(respString))
return nil, err
}
return &res, nil
@ -251,7 +251,7 @@ func (instance NopRSCloser) Seek(offset int64, whence int) (int64, error) {
return instance.status.Size, nil
}
}
return 0, errors.New("未实现")
return 0, errors.New("not implemented")
}

@ -221,7 +221,7 @@ const (
// DBErr 数据库操作失败
func DBErr(msg string, err error) Response {
if msg == "" {
msg = "数据库操作失败"
msg = "Database operation failed."
}
return Err(CodeDBError, msg, err)
}
@ -229,7 +229,7 @@ func DBErr(msg string, err error) Response {
// ParamErr 各种参数错误
func ParamErr(msg string, err error) Response {
if msg == "" {
msg = "参数错误"
msg = "Invalid parameters."
}
return Err(CodeParamErr, msg, err)
}

@ -19,7 +19,7 @@ func NewResponseWithGobData(data interface{}) Response {
var w bytes.Buffer
encoder := gob.NewEncoder(&w)
if err := encoder.Encode(data); err != nil {
return Err(CodeInternalSetting, "无法编码返回结果", err)
return Err(CodeInternalSetting, "Failed to encode response content", err)
}
return Response{Data: w.Bytes()}

@ -13,7 +13,7 @@ import (
func CheckLogin() Response {
return Response{
Code: CodeCheckLogin,
Msg: "未登录",
Msg: "Login required",
}
}

@ -69,7 +69,7 @@ func (job *CompressTask) SetError(err *JobError) {
func (job *CompressTask) removeZipFile() {
if job.zipPath != "" {
if err := os.Remove(job.zipPath); err != nil {
util.Log().Warning("无法删除临时压缩文件 %s , %s", job.zipPath, err)
util.Log().Warning("Failed to delete temp zip file %q: %s", job.zipPath, err)
}
}
}
@ -93,7 +93,7 @@ func (job *CompressTask) Do() {
return
}
util.Log().Debug("开始压缩文件")
util.Log().Debug("Starting compress file...")
job.TaskModel.SetProgress(CompressingProgress)
// 创建临时压缩文件
@ -122,7 +122,7 @@ func (job *CompressTask) Do() {
job.zipPath = zipFilePath
zipFile.Close()
util.Log().Debug("压缩文件存放至%s开始上传", zipFilePath)
util.Log().Debug("Compressed file saved to %q, start uploading it...", zipFilePath)
job.TaskModel.SetProgress(TransferringProgress)
// 上传文件

@ -77,7 +77,7 @@ func (job *DecompressTask) Do() {
// 创建文件系统
fs, err := filesystem.NewFileSystem(job.User)
if err != nil {
job.SetErrorMsg("无法创建文件系统", err)
job.SetErrorMsg("Failed to create filesystem.", err)
return
}
@ -85,7 +85,7 @@ func (job *DecompressTask) Do() {
err = fs.Decompress(context.Background(), job.TaskProps.Src, job.TaskProps.Dst, job.TaskProps.Encoding)
if err != nil {
job.SetErrorMsg("解压缩失败", err)
job.SetErrorMsg("Failed to decompress file.", err)
return
}

@ -4,5 +4,5 @@ import "errors"
var (
// ErrUnknownTaskType 未知任务类型
ErrUnknownTaskType = errors.New("未知任务类型")
ErrUnknownTaskType = errors.New("unknown task type")
)

@ -81,7 +81,7 @@ func (job *ImportTask) Do() {
// 查找存储策略
policy, err := model.GetPolicyByID(job.TaskProps.PolicyID)
if err != nil {
job.SetErrorMsg("找不到存储策略", err)
job.SetErrorMsg("Policy not exist.", err)
return
}
@ -96,7 +96,7 @@ func (job *ImportTask) Do() {
fs.Policy = &policy
if err := fs.DispatchHandler(); err != nil {
job.SetErrorMsg("无法分发存储策略", err)
job.SetErrorMsg("Failed to dispatch policy.", err)
return
}
@ -110,7 +110,7 @@ func (job *ImportTask) Do() {
true)
objects, err := fs.Handler.List(ctx, job.TaskProps.Src, job.TaskProps.Recursive)
if err != nil {
job.SetErrorMsg("无法列取文件", err)
job.SetErrorMsg("Failed to list files.", err)
return
}
@ -126,7 +126,7 @@ func (job *ImportTask) Do() {
virtualPath := path.Join(job.TaskProps.Dst, object.RelativePath)
folder, err := fs.CreateDirectory(coxIgnoreConflict, virtualPath)
if err != nil {
util.Log().Warning("导入任务无法创建用户目录[%s], %s", virtualPath, err)
util.Log().Warning("Importing task cannot create user directory %q: %s", virtualPath, err)
} else if folder.ID > 0 {
pathCache[virtualPath] = folder
}
@ -152,7 +152,7 @@ func (job *ImportTask) Do() {
} else {
folder, err := fs.CreateDirectory(context.Background(), virtualPath)
if err != nil {
util.Log().Warning("导入任务无法创建用户目录[%s], %s",
util.Log().Warning("Importing task cannot create user directory %q: %s",
virtualPath, err)
continue
}
@ -163,10 +163,10 @@ func (job *ImportTask) Do() {
// 插入文件记录
_, err := fs.AddFile(context.Background(), parentFolder, &fileHeader)
if err != nil {
util.Log().Warning("导入任务无法创插入文件[%s], %s",
util.Log().Warning("Importing task cannot insert user file %q: %s",
object.RelativePath, err)
if err == filesystem.ErrInsufficientCapacity {
job.SetErrorMsg("容量不足", err)
job.SetErrorMsg("Insufficient storage capacity.", err)
return
}
}

@ -89,12 +89,12 @@ func Resume(p Pool) {
if len(tasks) == 0 {
return
}
util.Log().Info("从数据库中恢复 %d 个未完成任务", len(tasks))
util.Log().Info("Resume %d unfinished task(s) from database.", len(tasks))
for i := 0; i < len(tasks); i++ {
job, err := GetJobFromModel(&tasks[i])
if err != nil {
util.Log().Warning("无法恢复任务,%s", err)
util.Log().Warning("Failed to resume task: %s", err)
continue
}

@ -44,11 +44,11 @@ func (pool *AsyncPool) freeWorker() {
// Submit 开始提交任务
func (pool *AsyncPool) Submit(job Job) {
go func() {
util.Log().Debug("等待获取Worker")
util.Log().Debug("Waiting for Worker.")
worker := pool.obtainWorker()
util.Log().Debug("获取到Worker")
util.Log().Debug("Worker obtained.")
worker.Do(job)
util.Log().Debug("释放Worker")
util.Log().Debug("Worker released.")
pool.freeWorker()
}()
}
@ -60,7 +60,7 @@ func Init() {
idleWorker: make(chan int, maxWorker),
}
TaskPoll.Add(maxWorker)
util.Log().Info("初始化任务队列,WorkerNum = %d", maxWorker)
util.Log().Info("Initialize task queue with WorkerNum = %d", maxWorker)
if conf.SystemConfig.Mode == "master" {
Resume(TaskPoll)

@ -73,21 +73,21 @@ func (job *RecycleTask) GetError() *JobError {
func (job *RecycleTask) Do() {
download, err := model.GetDownloadByGid(job.TaskProps.DownloadGID, job.User.ID)
if err != nil {
util.Log().Warning("回收任务 %d 找不到下载记录", job.TaskModel.ID)
job.SetErrorMsg("无法找到下载任务", err)
util.Log().Warning("Recycle task %d cannot found download record.", job.TaskModel.ID)
job.SetErrorMsg("Cannot found download task.", err)
return
}
nodeID := download.GetNodeID()
node := cluster.Default.GetNodeByID(nodeID)
if node == nil {
util.Log().Warning("回收任务 %d 找不到节点", job.TaskModel.ID)
job.SetErrorMsg("从机节点不可用", nil)
util.Log().Warning("Recycle task %d cannot found node.", job.TaskModel.ID)
job.SetErrorMsg("Invalid slave node.", nil)
return
}
err = node.GetAria2Instance().DeleteTempFile(download)
if err != nil {
util.Log().Warning("无法删除中转临时目录[%s], %s", download.Parent, err)
job.SetErrorMsg("文件回收失败", err)
util.Log().Warning("Failed to delete transfer temp folder %q: %s", download.Parent, err)
job.SetErrorMsg("Failed to recycle files.", err)
return
}
}

@ -69,7 +69,7 @@ func (job *TransferTask) SetErrorMsg(msg string, err error) {
}
if err := cluster.DefaultController.SendNotification(job.MasterID, job.Req.Hash(job.MasterID), notifyMsg); err != nil {
util.Log().Warning("无法发送转存失败通知到从机, %s", err)
util.Log().Warning("Failed to send transfer failure notification to master node: %s", err)
}
}
@ -82,26 +82,26 @@ func (job *TransferTask) GetError() *task.JobError {
func (job *TransferTask) Do() {
fs, err := filesystem.NewAnonymousFileSystem()
if err != nil {
job.SetErrorMsg("无法初始化匿名文件系统", err)
job.SetErrorMsg("Failed to initialize anonymous filesystem.", err)
return
}
fs.Policy = job.Req.Policy
if err := fs.DispatchHandler(); err != nil {
job.SetErrorMsg("无法分发存储策略", err)
job.SetErrorMsg("Failed to dispatch policy.", err)
return
}
master, err := cluster.DefaultController.GetMasterInfo(job.MasterID)
if err != nil {
job.SetErrorMsg("找不到主机节点", err)
job.SetErrorMsg("Cannot found master node ID.", err)
return
}
fs.SwitchToShadowHandler(master.Instance, master.URL.String(), master.ID)
file, err := os.Open(util.RelativePath(job.Req.Src))
if err != nil {
job.SetErrorMsg("无法读取源文件", err)
job.SetErrorMsg("Failed to read source file.", err)
return
}
@ -110,7 +110,7 @@ func (job *TransferTask) Do() {
// 获取源文件大小
fi, err := file.Stat()
if err != nil {
job.SetErrorMsg("无法获取源文件大小", err)
job.SetErrorMsg("Failed to get source file size.", err)
return
}
@ -122,7 +122,7 @@ func (job *TransferTask) Do() {
Size: uint64(size),
})
if err != nil {
job.SetErrorMsg("文件上传失败", err)
job.SetErrorMsg("Upload failed.", err)
return
}
@ -133,6 +133,6 @@ func (job *TransferTask) Do() {
}
if err := cluster.DefaultController.SendNotification(job.MasterID, job.Req.Hash(job.MasterID), msg); err != nil {
util.Log().Warning("无法发送转存成功通知到从机, %s", err)
util.Log().Warning("Failed to send transfer success notification to master node: %s", err)
}
}

@ -109,7 +109,7 @@ func (job *TransferTask) Do() {
// 获取从机节点
node := cluster.Default.GetNodeByID(job.TaskProps.NodeID)
if node == nil {
job.SetErrorMsg("从机节点不可用", nil)
job.SetErrorMsg("Invalid slave node.", nil)
}
// 切换为从机节点处理上传
@ -127,7 +127,7 @@ func (job *TransferTask) Do() {
}
if err != nil {
job.SetErrorMsg("文件转存失败", err)
job.SetErrorMsg("Failed to transfer file.", err)
} else {
successCount++
job.TaskModel.SetProgress(successCount)

@ -16,14 +16,14 @@ type GeneralWorker struct {
// Do 执行任务
func (worker *GeneralWorker) Do(job Job) {
util.Log().Debug("开始执行任务")
util.Log().Debug("Start executing task.")
job.SetStatus(Processing)
defer func() {
// 致命错误捕获
if err := recover(); err != nil {
util.Log().Debug("任务执行出错,%s", err)
job.SetError(&JobError{Msg: "致命错误", Error: fmt.Sprintf("%s", err)})
util.Log().Debug("Failed to execute task: %s", err)
job.SetError(&JobError{Msg: "Fatal error.", Error: fmt.Sprintf("%s", err)})
job.SetStatus(Error)
}
}()
@ -33,12 +33,12 @@ func (worker *GeneralWorker) Do(job Job) {
// 任务执行失败
if err := job.GetError(); err != nil {
util.Log().Debug("任务执行出错")
util.Log().Debug("Failed to execute task.")
job.SetStatus(Error)
return
}
util.Log().Debug("任务执行完成")
util.Log().Debug("Task finished.")
// 执行完成
job.SetStatus(Complete)
}

@ -45,7 +45,7 @@ func NewThumbFromFile(file io.Reader, name string) (*Thumb, error) {
case "png":
img, err = png.Decode(file)
default:
return nil, errors.New("未知的图像类型")
return nil, errors.New("unknown image format")
}
if err != nil {
return nil, err

@ -22,7 +22,7 @@ func CreatNestedFile(path string) (*os.File, error) {
if !Exists(basePath) {
err := os.MkdirAll(basePath, 0700)
if err != nil {
Log().Warning("无法创建目录,%s", err)
Log().Warning("Failed to create directory: %s", err)
return nil, err
}
}

@ -16,10 +16,10 @@ import (
// InitRouter 初始化路由
func InitRouter() *gin.Engine {
if conf.SystemConfig.Mode == "master" {
util.Log().Info("当前运行模式Master")
util.Log().Info("Current running mode: Master.")
return InitMasterRouter()
}
util.Log().Info("当前运行模式Slave")
util.Log().Info("Current running mode: Slave.")
return InitSlaveRouter()
}
@ -108,7 +108,7 @@ func InitCORS(router *gin.Engine) {
// slave模式下未启动跨域的警告
if conf.SystemConfig.Mode == "slave" {
util.Log().Warning("当前作为存储端Slave运行但未启用跨域配置可能会导致 Master 端无法正常上传文件")
util.Log().Warning("You are running Cloudreve as slave node, if you are using slave storage policy, please enable CORS feature in config file, otherwise file cannot be uploaded from Master site.")
}
}

Loading…
Cancel
Save