dao

package module
v0.0.0-...-094e1e4 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 8 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpectedDir = errors.New("expected dir")
)

Functions

func DatabaseNewFunc

func DatabaseNewFunc(dataSourceName string, newDB func(dataSourceName string) (Database, error)) func() (Database, error)

func StorageNewFunc

func StorageNewFunc(root string, newStorage func(root string) (Storage, error)) func() (Storage, error)

Types

type Branch

type Branch struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	CommitId    uint64 `json:"commitId"`
	Size        uint64 `json:"size"`
	Count       uint64 `json:"count"`
}

func NewBranch

func NewBranch(name string, commit Commit, dir Dir) Branch

func (Branch) GetCommitId

func (b Branch) GetCommitId() uint64

func (Branch) GetCount

func (b Branch) GetCount() uint64

func (Branch) GetDescription

func (b Branch) GetDescription() string

func (Branch) GetName

func (b Branch) GetName() string

func (Branch) GetSize

func (b Branch) GetSize() uint64

type Commit

type Commit struct {
	Id uint64

	Hash string
	// contains filtered or unexported fields
}

func NewCommit

func NewCommit(dir Dir, branchName string, message string) Commit

func (*Commit) BranchName

func (c *Commit) BranchName() string

func (*Commit) CreateTime

func (c *Commit) CreateTime() uint64

type DCIMDriver

type DCIMDriver struct {
	Id          uint64 `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Typ         string `json:"type"`

	// DCIM
	MetadataList []Metadata `json:"metadataList"`
}

type DCIMSearchSuffix

type DCIMSearchSuffix struct {
	Suffix string `json:"suffix"`
	Count  uint64 `json:"count"`
}

type DCIMSearchType

type DCIMSearchType struct {
	Type    string `json:"type"`
	SubType string `json:"subType"`
	Count   uint64 `json:"count"`
}

type Database

type Database interface {
	IsSqlite() bool
	DataSourceName() string
	Size() (int64, error)
	Remove() error
	Create() error
	Close() error

	ResetBranch(ctx context.Context, branchName string) error
	NewBranch(ctx context.Context, branchName string) (exist bool, err error)
	DeleteBranch(ctx context.Context, branchName string) error
	BranchInfo(ctx context.Context, branchName string) (branch Branch, err error)
	BranchList(ctx context.Context) (branches []IBranch, err error)

	WriteCommit(ctx context.Context, commit *Commit) error

	WriteDir(ctx context.Context, dirItems []DirItem) (dir Dir, err error)
	RemoveDirItem(ctx context.Context, branchName string, splitPath []string) (commit Commit, branch Branch, err error)

	WriteFile(ctx context.Context, file File) error
	UpsertDirItem(ctx context.Context, branchName string, splitPath []string, item DirItem) (commit Commit, branch Branch, err error)
	UpsertDirItems(ctx context.Context, branchName string, splitPath []string, items []DirItem) (commit Commit, branch Branch, err error)
	GetFileHashMode(ctx context.Context, branchName string, splitPath []string) (hash string, mode os.FileMode, err error)

	List(ctx context.Context, branchName string, splitPath []string) (dirItems []DirItem, err error)
	ListByHash(ctx context.Context, hash string) (dirItems []DirItem, err error)

	Open(ctx context.Context, branchName string, splitPath []string) (hash string, mode os.FileMode, dirItems []DirItem, err error)
	Open2(ctx context.Context, branchName string, splitPath []string) (dirItem DirItem, dirItems []DirItem, err error)

	FileCount(ctx context.Context) (int, error)
	DirCount(ctx context.Context) (int, error)
	DirItemCount(ctx context.Context) (int, error)
	BranchCount(ctx context.Context) (int, error)

	InsertDevice(ctx context.Context, id string, name string, os string, userAgent string, hostname string) error
	DeleteDevice(ctx context.Context, deviceId string) error
	ListDevice(ctx context.Context) (devices []Device, err error)

	InsertDriver(ctx context.Context, driverName string, description string) (exist bool, err error)
	InsertDriverBaiduPhoto(ctx context.Context, driverName string, description string, accessToken string, refreshToken string) (exist bool, err error)
	InsertDriverLocalFile(ctx context.Context, driverName string, description string, deviceId string, srcPath string, ignores string, encoder string) (exist bool, err error)
	UpdateDriverSync(ctx context.Context, driverId uint64, sync bool, h int64, m int64) error
	UpdateDriverLocalFile(ctx context.Context, driverId uint64, srcPath, ignores, encoder string) error
	ResetDriver(ctx context.Context, driverId uint64) error
	DeleteDriver(ctx context.Context, driverId uint64) error
	ListDriver(ctx context.Context) (drivers []Driver, err error)
	GetDriver(ctx context.Context, driverId uint64) (driver Driver, err error)
	GetDriverToken(ctx context.Context, driverId uint64) (driver Driver, err error)
	GetDriverSync(ctx context.Context, driverId uint64) (driver Driver, err error)
	ListCloudDriverSync(ctx context.Context) (drivers []Driver, err error)
	ListLocalFileDriver(ctx context.Context, deviceId string) (drivers []Driver, err error)
	GetDriverLocalFile(ctx context.Context, driverId uint64) (driver *Driver, err error)

	GetDriverDirCalculatedInfo(ctx context.Context, driverId uint64, filePath []string) (info DirCalculatedInfo, err error)

	InsertFile(ctx context.Context, hash string, size uint64) error
	InsertFileMd5(ctx context.Context, hash string, hashMd5 string) error
	ListFileMd5(ctx context.Context, md5List []string) (m map[string]string, err error)
	SumFileSize(ctx context.Context) (size uint64, err error)

	UpsertDriverFile(ctx context.Context, f DriverFile, mkdir bool) error
	UpsertDriverFiles(ctx context.Context, files []DriverFile) error
	ListDriverFile(ctx context.Context, driverId uint64, filePath []string) (files []DriverFile, err error)
	GetDriverFile(ctx context.Context, driverId uint64, filePath []string) (file DriverFile, err error)
	ListDriverFileByHash(ctx context.Context, hash string) (files []DriverFile, err error)
	CheckExists(ctx context.Context, driverId uint64, dirPath []string, checks []DirItemCheck, hashList []string) error

	InsertHeightWidth(ctx context.Context, hash string, hw HeightWidth) error
	InsertNullVideoMetadata(ctx context.Context, hash string) (exist bool, err error)
	InsertVideoMetadata(ctx context.Context, hash string, m VideoMetadata) (exist bool, err error)

	InsertDCIMMetadataTime(ctx context.Context, hash string, t int64) (exist bool, err error)
	UpsertDCIMMetadataTime(ctx context.Context, hash string, t int64) error
	GetEarliestCrated(ctx context.Context, hash string) (t int64, err error)
	ListMetadataTime(ctx context.Context) (list []Metadata, err error)
	ListDCIMDriver(ctx context.Context) (drivers []DCIMDriver, err error)
	ListDCIMMediaType(ctx context.Context) (m map[string][]Metadata, err error)
	ListDCIMLocation(ctx context.Context) (list []Metadata, err error)
	ListDCIMSearchType(ctx context.Context) (list []DCIMSearchType, err error)
	ListDCIMSearchSuffix(ctx context.Context) (list []DCIMSearchSuffix, err error)
	SearchDCIM(ctx context.Context, typeList []string, suffixList []string) (list []Metadata, err error)

	InsertNullExif(ctx context.Context, hash string) (exist bool, err error)
	InsertExif(ctx context.Context, hash string, e Exif) (exist bool, err error)
	ListExpectExif(ctx context.Context) (hashList []string, err error)
	ListExpectExifCb(ctx context.Context, cb func(hash string)) (err error)
	ListExif(ctx context.Context) (exifMap map[string]Exif, err error)
	ListMetadata(ctx context.Context) (list []Metadata, err error)
	GetMetadata(ctx context.Context, hash string) (Metadata, error)

	ListFile(ctx context.Context) (hashList []string, err error)

	InsertFileType(ctx context.Context, hash string, t FileType) (exist bool, err error)
	UpsertFileType(ctx context.Context, hash string, t FileType) error
	ListExpectFileType(ctx context.Context) (hashList []string, err error)
	ListFileHash(ctx context.Context) (hashList []string, err error)
	GetFileType(ctx context.Context, hash string) (fileType FileType, err error)

	ListLivePhotoAll(ctx context.Context) (hashList []string, err error)
	ListLivePhotoNew(ctx context.Context) (hashList []string, err error)
	SetLivpForMovAndHeicOrJpgInDirPath(ctx context.Context, driverId uint64, filePath []string) (err error)
	SetLivpForMovAndHeicOrJpgInDriver(ctx context.Context, driverId uint64) (err error)
	SetLivpForMovAndHeicOrJpgAll(ctx context.Context) error
	UpsertLivePhoto(ctx context.Context, movHash string, heicHash string, jpgHash string, livpHash string) error
	GetLivePhotoByLivp(ctx context.Context, livpHash string) (string, string, error)
}

type Device

type Device struct {
	Id        string `json:"id"`
	Name      string `json:"name"`
	OS        string `json:"os"`
	UserAgent string `json:"userAgent"`
	Hostname  string `json:"hostname"`
}

type Dir

type Dir struct {
	FileOrDir
	// contains filtered or unexported fields
}

func NewDir

func NewDir(hash string, size uint64, count uint64, totalCount uint64) Dir

func NewDirFromDirItem

func NewDirFromDirItem(item IDirItem) (Dir, error)

func (*Dir) Cal

func (dir *Dir) Cal(dirItems []DirItem)

func (Dir) Count

func (dir Dir) Count() uint64

func (Dir) TotalCount

func (dir Dir) TotalCount() uint64

type DirCalculatedInfo

type DirCalculatedInfo struct {
	FileSize          uint64 `json:"fileSize"`
	FileCount         uint64 `json:"fileCount"`
	DistinctFileSize  uint64 `json:"distinctFileSize"`
	DistinctFileCount uint64 `json:"distinctFileCount"`
	DirCount          uint64 `json:"dirCount"`
}

type DirItem

type DirItem struct {
	Hash       string `json:"hash"`
	Name       string `json:"name"`
	Mode       uint64 `json:"mode"`
	Size       uint64 `json:"size"`
	Count      uint64 `json:"count"`
	TotalCount uint64 `json:"totalCount"`
	CreateTime uint64 `json:"createTime"` // linux does not support it.
	ModifyTime uint64 `json:"modifyTime"`
	ChangeTime uint64 `json:"changeTime"` // windows does not support it.
	AccessTime uint64 `json:"accessTime"`
}

https://zhuanlan.zhihu.com/p/343682839

func NewDirItem

func NewDirItem(fileOrDir IFileOrDir, name string, mode uint64, createTime uint64, modifyTime uint64, changeTime uint64, accessTime uint64) DirItem

func (DirItem) GetAccessTime

func (d DirItem) GetAccessTime() uint64

func (DirItem) GetChangeTime

func (d DirItem) GetChangeTime() uint64

func (DirItem) GetCount

func (d DirItem) GetCount() uint64

func (DirItem) GetCreateTime

func (d DirItem) GetCreateTime() uint64

func (DirItem) GetHash

func (d DirItem) GetHash() string

func (DirItem) GetMode

func (d DirItem) GetMode() uint64

func (DirItem) GetModifyTime

func (d DirItem) GetModifyTime() uint64

func (DirItem) GetName

func (d DirItem) GetName() string

func (DirItem) GetSize

func (d DirItem) GetSize() uint64

func (DirItem) GetTotalCount

func (d DirItem) GetTotalCount() uint64

type DirItemCheck

type DirItemCheck struct {
	Name       string
	Size       uint64
	ModifyTime uint64
}

type DirItemOpened

type DirItemOpened struct {
	DirItem
	DirItems        []DirItem `json:"dirItems"`
	Content         []byte    `json:"content,omitempty"`
	ContentTooLarge bool      `json:"contentTooLarge"`
}

type Driver

type Driver struct {
	Id          uint64 `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Typ         string `json:"type"`

	// sync
	Sync bool  `json:"sync"`
	H    int64 `json:"h"`
	M    int64 `json:"m"`

	// baidu photo
	AccessToken  string `json:"accessToken"`
	RefreshToken string `json:"refreshToken"`

	// local file
	DeviceId string `json:"deviceId"`
	SrcPath  string `json:"srcPath"`
	Ignores  string `json:"ignores"`
	Encoder  string `json:"encoder"`
}

type DriverFile

type DriverFile struct {
	DriverId       uint64   `json:"driverId"`
	DriverName     string   `json:"driverName"`
	DirPath        []string `json:"dirPath"`
	Name           string   `json:"name"`
	Version        uint64   `json:"version"` // TODO: REMOVE IT!
	Hash           string   `json:"hash"`
	Mode           uint64   `json:"mode"`
	Size           uint64   `json:"size"`
	CreateTime     uint64   `json:"createTime"` // linux does not support it.
	ModifyTime     uint64   `json:"modifyTime"`
	ChangeTime     uint64   `json:"changeTime"` // windows does not support it.
	AccessTime     uint64   `json:"accessTime"`
	UploadDeviceId string   `json:"uploadDeviceId"`
	UploadTime     uint64   `json:"uploadTime"`
}

https://zhuanlan.zhihu.com/p/343682839

func (DriverFile) GetAccessTime

func (d DriverFile) GetAccessTime() uint64

func (DriverFile) GetChangeTime

func (d DriverFile) GetChangeTime() uint64

func (DriverFile) GetCreateTime

func (d DriverFile) GetCreateTime() uint64

func (DriverFile) GetDirPath

func (d DriverFile) GetDirPath() []string

func (DriverFile) GetDriverId

func (d DriverFile) GetDriverId() uint64

func (DriverFile) GetHash

func (d DriverFile) GetHash() string

func (DriverFile) GetMode

func (d DriverFile) GetMode() uint64

func (DriverFile) GetModifyTime

func (d DriverFile) GetModifyTime() uint64

func (DriverFile) GetName

func (d DriverFile) GetName() string

func (DriverFile) GetSize

func (d DriverFile) GetSize() uint64

type Exif

type Exif struct {
	ExifVersion         string
	ImageDescription    string
	Orientation         uint16 // 方向 https://developer.qiniu.com/dora/kb/1560/information-about-photo-exif-rotation-parameters-in-the-understanding-of-orientation?category=kb
	DateTime            string // 修改时间 YYYY:MM:DD HH:MM:SS
	DateTimeOriginal    string // 拍摄时间
	DateTimeDigitized   string // 写入时间
	OffsetTime          string // 时区 +01:00
	OffsetTimeOriginal  string
	OffsetTimeDigitized string
	SubsecTime          string // 亚秒 长度不确定
	SubsecTimeOriginal  string
	SubsecTimeDigitized string
	HostComputer        string
	Make                string
	Model               string
	ExifImageWidth      uint64
	ExifImageLength     uint64
	GPSLatitudeRef      string
	GPSLatitude         float64 // 纬度
	GPSLongitudeRef     string
	GPSLongitude        float64 // 经度
}

type File

type File struct {
	FileOrDir
}

func NewFile

func NewFile(hash string, size uint64) File

func NewFileByBytes

func NewFileByBytes(bytes []byte) File

type FileOrDir

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

func (FileOrDir) Count

func (i FileOrDir) Count() uint64

func (FileOrDir) Hash

func (i FileOrDir) Hash() string

func (FileOrDir) Size

func (i FileOrDir) Size() uint64

func (FileOrDir) TotalCount

func (i FileOrDir) TotalCount() uint64

type FileType

type FileType struct {
	Type      string `json:"type"`
	SubType   string `json:"subType"`
	Extension string `json:"extension"`
}

type HeightWidth

type HeightWidth struct {
	Width  uint64 `json:"width"`
	Height uint64 `json:"height"`
}

type IBranch

type IBranch interface {
	GetName() string
	GetDescription() string
	GetCommitId() uint64
	GetSize() uint64
	GetCount() uint64
}

type IDirItem

type IDirItem interface {
	GetHash() string
	GetName() string
	GetMode() uint64
	GetSize() uint64
	GetCount() uint64
	GetTotalCount() uint64
	GetCreateTime() uint64
	GetModifyTime() uint64
	GetChangeTime() uint64
	GetAccessTime() uint64
}

type IDriverFile

type IDriverFile interface {
	GetDriverId() uint64
	GetDirPath() []string
	GetName() string
	GetVersion() uint64
	GetHash() string
	GetMode() uint64
	GetSize() uint64
	GetCreateTime() uint64
	GetModifyTime() uint64
	GetChangeTime() uint64
	GetAccessTime() uint64
}

type IFileOrDir

type IFileOrDir interface {
	Hash() string
	Size() uint64
	Count() uint64
	TotalCount() uint64
}

type Metadata

type Metadata struct {
	Hash            string         `json:"hash"`
	FileType        *FileType      `json:"fileType"`
	Time            int64          `json:"time"`
	Year            int64          `json:"year"`
	Month           int64          `json:"month"`
	Day             int64          `json:"day"`
	Duration        string         `json:"duration"`
	HeightWidth     *HeightWidth   `json:"heightWidth"`
	GPSLatitudeRef  string         `json:"GPSLatitudeRef"`
	GPSLatitude     float64        `json:"GPSLatitude"` // 纬度
	GPSLongitudeRef string         `json:"GPSLongitudeRef"`
	GPSLongitude    float64        `json:"GPSLongitude"` // 经度
	Exif            *Exif          `json:"exif"`
	VideoMetadata   *VideoMetadata `json:"videoMetadata"`
}

type SizedReadCloser

type SizedReadCloser interface {
	io.ReadSeekCloser
	Size() int64
}

type Storage

type Storage interface {
	Write(hash string, fn func(w io.Writer, hasher io.Writer) error) (bool, error)
	ReadWithSize(hash string) (SizedReadCloser, error)
	GetFilePath(hash string) string

	Remove() error
	Create() error
	Close() error
}

type VideoMetadata

type VideoMetadata struct {
	Codec    string
	Created  int64
	Modified int64
	Duration float64 // 容器中媒体数据的持续时间(秒)
}

type VideoMetadataFfmpeg

type VideoMetadataFfmpeg struct {
	Height   string  // streams[0].height
	Width    string  // streams[0].width
	Created  int64   // format.tags.creation_time
	Duration float64 // format.duration
	Make     string  // format.tags. com.apple.quicktime.make
	Model    string  // format.tags. com.apple.quicktime.modal
}

VideoMetadataFfmpeg ffprobe.exe -v quiet -show_format -show_streams -print_format json 9638.mp4

Jump to

Keyboard shortcuts

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