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.
23 lines
554 B
23 lines
554 B
5 years ago
|
package filesystem
|
||
|
|
||
|
import "errors"
|
||
|
|
||
|
// GenericBeforeUpload 通用上传前处理钩子,包含数据库操作
|
||
|
func GenericBeforeUpload(fs *FileSystem, file FileData) error {
|
||
|
// 验证单文件尺寸
|
||
|
if !fs.ValidateFileSize(file.GetSize()) {
|
||
|
return errors.New("单个文件尺寸太大")
|
||
|
}
|
||
|
|
||
|
// 验证并扣除容量
|
||
|
if !fs.ValidateCapacity(file.GetSize()) {
|
||
|
return errors.New("容量空间不足")
|
||
|
}
|
||
|
|
||
|
// 验证扩展名
|
||
|
if !fs.ValidateExtension(file.GetFileName()) {
|
||
|
return errors.New("不允许上传此类型的文件")
|
||
|
}
|
||
|
return nil
|
||
|
}
|