attachment

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeInvalidNovelID apperr.Code = "attachment.invalid_novel_id"
	// CodeFileTooLarge 原图或处理后的图片超过文件体积限制。
	CodeFileTooLarge apperr.Code = "attachment.file_too_large"
	// CodeTooManyPixels 原图像素数超过解码限制。
	CodeTooManyPixels apperr.Code = "attachment.too_many_pixels"
	// CodeInvalidImage 图片格式不受支持、数据损坏或编码无效。
	CodeInvalidImage apperr.Code = "attachment.invalid_image"
)
View Source
const (
	MaxFileSize = 20 << 20
	MaxPixels   = 40_000_000
)

Variables

This section is empty.

Functions

func Handler

func Handler(store *Store) http.Handler

Types

type Image

type Image struct {
	ID       string    `json:"id"`
	Name     string    `json:"name"`
	Original ImageInfo `json:"original"`
	Standard ImageInfo `json:"standard"`
}

Image 同时是导入结果和本地 manifest,两个版本在导入后不再修改。

type ImageInfo

type ImageInfo struct {
	MIMEType string `json:"mime_type"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	Size     int    `json:"size"`
}

type Ref

type Ref struct {
	AttachmentID string  `json:"attachment_id"`
	Variant      Variant `json:"variant"`
}

Ref 是消息中持久化的图片引用,不包含文件路径或图片数据。

type Store

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

func NewStore

func NewStore(dir string) *Store

func (*Store) Delete

func (s *Store) Delete(novelID int64, id string) error

func (*Store) Get

func (s *Store) Get(novelID int64, id string) (Image, error)

func (*Store) Import

func (s *Store) Import(novelID int64, name string, src io.Reader) (Image, error)

Import 复制原图并生成标准版本;文件名仅用于展示,存储路径由后端生成。

func (*Store) Read

func (s *Store) Read(novelID int64, ref Ref) ([]byte, ImageInfo, error)

Read 返回指定版本的文件字节,由调用方在构造模型请求时编码为 Base64。

type Variant

type Variant string
const (
	Original Variant = "original"
	Standard Variant = "standard-v1"
)

Jump to

Keyboard shortcuts

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