Help us shape the future of Go! Take the 2026 Go Developer Survey

preview

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package preview 预览域服务:取件校验与预览生成/持久化的业务编排。

gen/handler/preview 是 HTTP 适配层(参数提取 + 错误→状态码映射), 闸门/过期/封禁/防爆破/密码/存储读取/预览生成/落库的业务事实全部收口于此。

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrShareNotFound 分享不存在/已过期/不可见(统一 404 语义)
	ErrShareNotFound = errors.New("share not found or expired")
	// ErrShareBlocked 分享被封禁或待审(走 errcode 管控语义)
	ErrShareBlocked = errors.New("share blocked")
	// ErrPasswordRequired 密码保护分享未通过密码校验(含防爆破锁定态)
	ErrPasswordRequired = errors.New("password required")
	// ErrLocked 密码错误次数过多,临时锁定
	ErrLocked = errors.New("too many attempts, temporarily locked")
	// ErrPreviewUnavailable 预览不可用(生成失败/存储不可达)
	ErrPreviewUnavailable = errors.New("preview unavailable")
	// ErrPreviewBusy 生成并发闸满(防 CPU/内存耗尽:图片解码与 ffmpeg 均为重活,
	// 攻击者跨 IP 并发预览未缓存的大图/视频可打满 CPU——限流按 IP 计数堵不住分布式)
	ErrPreviewBusy = errors.New("preview generation busy")
)

业务错误(HTTP 适配层据此映射状态码与文案,不泄露内部细节)。

Functions

This section is empty.

Types

type GetReq

type GetReq struct {
	Code     string
	UserID   *uint  // 登录态(nil = 匿名)
	ClientIP string // 可信代理解析后的取件方 IP(防爆破锁定键)
	Password string // 密码保护分享的取件密码
}

GetReq 预览获取请求。HTTP 关注点(取件码/密码/客户端 IP/登录态)由 适配层提取后传入;锁定、校验、生成、落库均为域内事实。

type LockedError

type LockedError struct{ Remain int }

LockedError 防爆破锁定态(携带剩余锁定秒数,供文案)

func (*LockedError) Error

func (e *LockedError) Error() string

type Service

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

Service 预览域服务。存储实例由 bootstrap 注入;nil 时预览生成不可用 (回归 2026-10-03:此前硬编码 data/uploads 路径基,与统一存储不一致)。

func NewService

func NewService(gormDB *gorm.DB, st storage.StorageInterface) *Service

NewService 构造预览域服务。

func (*Service) GetOrCreate

func (s *Service) GetOrCreate(ctx context.Context, req GetReq) (*model.FilePreview, error)

GetOrCreate 取预览:无则生成并持久化(get-or-create)。

Jump to

Keyboard shortcuts

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