xfile

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: BSD-3-Clause-Clear Imports: 4 Imported by: 0

Documentation

Overview

自建文件管理服务

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(f *File) (bool, error)

存储文件信息 其中,Md5、SHA1、FilePath、Size四项不允许为空

返回值中,bool类型的是否存在【存在的话将不会再次存储】 PS: 若返回已存在的话,源文件可直接进行删除,而传入值f则会被替换为已存在的文件详情信息

func Regedit

func Regedit(c *Config)

入口配置

Types

type Config

type Config struct {
	DB           *gorm.DB
	FileName     string
	FileDiffName string
}

配置项

type Diff

type Diff struct {
	Id        uint64 `gorm:"column:id;primaryKey;type:INT UNSIGNED;not null;autoIncrement" json:"id" form:"id"` // 自增ID
	Fid1      uint   `gorm:"column:fid1;type:INT UNSIGNED" json:"fid1" form:"fid1"`                             //文件1的ID
	Fid2      uint   `gorm:"column:fid2;type:INT UNSIGNED" json:"fid2" form:"fid2"`                             //文件2的ID
	AhashDiff int    `gorm:"column:ahash_diff;type:INT UNSIGNED" json:"ahash_diff" form:"ahash_diff"`           //a hash的差别
	DhashDiff int    `gorm:"column:dhash_diff;type:INT UNSIGNED" json:"dhash_diff" form:"dhash_diff"`           //d hash的差别
	PhashDiff int    `gorm:"column:phash_diff;type:INT UNSIGNED" json:"phash_diff" form:"phash_diff"`           //p hash的差别
	IsOver    uint8  `gorm:"column:is_over;type:TINYINT UNSIGNED" json:"is_over" form:"is_over"`                //是否已处理
	CreatedAt string `gorm:"column:created_at;type:DATETIME" json:"created_at" form:"created_at"`               //添加时间
	UpdatedAt string `gorm:"column:updated_at;type:DATETIME" json:"updated_at" form:"updated_at"`               //处理时间
}

文件hash比较表

func (*Diff) TableName

func (c *Diff) TableName() string

获取表名

type File

type File struct {
	Id          uint   `gorm:"column:id;primaryKey;type:INT UNSIGNED;not null;autoIncrement" json:"id" form:"id"` // 自增ID
	Md5         string `gorm:"column:md5;type:CHAR(32);index:search_key" json:"md5" form:"md5"`                   //文件MD5签名
	Sha1        string `gorm:"column:sha1;type:VARCHAR(100);index:search_key" json:"sha1" form:"sha1"`            //文件SHA1签名
	Size        uint   `gorm:"column:size;type:INT UNSIGNED;index:search_key" json:"size" form:"size"`            //文件大小,单位:B
	FilePath    string `gorm:"column:file_path" json:"file_path" form:"file_path"`                                //图片存放位置
	QualityPath string `gorm:"column:quality_path" json:"quality_path" form:"quality_path"`                       //压缩后的图片存放位置,压缩质量暂定为10
	Thumb100    string `gorm:"column:thumb100" json:"thumb100" form:"thumb100"`                                   //100x100缩略图存放位置
	Thumb200    string `gorm:"column:thumb200" json:"thumb200" form:"thumb200"`                                   //200x200缩略图存放位置
	Width       uint   `gorm:"column:width;type:INT UNSIGNED" json:"width" form:"width"`                          //图片/视频宽度
	Height      uint   `gorm:"column:height;type:INT UNSIGNED" json:"height" form:"height"`                       //图片/视频高度
	Length      uint   `gorm:"column:length;type:INT UNSIGNED" json:"length" form:"length"`                       //视频/音频时间长度,单位:ms
	Ahash       uint64 `gorm:"column:ahash;type:BIGINT UNSIGNED" json:"ahash" form:"ahash"`                       //A-Hash
	Dhash       uint64 `gorm:"column:dhash;type:BIGINT UNSIGNED" json:"dhash" form:"dhash"`                       //D-Hash
	Phash       uint64 `gorm:"column:phash;type:BIGINT UNSIGNED" json:"phash" form:"phash"`                       //P-Hash
	HashId      uint   `gorm:"column:hash_id;type:INT UNSIGNED" json:"hash_id" form:"hash_id"`                    //替换图ID,存在此ID的不再进行比对计算,此值不为0则表示原图已删除,使用此ID定位的图来进行展示
	CreatedAt   string `gorm:"column:created_at;type:DATETIME" json:"created_at" form:"created_at"`
}

文件管理服务,支持文件上传、查看、打开统计 其中,图片文件额外包含格式转换,均转换为webp格式进行存储

func Find

func Find(id uint) (*File, error)

查询文件详情信息

	此方法会根据file表中的hash_id字段来获取上一级的文件信息,并进行覆盖

id	文件ID

func FindSearch

func FindSearch(md5, sha1 string, size uint) (*File, error)

获取已存在的文件标识

md5		文件的MD5签名
sha1	文件的SHA1签名
size	文件大小,单位:B

func (*File) TableName

func (c *File) TableName() string

获取表名

Jump to

Keyboard shortcuts

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