xfile

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause-Clear Imports: 17 Imported by: 0

Documentation

Overview

自建文件管理服务

Index

Constants

View Source
const (
	ExtNone     = iota // 未知文件类型
	ExtImage           // 图片类型
	ExtDocument        // 文档类型
	ExtAudio           // 音频类型
	ExtVideo           // 视频类型
	ExtConfig          // 配置文件
	ExtZip             // 压缩包
)

Variables

This section is empty.

Functions

func Append added in v0.3.7

func Append(file_path string, cont []byte) error

写入文件

file_path	文件路径
cont		文件内容

func AppendString added in v0.3.7

func AppendString(file_path, cont string) error

写入文件(字符串)

file_path	文件路径
cont		文件内容

func CheckType added in v0.1.11

func CheckType(ext string) int

根据后缀判断文件类型

ext	文件后缀,使用path.Ext(f.Filename)获取到的文件后缀

func Create

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

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

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

func GetAppPath added in v0.2.71

func GetAppPath(name ...string) (string, error)

获取程序的配置目录

name	子级目录名称,多级可以直接传入/,也可以传入多个参数

func HashDiff added in v0.0.18

func HashDiff(fid1, fid2 uint) error

针对文件1和文件2进行hash比较,并将值存储到hash比较表 `Diff` 中

fid1	文件1的ID
fid2	文件2的ID

func OpenImage added in v0.1.7

func OpenImage(file string) (image.Image, error)

打开图片文件

func Regedit

func Regedit(c *Config)

入口配置

func Write added in v0.1.23

func Write(file_path string, cont []byte) error

写入文件

file_path	文件路径
cont		文件内容

func WriteString added in v0.1.23

func WriteString(file_path, cont string) error

写入文件(字符串)

file_path	文件路径
cont		文件内容

Types

type Config

type Config struct {
	DB           *gorm.DB
	FileName     string // file表存储表名
	FileDiffName string // diff表存储表名
}

配置项

type Diff

type Diff struct {
	Id        uint64 `gorm:"column:id;primaryKey;not null;autoIncrement" json:"id" form:"id"`                              // 自增ID
	Fid1      uint   `gorm:"column:fid1;comment:文件1的ID" json:"fid1" form:"fid1"`                                           //文件1的ID
	Fid2      uint   `gorm:"column:fid2;comment:文件2的ID" json:"fid2" form:"fid2"`                                           //文件2的ID
	AhashDiff int    `gorm:"column:ahash_diff;comment:a hash的差别" json:"ahash_diff" form:"ahash_diff"`                      //a hash的差别
	DhashDiff int    `gorm:"column:dhash_diff;comment:d hash的差别" json:"dhash_diff" form:"dhash_diff"`                      //d hash的差别
	PhashDiff int    `gorm:"column:phash_diff;comment:p hash的差别" json:"phash_diff" form:"phash_diff"`                      //p hash的差别
	IsOver    uint8  `gorm:"column:is_over;type:TINYINT UNSIGNED;comment:是否已处理 0-未处理 1-已处理" json:"is_over" form:"is_over"` //是否已处理
	CreatedAt string `gorm:"column:created_at;type:DATETIME;comment:添加时间" json:"created_at" form:"created_at"`             //添加时间
	UpdatedAt string `gorm:"column:updated_at;type:DATETIME;comment:处理时间" 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;not null;autoIncrement" json:"id" form:"id"`                         // 自增ID
	Md5         string `gorm:"column:md5;type:CHAR(32);index:search_key;comment:文件MD5签名" json:"md5" form:"md5"`         //文件MD5签名
	Sha1        string `gorm:"column:sha1;type:VARCHAR(100);index:search_key;comment:文件SHA1签名" json:"sha1" form:"sha1"` //文件SHA1签名
	Size        uint   `gorm:"column:size;index:search_key;comment:文件大小,单位:B" json:"size" form:"size"`                  //文件大小,单位:B
	FilePath    string `gorm:"column:file_path;type:VARCHAR(200);comment:图片存放位置" json:"file_path" form:"file_path"`     //图片存放位置
	QualityPath string ``                                                                                               //压缩后的图片存放位置,压缩质量暂定为10
	/* 149-byte string literal not displayed */
	Thumb100 string `gorm:"column:thumb100;type:VARCHAR(200);comment:100x100缩略图存放位置" json:"thumb100" form:"thumb100"` //100x100缩略图存放位置
	Thumb200 string `gorm:"column:thumb200;type:VARCHAR(200);comment:200x200缩略图存放位置" json:"thumb200" form:"thumb200"` //200x200缩略图存放位置
	Width    uint   `gorm:"column:width;comment:图片/视频宽度" json:"width" form:"width"`                                   //图片/视频宽度
	Height   uint   `gorm:"column:height;comment:图片/视频高度" json:"height" form:"height"`                                //图片/视频高度
	Length   uint   `gorm:"column:length;comment:视频/音频时间长度,单位:ms" json:"length" form:"length"`                        //视频/音频时间长度,单位:ms
	Ahash    uint64 `gorm:"column:ahash;type:BIGINT UNSIGNED;comment:A-Hash" json:"ahash" form:"ahash"`               //A-Hash
	Dhash    uint64 `gorm:"column:dhash;type:BIGINT UNSIGNED;comment:D-Hash" json:"dhash" form:"dhash"`               //D-Hash
	Phash    uint64 `gorm:"column:phash;type:BIGINT UNSIGNED;comment:P-Hash" json:"phash" form:"phash"`               //P-Hash
	HashId   uint   ``                                                                                                //替换图ID,存在此ID的不再进行比对计算,此值不为0则表示原图已删除,使用此ID定位的图来进行展示
	/* 193-byte string literal not displayed */
	CreatedAt string `gorm:"column:created_at;type:DATETIME;comment:创建时间" 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