Files
geo/server/internal/shared/objectstorage/reloadable.go
T
root 7d8e82c69f 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>
2026-05-26 01:19:01 +08:00

110 lines
2.7 KiB
Go

package objectstorage
import (
"context"
"sync"
)
type ReloadableClient struct {
mu sync.RWMutex
current Client
}
func NewReloadableClient(current Client) *ReloadableClient {
return &ReloadableClient{current: current}
}
func (c *ReloadableClient) Update(next Client) {
if c == nil || next == nil {
return
}
c.mu.Lock()
defer c.mu.Unlock()
c.current = next
}
func (c *ReloadableClient) Validate() error {
return c.snapshot().Validate()
}
func (c *ReloadableClient) PutBytes(ctx context.Context, objectKey string, content []byte, contentType string) error {
return c.snapshot().PutBytes(ctx, objectKey, content, contentType)
}
func (c *ReloadableClient) GetBytes(ctx context.Context, objectKey string) ([]byte, error) {
return c.snapshot().GetBytes(ctx, objectKey)
}
func (c *ReloadableClient) Exists(ctx context.Context, objectKey string) (bool, error) {
return c.snapshot().Exists(ctx, objectKey)
}
func (c *ReloadableClient) Delete(ctx context.Context, objectKey string) error {
return c.snapshot().Delete(ctx, objectKey)
}
func (c *ReloadableClient) PublicURL(objectKey string) (string, error) {
return c.snapshot().PublicURL(objectKey)
}
func (c *ReloadableClient) DownloadURL(objectKey string) (string, error) {
return c.snapshot().DownloadURL(objectKey)
}
func (c *ReloadableClient) List(ctx context.Context, in ListInput) (*ListResult, error) {
client := c.snapshot()
management, ok := client.(ManagementClient)
if !ok {
return nil, ErrNotConfigured
}
return management.List(ctx, in)
}
func (c *ReloadableClient) Stat(ctx context.Context, objectKey string) (*ObjectInfo, error) {
client := c.snapshot()
management, ok := client.(ManagementClient)
if !ok {
return nil, ErrNotConfigured
}
return management.Stat(ctx, objectKey)
}
func (c *ReloadableClient) Copy(ctx context.Context, sourceKey, destinationKey string) error {
client := c.snapshot()
management, ok := client.(ManagementClient)
if !ok {
return ErrNotConfigured
}
return management.Copy(ctx, sourceKey, destinationKey)
}
func (c *ReloadableClient) Usage(ctx context.Context) (*UsageInfo, error) {
client := c.snapshot()
usageClient, ok := client.(UsageClient)
if !ok {
return nil, ErrUsageUnsupported
}
return usageClient.Usage(ctx)
}
func (c *ReloadableClient) PublicReadableURL(objectKey string) (string, error) {
client := c.snapshot()
publicClient, ok := client.(PublicReadableClient)
if !ok {
return "", ErrObjectNotPublic
}
return publicClient.PublicReadableURL(objectKey)
}
func (c *ReloadableClient) snapshot() Client {
if c == nil {
return disabledClient{reason: "object storage client is nil"}
}
c.mu.RLock()
defer c.mu.RUnlock()
if c.current == nil {
return disabledClient{reason: "object storage client is not initialized"}
}
return c.current
}