初始化2

This commit is contained in:
2026-07-10 17:33:33 +08:00
parent b51ee98afa
commit 94f6ecf901
59 changed files with 3893 additions and 980 deletions

View File

@@ -21,11 +21,13 @@ type UserStorageInfo struct {
PolicyID uint64 // 当前使用的策略ID(最高优先级)
PolicyName string
PolicyType string
TotalQuota int64 // 总配额(所有策略叠加)
UsedStorage int64 // 已用空间
UsedPercent float64
AccessMode string
Assignments []model.StorageAssignment // 所有关联的分配规则
TotalQuota int64 // 总配额(所有策略叠加)
UsedStorage int64 // 已用空间
UsedPercent float64
AccessMode string
MaxFileSize int64 // 单文件大小上限(字节), 0=不限制
ChunkThreshold int64 // 分片上传阈值(字节)
Assignments []model.StorageAssignment // 所有关联的分配规则
}
// ResolvePolicyID 确定用户上传时应使用的存储策略
@@ -97,9 +99,47 @@ func (s *StorageAssignService) GetUserStorageInfo(userID uint64) (*UserStorageIn
info.UsedPercent = float64(info.UsedStorage) / float64(info.TotalQuota) * 100
}
// 根据角色确定文件大小限制
info.MaxFileSize, info.ChunkThreshold = s.getFileSizeLimit(userID)
return info, nil
}
// getFileSizeLimit 根据用户角色返回单文件大小限制和分片阈值
// 返回: maxFileSize(字节), chunkThreshold(字节)
func (s *StorageAssignService) getFileSizeLimit(userID uint64) (int64, int64) {
// 获取用户角色
var userRoles []model.UserRole
config.DB.Where("user_id = ?", userID).Find(&userRoles)
roleIDs := make([]uint64, 0, len(userRoles))
for _, ur := range userRoles {
roleIDs = append(roleIDs, ur.RoleID)
}
// 检查角色名称确定限制
var roles []model.Role
if len(roleIDs) > 0 {
config.DB.Where("id IN ?", roleIDs).Find(&roles)
}
for _, r := range roles {
switch r.Name {
case "admin":
return 0, 100 * 1024 * 1024 // 不限大小, 100MB分片
case "staff":
return 500 * 1024 * 1024, 50 * 1024 * 1024 // 500MB上限, 50MB分片
case "user":
return 100 * 1024 * 1024, 10 * 1024 * 1024 // 100MB上限, 10MB分片
case "guest":
return 0, 0 // 不允许上传
}
}
// 默认
return 100 * 1024 * 1024, 10 * 1024 * 1024
}
// getUserAssignments 获取用户的所有存储分配(去重+排序)
func (s *StorageAssignService) getUserAssignments(userID uint64) []model.StorageAssignment {
var all []model.StorageAssignment