filedata

package
v0.2.51 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxFileSize = 4 * 1024 * 1024 // 4MB
	AvatarPath  = "avatars"
)

Variables

This section is empty.

Functions

func CheckImageType

func CheckImageType(filename string) (string, error)

CheckImageType returns the image MIME type for supported extensions.

func CountDailyUploads added in v0.1.1

func CountDailyUploads(userId uint64) int64

CountDailyUploads returns the number of files uploaded by a user today.

func CountUserUploadsInTimeRange added in v0.0.6

func CountUserUploadsInTimeRange(userId uint64, startTime, endTime time.Time) int64

CountUserUploadsInTimeRange counts uploads for a user within a time range.

func CountUserUploadsToday added in v0.0.6

func CountUserUploadsToday(userId uint64) int64

CountUserUploadsToday counts uploads for a user today.

Types

type AvatarUpload added in v0.2.10

type AvatarUpload struct {
	Filename string
	Data     []byte
}

type Entity

type Entity struct {
	Id     uint64 `gorm:"primaryKey;column:id;autoIncrement;not null;" json:"id"`          // 主键
	Name   string `gorm:"column:name;uniqueIndex;type:varchar(256);not null;" json:"name"` // 添加唯一索引
	Type   string `gorm:"column:assert_type;index;type:varchar(64);not null;" json:"type"` //
	Data   []byte `gorm:"column:content;type:BLOB;" json:"data"`                           // 内容
	UserId uint64 ``                                                                       //
	/* 126-byte string literal not displayed */
	CreatedAt time.Time `gorm:"column:created_at;index;autoCreateTime;<-:create;index:idx_file_data_user_created,priority:2;" json:"createdAt"` //
	UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime;" json:"updatedAt"`
}

func GetByName

func GetByName(name string) (entity Entity)

func GetFileByName

func GetFileByName(name string) (*Entity, error)

func SaveAvatar

func SaveAvatar(userId uint64, fileData []byte, filename string) (*Entity, error)

SaveAvatar stores an uploaded avatar file.

func SaveAvatarSet added in v0.2.10

func SaveAvatarSet(userId uint64, uploads []AvatarUpload) ([]*Entity, error)

func SaveFile

func SaveFile(userId uint64, name string, fileType string, data []byte) (*Entity, error)

func SaveFileFromUpload

func SaveFileFromUpload(userId uint64, fileData []byte, filename string, customPath string) (*Entity, error)

func (*Entity) GetAccessPath added in v0.0.6

func (itself *Entity) GetAccessPath() string

func (*Entity) TableName

func (itself *Entity) TableName() string

type FileResource added in v0.2.46

type FileResource struct {
	Id        uint64    `json:"id"`
	Name      string    `json:"name"`
	Type      string    `json:"type"`
	Size      int64     `json:"size"`
	UserId    uint64    `json:"userId"`
	CreatedAt time.Time `json:"createdAt"`
	URL       string    `json:"url"`
	Data      []byte    `json:"-"`
}

func (FileResource) GetAccessPath added in v0.2.46

func (itself FileResource) GetAccessPath() string

type FileResourcePageResult added in v0.2.46

type FileResourcePageResult struct {
	List     []FileResource
	Page     int
	PageSize int
	MaxId    int64
}

func FileResourcePage added in v0.2.46

func FileResourcePage(page, pageSize int) FileResourcePageResult

Jump to

Keyboard shortcuts

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