i18n: logs in filesystem

pull/1491/head
HFO4 2 years ago
parent 196729bae8
commit 28c2ffe72e

@ -107,7 +107,7 @@ func (fs *FileSystem) doCompress(ctx context.Context, file *model.File, folder *
fs.Policy = file.GetPolicy() fs.Policy = file.GetPolicy()
err := fs.DispatchHandler() err := fs.DispatchHandler()
if err != nil { if err != nil {
util.Log().Warning("无法压缩文件%s%s", file.Name, err) util.Log().Warning("Failed to compress file %q: %s", file.Name, err)
return return
} }
@ -117,7 +117,7 @@ func (fs *FileSystem) doCompress(ctx context.Context, file *model.File, folder *
file.SourceName, file.SourceName,
) )
if err != nil { if err != nil {
util.Log().Debug("Open%s%s", file.Name, err) util.Log().Debug("Failed to open %q: %s", file.Name, err)
return return
} }
if closer, ok := fileToZip.(io.Closer); ok { if closer, ok := fileToZip.(io.Closer); ok {
@ -176,7 +176,7 @@ func (fs *FileSystem) Decompress(ctx context.Context, src, dst, encoding string)
// 结束时删除临时压缩文件 // 结束时删除临时压缩文件
if tempZipFilePath != "" { if tempZipFilePath != "" {
if err := os.Remove(tempZipFilePath); err != nil { if err := os.Remove(tempZipFilePath); err != nil {
util.Log().Warning("无法删除临时压缩文件 %s , %s", tempZipFilePath, err) util.Log().Warning("Failed to delete temp archive file %q: %s", tempZipFilePath, err)
} }
} }
}() }()
@ -197,7 +197,7 @@ func (fs *FileSystem) Decompress(ctx context.Context, src, dst, encoding string)
zipFile, err := util.CreatNestedFile(tempZipFilePath) zipFile, err := util.CreatNestedFile(tempZipFilePath)
if err != nil { if err != nil {
util.Log().Warning("无法创建临时压缩文件 %s , %s", tempZipFilePath, err) util.Log().Warning("Failed to create temp archive file %q: %s", tempZipFilePath, err)
tempZipFilePath = "" tempZipFilePath = ""
return err return err
} }
@ -206,7 +206,7 @@ func (fs *FileSystem) Decompress(ctx context.Context, src, dst, encoding string)
// 下载前先判断是否是可解压的格式 // 下载前先判断是否是可解压的格式
format, readStream, err := archiver.Identify(fs.FileTarget[0].SourceName, fileStream) format, readStream, err := archiver.Identify(fs.FileTarget[0].SourceName, fileStream)
if err != nil { if err != nil {
util.Log().Warning("无法识别文件格式 %s , %s", fs.FileTarget[0].SourceName, err) util.Log().Warning("Failed to detect compressed format of file %q: %s", fs.FileTarget[0].SourceName, err)
return err return err
} }
@ -228,7 +228,7 @@ func (fs *FileSystem) Decompress(ctx context.Context, src, dst, encoding string)
if isZip { if isZip {
_, err = io.Copy(zipFile, readStream) _, err = io.Copy(zipFile, readStream)
if err != nil { if err != nil {
util.Log().Warning("无法写入临时压缩文件 %s , %s", tempZipFilePath, err) util.Log().Warning("Failed to write temp archive file %q: %s", tempZipFilePath, err)
return err return err
} }
@ -261,7 +261,7 @@ func (fs *FileSystem) Decompress(ctx context.Context, src, dst, encoding string)
wg.Done() wg.Done()
} }
if err := recover(); err != nil { if err := recover(); err != nil {
util.Log().Warning("上传压缩包内文件时出错") util.Log().Warning("Error while uploading files inside of archive file.")
fmt.Println(err) fmt.Println(err)
} }
}() }()
@ -274,7 +274,7 @@ func (fs *FileSystem) Decompress(ctx context.Context, src, dst, encoding string)
}, true) }, true)
fileStream.Close() fileStream.Close()
if err != nil { if err != nil {
util.Log().Debug("无法上传压缩包内的文件%s , %s , 跳过", rawPath, err) util.Log().Debug("Failed to upload file %q in archive file: %s, skipping...", rawPath, err)
} }
} }
@ -297,7 +297,7 @@ func (fs *FileSystem) Decompress(ctx context.Context, src, dst, encoding string)
// 上传文件 // 上传文件
fileStream, err := f.Open() fileStream, err := f.Open()
if err != nil { if err != nil {
util.Log().Warning("无法打开压缩包内文件%s , %s , 跳过", rawPath, err) util.Log().Warning("Failed to open file %q in archive file: %s, skipping...", rawPath, err)
return nil return nil
} }

@ -72,7 +72,7 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder, file fs
if err != nil { if err != nil {
if err := fs.Trigger(ctx, "AfterValidateFailed", file); err != nil { if err := fs.Trigger(ctx, "AfterValidateFailed", file); err != nil {
util.Log().Debug("AfterValidateFailed 钩子执行失败,%s", err) util.Log().Debug("AfterValidateFailed hook execution failed: %s", err)
} }
return nil, ErrFileExisted.WithError(err) return nil, ErrFileExisted.WithError(err)
} }
@ -203,7 +203,7 @@ func (fs *FileSystem) deleteGroupedFile(ctx context.Context, files map[uint][]*m
// 取消上传会话 // 取消上传会话
for _, upSession := range uploadSessions { for _, upSession := range uploadSessions {
if err := fs.Handler.CancelToken(ctx, upSession); err != nil { if err := fs.Handler.CancelToken(ctx, upSession); err != nil {
util.Log().Warning("无法取消 [%s] 的上传会话: %s", upSession.Name, err) util.Log().Warning("Failed to cancel upload session for %q: %s", upSession.Name, err)
} }
cache.Deletes([]string{upSession.Key}, UploadSessionCachePrefix) cache.Deletes([]string{upSession.Key}, UploadSessionCachePrefix)
@ -270,14 +270,14 @@ func (fs *FileSystem) GetSource(ctx context.Context, fileID uint) (string, error
if !fs.Policy.IsOriginLinkEnable { if !fs.Policy.IsOriginLinkEnable {
return "", serializer.NewError( return "", serializer.NewError(
serializer.CodePolicyNotAllowed, serializer.CodePolicyNotAllowed,
"当前存储策略无法获得外链", "This policy is not enabled for getting source link",
nil, nil,
) )
} }
source, err := fs.SignURL(ctx, &fs.FileTarget[0], 0, false) source, err := fs.SignURL(ctx, &fs.FileTarget[0], 0, false)
if err != nil { if err != nil {
return "", serializer.NewError(serializer.CodeNotSet, "无法获取外链", err) return "", serializer.NewError(serializer.CodeNotSet, "Failed to get source link", err)
} }
return source, nil return source, nil
@ -298,7 +298,7 @@ func (fs *FileSystem) SignURL(ctx context.Context, file *model.File, ttl int64,
siteURL := model.GetSiteURL() siteURL := model.GetSiteURL()
source, err := fs.Handler.Source(ctx, fs.FileTarget[0].SourceName, *siteURL, ttl, isDownload, fs.User.Group.SpeedLimit) source, err := fs.Handler.Source(ctx, fs.FileTarget[0].SourceName, *siteURL, ttl, isDownload, fs.User.Group.SpeedLimit)
if err != nil { if err != nil {
return "", serializer.NewError(serializer.CodeNotSet, "无法获取外链", err) return "", serializer.NewError(serializer.CodeNotSet, "Failed to get source link", err)
} }
return source, nil return source, nil

@ -203,7 +203,7 @@ func NewFileSystemFromCallback(c *gin.Context) (*FileSystem, error) {
// 获取回调会话 // 获取回调会话
callbackSessionRaw, ok := c.Get(UploadSessionCtx) callbackSessionRaw, ok := c.Get(UploadSessionCtx)
if !ok { if !ok {
return nil, errors.New("找不到回调会话") return nil, errors.New("upload session not exist")
} }
callbackSession := callbackSessionRaw.(*serializer.UploadSession) callbackSession := callbackSessionRaw.(*serializer.UploadSession)

@ -44,7 +44,7 @@ func (fs *FileSystem) Trigger(ctx context.Context, name string, file fsctx.FileH
for _, hook := range hooks { for _, hook := range hooks {
err := hook(ctx, fs, file) err := hook(ctx, fs, file)
if err != nil { if err != nil {
util.Log().Warning("钩子执行失败%s", err) util.Log().Warning("Failed to execute hook%s", err)
return err return err
} }
} }
@ -112,7 +112,7 @@ func HookDeleteTempFile(ctx context.Context, fs *FileSystem, file fsctx.FileHead
// 删除临时文件 // 删除临时文件
_, err := fs.Handler.Delete(ctx, []string{file.Info().SavePath}) _, err := fs.Handler.Delete(ctx, []string{file.Info().SavePath})
if err != nil { if err != nil {
util.Log().Warning("无法清理上传临时文件,%s", err) util.Log().Warning("Failed to clean-up temp files: %s", err)
} }
return nil return nil

@ -71,16 +71,16 @@ func getThumbWorker() *Pool {
thumbPool = &Pool{ thumbPool = &Pool{
worker: make(chan int, maxWorker), worker: make(chan int, maxWorker),
} }
util.Log().Debug("初始化Thumb任务队列WorkerNum = %d", maxWorker) util.Log().Debug("Initialize thumbnails task queue with: WorkerNum = %d", maxWorker)
}) })
return thumbPool return thumbPool
} }
func (pool *Pool) addWorker() { func (pool *Pool) addWorker() {
pool.worker <- 1 pool.worker <- 1
util.Log().Debug("Thumb任务队列addWorker") util.Log().Debug("Worker added to thumbnails task queue.")
} }
func (pool *Pool) releaseWorker() { func (pool *Pool) releaseWorker() {
util.Log().Debug("Thumb任务队列releaseWorker") util.Log().Debug("Worker released from thumbnails task queue.")
<-pool.worker <-pool.worker
} }
@ -107,7 +107,7 @@ func (fs *FileSystem) GenerateThumbnail(ctx context.Context, file *model.File) {
image, err := thumb.NewThumbFromFile(source, file.Name) image, err := thumb.NewThumbFromFile(source, file.Name)
if err != nil { if err != nil {
util.Log().Warning("生成缩略图时无法解析 [%s] 图像数据:%s", file.SourceName, err) util.Log().Warning("Cannot generate thumb because of failed to parse image %q: %s", file.SourceName, err)
return return
} }
@ -125,7 +125,7 @@ func (fs *FileSystem) GenerateThumbnail(ctx context.Context, file *model.File) {
} }
if err != nil { if err != nil {
util.Log().Warning("无法保存缩略图:%s", err) util.Log().Warning("Failed to save thumb: %s", err)
return return
} }

@ -69,7 +69,7 @@ func (fs *FileSystem) Upload(ctx context.Context, file *fsctx.FileStream) (err e
followUpErr := fs.Trigger(ctx, "AfterValidateFailed", file) followUpErr := fs.Trigger(ctx, "AfterValidateFailed", file)
// 失败后再失败... // 失败后再失败...
if followUpErr != nil { if followUpErr != nil {
util.Log().Debug("AfterValidateFailed 钩子执行失败,%s", followUpErr) util.Log().Debug("AfterValidateFailed hook execution failed: %s", followUpErr)
} }
return err return err
@ -113,13 +113,13 @@ func (fs *FileSystem) CancelUpload(ctx context.Context, path string, file fsctx.
// 客户端正常关闭,不执行操作 // 客户端正常关闭,不执行操作
default: default:
// 客户端取消上传,删除临时文件 // 客户端取消上传,删除临时文件
util.Log().Debug("客户端取消上传") util.Log().Debug("Client canceled upload.")
if fs.Hooks["AfterUploadCanceled"] == nil { if fs.Hooks["AfterUploadCanceled"] == nil {
return return
} }
err := fs.Trigger(ctx, "AfterUploadCanceled", file) err := fs.Trigger(ctx, "AfterUploadCanceled", file)
if err != nil { if err != nil {
util.Log().Debug("执行 AfterUploadCanceled 钩子出错,%s", err) util.Log().Debug("AfterUploadCanceled hook execution failed: %s", err)
} }
} }

Loading…
Cancel
Save