- PostgreSQL metadata overlay layer on top of existing S3 storage - 3 new tables: folders, files, share_links - Folder CRUD: create, get with children, tree, rename, delete (cascade) - File operations: upload to folder, move between folders - Share links: create with optional password/expiry/download limit, public access - S3 compensation on PG write failure - Existing 14 endpoints untouched
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package validators
|
|
|
|
import (
|
|
"rag/file-system/internal/api/requests"
|
|
"rag/file-system/internal/common"
|
|
"strings"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
type FolderValidator struct{}
|
|
|
|
func NewFolderValidator() *FolderValidator {
|
|
return &FolderValidator{}
|
|
}
|
|
|
|
func (v *FolderValidator) ValidateCreate(req *requests.CreateFolderRequest) error {
|
|
name := strings.TrimSpace(req.Name)
|
|
if name == "" {
|
|
return common.NewBusinessException("目录名称不能为空")
|
|
}
|
|
if utf8.RuneCountInString(name) > 255 {
|
|
return common.NewBusinessException("目录名称不能超过255个字符")
|
|
}
|
|
if strings.Contains(name, "/") || strings.Contains(name, "\\") {
|
|
return common.NewBusinessException("目录名称不能包含 / 或 \\")
|
|
}
|
|
req.Name = name
|
|
return nil
|
|
}
|
|
|
|
func (v *FolderValidator) ValidateRename(req *requests.RenameFolderRequest) error {
|
|
name := strings.TrimSpace(req.Name)
|
|
if name == "" {
|
|
return common.NewBusinessException("目录名称不能为空")
|
|
}
|
|
if utf8.RuneCountInString(name) > 255 {
|
|
return common.NewBusinessException("目录名称不能超过255个字符")
|
|
}
|
|
if strings.Contains(name, "/") || strings.Contains(name, "\\") {
|
|
return common.NewBusinessException("目录名称不能包含 / 或 \\")
|
|
}
|
|
req.Name = name
|
|
return nil
|
|
}
|