staticcdn

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid        = errors.New("静态资源 CDN 配置不合法")
	ErrNotFound       = errors.New("静态资源 CDN 不存在")
	ErrConflict       = errors.New("静态资源 CDN 已存在")
	ErrBucketNotEmpty = errors.New("S3 Bucket 中仍有文件,请清空后再删除")
	ErrDeletePending  = errors.New("CloudFront 正在停用,请等待状态更新后再次确认删除")
)

Functions

This section is empty.

Types

type AWSCredentialProvider

type AWSCredentialProvider interface {
	Environment(context.Context, string) ([]string, error)
}

type CommandError

type CommandError struct {
	Message string
	Err     error
}

func (*CommandError) Error

func (e *CommandError) Error() string

func (*CommandError) Unwrap

func (e *CommandError) Unwrap() error

type Object

type Object struct {
	Key          string    `json:"key"`
	Size         int64     `json:"size"`
	ETag         string    `json:"etag"`
	LastModified time.Time `json:"last_modified"`
	CDNURL       string    `json:"cdn_url"`
}

type Resource

type Resource struct {
	ProjectKey      string    `json:"project_key"`
	EnvironmentKey  string    `json:"environment_key"`
	DisplayName     string    `json:"display_name"`
	BucketName      string    `json:"bucket_name"`
	Region          string    `json:"region"`
	CORSOrigins     []string  `json:"cors_origins"`
	DistributionID  string    `json:"distribution_id,omitempty"`
	DistributionARN string    `json:"distribution_arn,omitempty"`
	DomainName      string    `json:"domain_name,omitempty"`
	CDNURL          string    `json:"cdn_url,omitempty"`
	OACID           string    `json:"oac_id,omitempty"`
	Status          string    `json:"status"`
	LastError       string    `json:"last_error,omitempty"`
	CreatedBy       string    `json:"created_by"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(config *appconfig.Config, store Store, credentials AWSCredentialProvider) *Service

func (*Service) AuthorizeUpload

func (s *Service) AuthorizeUpload(ctx context.Context, project, environment, bucket, key string) (UploadAuthorization, error)

func (*Service) Create

func (s *Service) Create(ctx context.Context, input Resource, createdBy string) (Resource, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, project, environment, bucket string) (Resource, error)

func (*Service) DeleteObject

func (s *Service) DeleteObject(ctx context.Context, project, environment, bucket, key string) error

func (*Service) Invalidate

func (s *Service) Invalidate(ctx context.Context, project, environment, bucket string, paths []string) error

func (*Service) List

func (s *Service) List(ctx context.Context, project, environment string, refresh bool) ([]Resource, error)

func (*Service) Objects

func (s *Service) Objects(ctx context.Context, project, environment, bucket, prefix string) ([]Object, error)

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context, project, environment, bucket string) (Resource, error)

func (*Service) UploadObject

func (s *Service) UploadObject(ctx context.Context, project, environment, bucket, key, contentType string, body io.Reader) error

UploadObject provides a same-origin fallback when a browser cannot reach a presigned S3 URL because of a local network policy, extension, proxy, or transient CORS failure. The HTTP layer enforces the request size limit. A private temporary file is used because aws s3api put-object requires a file path for binary payloads; it is removed on every return path.

type Store

type Store interface {
	ListStaticCDNs(context.Context, string, string) ([]Resource, error)
	GetStaticCDN(context.Context, string, string, string) (Resource, error)
	SaveStaticCDN(context.Context, Resource) error
	DeleteStaticCDN(context.Context, string, string, string) error
}

type UploadAuthorization

type UploadAuthorization struct {
	Key       string    `json:"key"`
	Method    string    `json:"method"`
	UploadURL string    `json:"upload_url"`
	CDNURL    string    `json:"cdn_url"`
	ExpiresAt time.Time `json:"expires_at"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL