This commit is contained in:
2026-08-16 09:02:39 +08:00
parent c554152f4f
commit f7f6db8695
105 changed files with 2535 additions and 948 deletions
+10 -2
View File
@@ -103,6 +103,9 @@ func composeFiles(ctx context.Context, storage biz.FileStorage, names []string,
}
func (s *fileStorage) resolve(name string) (string, error) {
if name == "" {
return "", fmt.Errorf("key不能为空")
}
clean := filepath.Clean(strings.TrimPrefix(name, "/"))
if clean == "." || filepath.IsAbs(clean) || clean == ".." || strings.HasPrefix(clean, ".."+string(filepath.Separator)) {
return "", fmt.Errorf("invalid storage path")
@@ -146,7 +149,12 @@ func (s *fileStorage) Delete(ctx context.Context, name string) error {
if err != nil {
return err
}
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
// Match the compatible Local.DeleteFile behavior: a missing object is an error and the
// media DB record is retained when the physical file cannot be removed.
if _, err := os.Stat(path); os.IsNotExist(err) {
return fmt.Errorf("文件不存在")
}
if err := os.Remove(path); err != nil {
return err
}
return nil
@@ -170,7 +178,7 @@ func (s *fileStorage) DeletePrefix(ctx context.Context, prefix string) error {
return nil
}
func (s *fileStorage) List(ctx context.Context, prefix, cursor string, limit int) ([]*biz.StoredFile, string, bool, error) {
if limit < 1 || limit > 1000 {
if limit <= 0 {
limit = 100
}
root, err := s.resolve(strings.TrimSuffix(prefix, "/") + "/placeholder")