model

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileNotFound     = &errors.DomainError{Code: "FILE_NOT_FOUND", Message: "文件不存在"}
	ErrFileNameEmpty    = &errors.DomainError{Code: "FILE_NAME_EMPTY", Message: "文件名不能为空"}
	ErrFileIDEmpty      = &errors.DomainError{Code: "FILE_NAME_EMPTY", Message: "文件ID不能为空"}
	ErrFilePathEmpty    = &errors.DomainError{Code: "FILE_PATH_EMPTY", Message: "文件路径不能为空"}
	ErrFileQueryFailed  = &errors.DomainError{Code: "FILE_QUERY_FAILED", Message: "文件查询失败"}
	ErrFileNameExists   = &errors.DomainError{Code: "FILE_NAME_EXISTS", Message: "已存在同名文件"}
	ErrFileDeleteFailed = &errors.DomainError{Code: "FILE_DELETE_FAILED", Message: "文件删除失败"}
)

文件管理相关错误

View Source
var (
	// ErrFileUploadFailed 基础上传错误
	ErrFileUploadFailed = &errors.DomainError{Code: "FILE_UPLOAD_FAILED", Message: "文件上传失败"}
	ErrFileCheckFailed  = &errors.DomainError{Code: "FILE_CHECK_FAILED", Message: "文件检测失败"}

	// ErrMultipartInitFailed 分片上传相关错误
	ErrMultipartInitFailed     = &errors.DomainError{Code: "MULTIPART_INIT_FAILED", Message: "分片上传初始化失败"}
	ErrMultipartUploadFailed   = &errors.DomainError{Code: "MULTIPART_UPLOAD_FAILED", Message: "分片上传失败"}
	ErrMultipartCompleteFailed = &errors.DomainError{Code: "MULTIPART_COMPLETE_FAILED", Message: "分片上传完成失败"}
	ErrMultipartStatusFailed   = &errors.DomainError{Code: "MULTIPART_STATUS_FAILED", Message: "分片上传状态查询失败"}
	ErrMultipartReadFailed     = &errors.DomainError{Code: "MULTIPART_READ_FAILED", Message: "文件分片读取失败"}

	// ErrFileInvalidType 文件类型和限制相关错误
	ErrFileInvalidType  = &errors.DomainError{Code: "FILE_INVALID_TYPE", Message: "不支持的文件类型"}
	ErrFileSizeExceeded = &errors.DomainError{Code: "FILE_SIZE_EXCEEDED", Message: "文件大小超出限制"}

	// ErrFileRecordSaveFailed 存储相关错误
	ErrFileRecordSaveFailed = &errors.DomainError{Code: "FILE_RECORD_SAVE_FAILED", Message: "文件记录保存失败"}
)

文件上传相关错误

Functions

This section is empty.

Types

type File

type File struct {
	ID        uint64    `json:"id"`
	MediaType MediaType `json:"media_type"`
	Name      FileName  `json:"name"`
	NameIndex string    `json:"name_index"`
	Path      string    `json:"path"`
	Size      uint64    `json:"size"`
	Ext       string    `json:"ext"`
	MimeType  string    `json:"mime_type"`
	Status    uint8     `json:"status"`
	CreatedAt time.Time `json:"created_at"`
}

File 文件领域模型

func FileFromModel

func FileFromModel(ctx context.Context, m file.File) *File

func FileListFromModel

func FileListFromModel(ctx context.Context, files []file.File) []File

func NewFile

func NewFile(ctx context.Context, name, ext, path, mimeType string, size uint64) *File

NewFile 创建文件

func (*File) ToModel

func (f *File) ToModel() *file.File

ToModel 转换为数据模型

func (*File) Validate

func (f *File) Validate() error

type FileName

type FileName string

FileName 文件名领域值对象

func (FileName) NameIndex

func (f FileName) NameIndex() string

NameIndex 生成文件名索引

func (FileName) String

func (f FileName) String() string

func (FileName) Validate

func (f FileName) Validate() error

type MediaType

type MediaType uint8

MediaType 文件媒体类型

const (
	MediaTypeImage      MediaType = iota + 1 // 图片
	MediaTypeVideo                           // 视频
	MediaTypeAudio                           // 音频
	MediaTypeDocument                        // 文档
	MediaTypeCompressed                      // 压缩文件
)

func DetermineMediaType

func DetermineMediaType(ext, mimeType string) MediaType

DetermineMediaType 根据扩展名和MIME类型确定媒体类型

func (MediaType) String

func (t MediaType) String() string

String 获取媒体类型描述

func (MediaType) ToInt

func (t MediaType) ToInt() uint8

ToInt 转换为整数

type MultipartUpload

type MultipartUpload struct {
	ID        uint64    `json:"id"`
	FileName  string    `json:"file_name"`
	Path      string    `json:"path"`
	Size      uint64    `json:"size"`
	MimeType  string    `json:"mime_type"`
	Ext       string    `json:"ext"`
	UploadID  string    `json:"upload_id"`
	Status    uint8     `json:"status"` // 1-进行中 2-已完成 3-已取消
	Parts     []*Part   `json:"parts"`
	CreatedAt time.Time `json:"created_at"`
}

MultipartUpload 分片上传信息

func MultipartUploadFormModel

func MultipartUploadFormModel(mu *file.MultipartUpload) *MultipartUpload

func NewMultipartUpload

func NewMultipartUpload(fileName, path string, size uint64, mimeType, ext, uploadId string) *MultipartUpload

NewMultipartUpload 创建分片上传

func (*MultipartUpload) Abort

func (m *MultipartUpload) Abort()

Abort 取消上传

func (*MultipartUpload) AddPart

func (m *MultipartUpload) AddPart(partNumber int, etag string, size int64)

AddPart 添加分片

func (*MultipartUpload) Complete

func (m *MultipartUpload) Complete()

Complete 完成上传

type Part

type Part struct {
	PartNumber int
	ETag       string
	Size       int64
}

Part 分片信息

func PartListFromStoragePart

func PartListFromStoragePart(parts []fs.MultipartPart) []Part

Jump to

Keyboard shortcuts

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