feat(ops): add object storage management and site-mapping CSV import/export

Ship the Ops backstage 对象存储 page (browse / upload / move / delete /
folder ops) backed by a new object-storage service + handler, with the
shared storage client extended with List/Stat/Copy/Usage/DownloadURL so
both MinIO and Aliyun providers cover the new surface. Add
ForcePathStyle to the object-storage config and treat r2/s3/custom_s3
as external providers so Cloudflare R2 and other S3-compatibles can
share the MinIO client path without spinning up the bundled MinIO.

Also add CSV import/export + template download to the site-domain
mappings page, raise gin MaxMultipartMemory to 8 MiB for the new
multipart endpoints, register Ops swagger routes, and extend the
descriptions-parity test to cover the ops router.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-26 01:19:01 +08:00
parent 5f6e9f11da
commit 7d8e82c69f
37 changed files with 5111 additions and 66 deletions
@@ -3,6 +3,7 @@ package objectstorage
import (
"fmt"
"net/url"
"path/filepath"
"strings"
"github.com/geo-platform/tenant-api/internal/shared/config"
@@ -65,6 +66,66 @@ func buildPublicURL(cfg config.ObjectStorageConfig, objectKey string, bucketInHo
return endpointURL.String(), nil
}
func DownloadContentDisposition(objectKey string) string {
name := strings.TrimSpace(filepath.Base(strings.TrimRight(objectKey, "/")))
if name == "" || name == "." || name == "/" || name == "\\" {
name = "object"
}
name = strings.Map(func(r rune) rune {
if r == '"' || r == '\\' || r == '\r' || r == '\n' {
return -1
}
return r
}, name)
if name == "" {
name = "object"
}
return fmt.Sprintf(
`attachment; filename="%s"; filename*=UTF-8''%s`,
asciiContentDispositionFileName(name),
url.PathEscape(name),
)
}
func downloadContentDisposition(objectKey string) string {
return DownloadContentDisposition(objectKey)
}
func asciiContentDispositionFileName(name string) string {
var builder strings.Builder
for _, r := range name {
if r < 0x20 || r >= 0x7f || r == '"' || r == '\\' {
continue
}
builder.WriteRune(r)
}
fallback := strings.TrimSpace(builder.String())
if fallback == "" || fallback == "." || fallback == ".." || strings.HasPrefix(fallback, ".") {
return "object" + safeASCIIExtension(name)
}
return fallback
}
func safeASCIIExtension(name string) string {
ext := filepath.Ext(name)
if ext == "" || ext == "." {
return ""
}
var builder strings.Builder
for _, r := range ext {
if r < 0x20 || r >= 0x7f || r == '"' || r == '\\' {
continue
}
builder.WriteRune(r)
}
ext = strings.TrimSpace(builder.String())
if !strings.HasPrefix(ext, ".") || ext == "." {
return ""
}
return ext
}
func parseURLWithScheme(raw string, defaultScheme string) (*url.URL, error) {
raw = strings.TrimSpace(raw)
if raw == "" {