You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
659 B
30 lines
659 B
package filesystem
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// GenericBeforeUpload 通用上传前处理钩子,包含数据库操作
|
|
func GenericBeforeUpload(ctx context.Context, fs *FileSystem, file FileData) error {
|
|
// 验证单文件尺寸
|
|
if !fs.ValidateFileSize(ctx, file.GetSize()) {
|
|
return FileSizeTooBigError
|
|
}
|
|
|
|
// 验证文件名
|
|
if !fs.ValidateLegalName(ctx, file.GetFileName()) {
|
|
return IlegalObjectNameError
|
|
}
|
|
|
|
// 验证扩展名
|
|
if !fs.ValidateExtension(ctx, file.GetFileName()) {
|
|
return FileExtensionNotAllowedError
|
|
}
|
|
|
|
// 验证并扣除容量
|
|
if !fs.ValidateCapacity(ctx, file.GetSize()) {
|
|
return InsufficientCapacityError
|
|
}
|
|
return nil
|
|
}
|