hms

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 69 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SEC_null = iota
	SEC_badenc
	SEC_panic

	SEC_auth_absent
	SEC_auth_scheme
	SEC_basic_decode
	SEC_basic_noacc
	SEC_basic_deny
	SEC_token_noacc
	SEC_token_malform
	SEC_token_notsign
	SEC_token_badclaims
	SEC_token_expired
	SEC_token_notyet
	SEC_token_issuer
	SEC_token_error
	SEC_token_badaid
	SEC_param_noacc

	SEC_nourl

	SEC_signin_nobind
	SEC_signin_nosecret
	SEC_signin_smallsec
	SEC_signin_nouser
	SEC_signin_denypass
	SEC_signin_sigtime
	SEC_signin_timeout
	SEC_signin_hs256
	SEC_signin_denyhash

	SEC_page_absent

	SEC_media_badacc
	SEC_media_noacc
	SEC_media_badmedia
	SEC_media_badhd
	SEC_media_badpath
	SEC_media_hidden
	SEC_media_access
	SEC_media_hdgone
	SEC_media_hdfail
	SEC_media_hdnocnt
	SEC_media_medgone
	SEC_media_medfail
	SEC_media_mednocnt
	SEC_media_filegone
	SEC_media_fileopen

	SEC_etmb_badacc
	SEC_etmb_noacc
	SEC_etmb_nopuid
	SEC_etmb_nopath
	SEC_etmb_hidden
	SEC_etmb_access
	SEC_etmb_badcnt
	SEC_etmb_notmb

	SEC_mtmb_badacc
	SEC_mtmb_noacc
	SEC_mtmb_nopuid
	SEC_mtmb_nopath
	SEC_mtmb_hidden
	SEC_mtmb_access
	SEC_mtmb_badcnt
	SEC_mtmb_absent

	SEC_tile_badacc
	SEC_tile_noacc
	SEC_tile_nopuid
	SEC_tile_twodim
	SEC_tile_badwdh
	SEC_tile_badhgt
	SEC_tile_zero
	SEC_tile_nopath
	SEC_tile_hidden
	SEC_tile_access
	SEC_tile_badcnt
	SEC_tile_absent

	SEC_reload_load
	SEC_reload_tmpl

	SEC_getlog_nobind

	SEC_folder_nobind
	SEC_folder_badacc
	SEC_folder_noacc
	SEC_folder_badpath
	SEC_folder_hidden
	SEC_folder_access
	SEC_folder_stat
	SEC_folder_noshr
	SEC_folder_home
	SEC_folder_drives
	SEC_folder_remote
	SEC_folder_shares
	SEC_folder_media
	SEC_folder_map
	SEC_folder_nocat
	SEC_folder_absent
	SEC_folder_fail
	SEC_folder_open
	SEC_folder_m3u
	SEC_folder_wpl
	SEC_folder_pls
	SEC_folder_asx
	SEC_folder_xspf
	SEC_folder_format
	SEC_folder_tracks

	// res/tags
	SEC_tags_nobind
	SEC_tags_badacc
	SEC_tags_noacc
	SEC_tags_badpath
	SEC_tags_hidden
	SEC_tags_access
	SEC_tags_extract

	SEC_ispath_nobind
	SEC_ispath_badacc
	SEC_ispath_noacc
	SEC_ispath_deny

	SEC_tagschk_nobind
	SEC_tagschk_badacc
	SEC_tagschk_noacc

	SEC_tagsstart_nobind

	SEC_tagsbreak_nobind

	SEC_tilechk_nobind
	SEC_tilechk_badacc
	SEC_tilechk_noacc

	SEC_tilestart_nobind

	SEC_tilebreak_nobind

	SEC_drvadd_nobind
	SEC_drvadd_badacc
	SEC_drvadd_noacc
	SEC_drvadd_deny
	SEC_drvadd_badpath
	SEC_drvadd_miss
	SEC_drvadd_hidden

	SEC_drvdel_nobind
	SEC_drvdel_badacc
	SEC_drvdel_noacc
	SEC_drvdel_deny
	SEC_drvdel_nopath

	SEC_cldadd_nobind
	SEC_cldadd_badacc
	SEC_cldadd_noacc
	SEC_cldadd_deny
	SEC_cldadd_badhost
	SEC_cldadd_ftpdial
	SEC_cldadd_ftpcred
	SEC_cldadd_ftproot
	SEC_cldadd_sftpdial
	SEC_cldadd_sftpcli
	SEC_cldadd_sftppwd
	SEC_cldadd_sftproot
	SEC_cldadd_davdial

	SEC_clddel_nobind
	SEC_clddel_badacc
	SEC_clddel_noacc
	SEC_clddel_deny
	SEC_clddel_nopath

	SEC_shradd_nobind
	SEC_shradd_badacc
	SEC_shradd_noacc
	SEC_shradd_deny
	SEC_shradd_nopath
	SEC_shradd_access

	SEC_shrdel_nobind
	SEC_shrdel_badacc
	SEC_shrdel_noacc
	SEC_shrdel_deny
	SEC_shrdel_nopath
	SEC_shrdel_access

	SEC_edtcopy_nobind
	SEC_edtcopy_badacc
	SEC_edtcopy_noacc
	SEC_edtcopy_deny
	SEC_edtcopy_nopath
	SEC_edtcopy_nodest
	SEC_edtcopy_over
	SEC_edtcopy_opsrc
	SEC_edtcopy_statsrc
	SEC_edtcopy_mkdir
	SEC_edtcopy_rd
	SEC_edtcopy_opdst
	SEC_edtcopy_copy
	SEC_edtcopy_statfile

	SEC_edtren_nobind
	SEC_edtren_badacc
	SEC_edtren_noacc
	SEC_edtren_deny
	SEC_edtren_nopath
	SEC_edtren_nodest
	SEC_edtren_over
	SEC_edtren_move
	SEC_edtren_stat

	SEC_edtdel_nobind
	SEC_edtdel_badacc
	SEC_edtdel_noacc
	SEC_edtdel_deny
	SEC_edtdel_nopath
	SEC_edtdel_remove

	// gps/range
	SEC_gpsrange_nobind
	SEC_gpsrange_badacc
	SEC_gpsrange_noacc
	SEC_gpsrange_shpcirc
	SEC_gpsrange_shppoly
	SEC_gpsrange_shprect
	SEC_gpsrange_shpbad
	SEC_gpsrange_list

	// gps/scan
	SEC_gpsscan_nobind
	SEC_gpsscan_badacc
	SEC_gpsscan_noacc

	// stat/usrlst
	SEC_usrlst_nobind
	SEC_usrlst_asts
	SEC_usrlst_fost
	SEC_usrlst_post
)

Service provider error codes. Each error code have unique source code point, so this error code at service reply exactly points to error place.

View Source
const (
	// orientation: normal
	OrientNormal = 1
	// orientation: horizontal reversed
	OrientHorzReversed = 2
	// orientation: flipped
	OrientFlipped = 3
	// orientation: flipped & horizontal reversed
	OrientFlipHorzReversed = 4
	// orientation: clockwise turned & horizontal reversed
	OrientCwHorzReversed = 5
	// orientation: clockwise turned
	OrientCw = 6
	// orientation: anticlockwise turned & horizontal reversed
	OrientAcwHorzReversed = 7
	// orientation: anticlockwise turned
	OrientAcw = 8
)

EXIF image orientation constants.

View Source
const (
	// FPAnone - profile have no any access to specified file path.
	FPAnone = 0
	// FPAadmin - only authorized access to specified file path.
	FPAadmin = 1
	// FPAshare - access to specified file path is shared.
	FPAshare = 2
)

File path access.

View Source
const (
	CPhome   = "<home>"
	CPlocal  = "<local>"
	CPremote = "<remote>"
	CPshares = "<shares>"
	CPmedia  = "<media>"
	CPvideo  = "<video>"
	CPaudio  = "<audio>"
	CPimage  = "<image>"
	CPbooks  = "<books>"
	CPtexts  = "<texts>"
	CPmap    = "<map>"
)

Categories paths constants.

View Source
const ExifDate = "2006-01-02 15:04:05.999"
View Source
const FGnum = 8

FGnum is count of file groups.

Variables

View Source
var (
	ErrNoJwtID  = errors.New("jwt-token does not have user id")
	ErrBadJwtID = errors.New("jwt-token id does not refer to registered user")
	ErrNoAuth   = errors.New("authorization is absent")
	ErrNoScheme = errors.New("authorization does not have expected scheme")
	ErrNoSecret = errors.New("expected password or SHA25 hash on it and current time as a nonce")
	ErrSmallKey = errors.New("password too small")
	ErrNoCred   = errors.New("profile with given credentials does not registered")
	ErrNotPass  = errors.New("password is incorrect")
	ErrSigTime  = errors.New("signing time can not been recognized (time in RFC3339 expected)")
	ErrSigOut   = errors.New("nonce is expired")
	ErrBadHash  = errors.New("hash cannot be decoded in hexadecimal")
	ErrNoAcc    = errors.New("profile is absent")
)

HTTP error messages

View Source
var (
	S2B      = wpk.S2B
	B2S      = wpk.B2S
	JoinPath = wpk.JoinPath
	ToSlash  = wpk.ToSlash
	ToLower  = wpk.ToLower
	ToKey    = wpk.ToKey
	Cfg      = cfg.Cfg
	Log      = cfg.Log
)
View Source
var (
	ErrNoPUID      = errors.New("file with given puid not found")
	ErrUncacheable = errors.New("file format is uncacheable")
	ErrNotHD       = errors.New("image dimensions does not fit to full HD")
	ErrNotDisk     = errors.New("file is not image of supported format")
	ErrNoMTime     = errors.New("modify time tag does not found")
	ErrNoMime      = errors.New("MIME tag does not found")
	ErrEmptyExif   = errors.New("EXIF metadata is empty")
	ErrEmptyID3    = errors.New("ID3 metadata is empty")
)

Error messages

View Source
var (
	PathCache = NewBimap[Puid_t, string]()  // Bidirectional map for PUIDs and system paths.
	GpsCache  = NewCache[Puid_t, GpsInfo]() // FIFO cache with GPS coordinates.

)
View Source
var (
	Err404     = errors.New("page not found")
	ErrNotSys  = errors.New("root PUID does not refers to file system path")
	ErrPathOut = errors.New("path cannot refers outside root PUID")

	ErrArgNoHD   = errors.New("'hd' parameter not recognized")
	ErrArgNoDim  = errors.New("bad tiles dimensions")
	ErrArgZDim   = errors.New("dimensions can not be zero")
	ErrNotDir    = errors.New("path is not directory")
	ErrNoPath    = errors.New("path is not found")
	ErrDeny      = errors.New("access denied for specified authorization")
	ErrNotShared = errors.New("access to specified resource does not shared")
	ErrHidden    = errors.New("access to specified file path is disabled")
	ErrNoAccess  = errors.New("profile has no access to specified file path")
	ErrNoCat     = errors.New("specified category does not found")
	ErrNotPlay   = errors.New("file can not be read as playlist")
	ErrFileOver  = errors.New("to many files with same names contains")
	ErrShapeCirc = errors.New("circle must contains 1 coordinates point")
	ErrShapePoly = errors.New("polygon must contains 3 coordinates points at least")
	ErrShapeRect = errors.New("rectangle must contains 4 coordinates points")
	ErrShapeBad  = errors.New("shape is not recognized")
)

HTTP error messages

View Source
var (
	ErrBadMedia = errors.New("media content is corrupted")
	ErrNoThumb  = errors.New("embedded thumbnail is not found")
	ErrNotFile  = errors.New("property is not file")
	ErrNotImg   = errors.New("file is not image")
	ErrTooBig   = errors.New("file is too big")
	ErrImgNil   = errors.New("can not allocate image")
)

Error messages

View Source
var (
	// UserOnline is map of last AJAX query time for each user.
	UserOnline = map[uint64]time.Time{}
	// UaMap is the map of user agent hashes and associated client IDs.
	UaMap = map[uint64]uint64{}
)

AuthGetters is the list of functions to extract the authorization data from the parts of request. List and order in it can be changed.

CatKeyPath is predefined read-only maps with PUIDs keys and categories values.

View Source
var CatNames = map[string]string{
	CPhome:   "Home",
	CPlocal:  "Local disks",
	CPremote: "Network disks",
	CPshares: "Shared resources",
	CPmedia:  "Multimedia files",
	CPvideo:  "Movie and video files",
	CPaudio:  "Music and audio files",
	CPimage:  "Photos and images",
	CPbooks:  "Books",
	CPtexts:  "Text files",
	CPmap:    "Map",
}

CatPathKey is predefined read-only map with categories keys and PUIDs values.

View Source
var (
	ErrBadType = errors.New("type does not supported to insert into database")
)
View Source
var (
	ErrM3USign = errors.New("file does not starts with M3U signature")
)
View Source
var Hidden = FileMask{
	Exts: []string{
		".sys", ".tmp", ".bak",
	},
	Names: []string{
		"thumbs.db", ".*",
	},
	Paths: []string{
		"?:/system volume information",
		"?:/windows",
		"?:/windowsapps",
		"?:/winreagent",
		"?:/$windows.~ws",
		"?:/$recycle.bin",
		"?:/program files",
		"?:/program files (x86)",
		"?:/programdata",
		"?:/recovery",
		"?:/config.msi",
	},
}
View Source
var ImgScanner scanner

ImgScanner is singleton for thumbnails producing with single queue to prevent overload.

View Source
var MimeExt = map[string]Mime_t{
	"gif":  MimeGif,
	"png":  MimePng,
	"jpg":  MimeJpeg,
	"jpeg": MimeJpeg,
	"webp": MimeWebp,
}
View Source
var MimeStr = map[Mime_t]string{
	MimeNil:  "",
	MimeUnk:  "image/*",
	MimeGif:  "image/gif",
	MimePng:  "image/png",
	MimeJpeg: "image/jpeg",
	MimeWebp: "image/webp",
}
View Source
var MimeVal = map[string]Mime_t{
	"image/*":    MimeUnk,
	"image/gif":  MimeGif,
	"image/png":  MimePng,
	"image/jpg":  MimeJpeg,
	"image/jpeg": MimeJpeg,
	"image/webp": MimeWebp,
}
View Source
var Passlist []net.IPNet
View Source
var ResFS wpk.Union // resources packages root dir.
View Source
var XormStorage *xorm.Engine
View Source
var XormUserlog *xorm.Engine

Functions

func AddOrientFilter

func AddOrientFilter(flt []gift.Filter, orientation int) []gift.Filter

AddOrientFilter appends filters to bring image to normal orientation.

func ApiWrap

func ApiWrap(c *gin.Context)

func Auth

func Auth(required bool) gin.HandlerFunc

Auth is authorization middleware, sets User object associated with authorization to gin context. `required` parameter tells to continue if authorization is absent.

func CacheSize

func CacheSize[K comparable, T Sizer](cache *Cache[K, T]) (size int64)

CacheSize returns size of given cache.

func CalcUAID

func CalcUAID(addr, ua string) uint64

CalcUAID calculate user agent ID by xxhash from given strings.

func CfgReadYaml

func CfgReadYaml(fname string) (err error)

CfgReadYaml reads content of Config structure from YAML-file with given file name.

func CfgWriteYaml

func CfgWriteYaml(fname string) error

CfgWriteYaml writes content of Config object in YAML format with header comment to file with given file name.

func ClosePackages

func ClosePackages() (err error)

ClosePackages closes all existing caches.

func DirStoreSet

func DirStoreSet(session *Session, puid Puid_t, dp DirProp) (err error)

DirStoreSet puts value to directories cache.

func DrawThumb

func DrawThumb(src image.Image, wdh, hgt int, orientation int) (data []byte, err error)

DrawThumb produces new thumbnail object.

func DrawTile

func DrawTile(src image.Image, wdh, hgt int, orientation int) (data []byte, err error)

DrawTile produces new tile object.

func ExifStoreSet

func ExifStoreSet(session *Session, puid Puid_t, tp ExifProp) (err error)

ExifStoreSet puts value to EXIF database.

func ExtStoreSet

func ExtStoreSet(session *Session, puid Puid_t, xp ExtProp) (err error)

ExtStoreSet puts value to embedded info database.

func FromHHMMSS

func FromHHMMSS(dur string) int64

func GetAID

func GetAID(c *gin.Context) (id uint64, err error)

func GetFileExt

func GetFileExt(fname string) string

GetFileExt returns file extension converted to lowercase.

func GetScanThreadsNum

func GetScanThreadsNum() int

GetScanThreadsNum returns number of scanning threads depended of settings and developer mode.

func GetUAID

func GetUAID(r *http.Request) (uaid uint64, err error)

GetUAID extract user agent ID from cookie.

func GetUID

func GetUID(c *gin.Context) uint64

func GpsCachePut

func GpsCachePut(puid Puid_t, tp ExifProp)

func Handle404

func Handle404(c *gin.Context)

func HasRangeBegin

func HasRangeBegin(r *http.Request) bool

HasRangeBegin returns true if request headers have "Range" header with range thats starts from beginning of the file.

func Id3StoreSet

func Id3StoreSet(session *Session, puid Puid_t, tp Id3Prop) (err error)

Id3StoreSet puts value to tags database.

func ImgCacheTrim

func ImgCacheTrim()

func InPasslist

func InPasslist(ip net.IP) bool

InPasslist checks that IP is loopback or in passlist.

func InitPackages

func InitPackages() (err error)

InitPackages opens all existing caches.

func IsRemote

func IsRemote(syspath string) bool

IsRemote returns true is resource is hosted anywhere outside.

func IsStatic

func IsStatic(fi fs.FileInfo) (static bool)

IsStatic returns whether file info refers to content that can not be modified or moved.

func IsTypeDecoded

func IsTypeDecoded(ext string) bool

IsTypeDecoded checks that file extension belongs to images that can be decoded.

func IsTypeEXIF

func IsTypeEXIF(ext string) bool

IsTypeEXIF checks that file extension belongs to images with EXIF tags.

func IsTypeID3

func IsTypeID3(ext string) bool

IsTypeID3 checks that file extension belongs to audio/video files with ID3 tags.

func IsTypeISO

func IsTypeISO(ext string) bool

IsTypeISO checks that file extension is ISO-disk.

func IsTypeImage

func IsTypeImage(ext string) bool

IsTypeImage checks that file is some image format.

func IsTypeJPEG

func IsTypeJPEG(ext string) bool

IsTypeJPEG checks that file extension is in JPEG group.

func IsTypeMp3

func IsTypeMp3(ext string) bool

IsTypeMp3 checks that file is MP3.

func IsTypeNativeImg

func IsTypeNativeImg(ext string) bool

IsTypeNativeImg checks that image file is supported by any browser without format conversion.

func IsTypePlaylist

func IsTypePlaylist(ext string) bool

IsTypePlaylist checks that file extension belongs playlist file.

func IsTypeTileImg

func IsTypeTileImg(ext string) bool

IsTypeTileImg checks that image file can be used to build tiles sheet.

func JoinUrl

func JoinUrl(elem ...string) string

JoinUrl performs concatenation of URL address with path elements.

func LoadTemplates

func LoadTemplates() (err error)

LoadTemplates is hot templates reload, during server running.

func LoadUaMap

func LoadUaMap() (err error)

LoadUaMap forms content of UaMap from database on server start.

func Mp3Scan

func Mp3Scan(r io.Reader) (length time.Duration, bitrate int, err error)

Mp3Scan scans file to calculate length of play and average bitrate. Bitrate is rounded up to kilobits.

func Negotiate

func Negotiate(c *gin.Context, code int, data any)

func OpenPackage

func OpenPackage() (err error)

OpenPackage opens hms-package.

func PackInfo

func PackInfo(fname string, pkg *wpk.Package, d time.Duration)

PackInfo writes info to log about opened cache.

func PathStarts

func PathStarts(fpath, prefix string) bool

PathStarts check up that given file path has given parental path.

func PathStorePath

func PathStorePath(session *Session, puid Puid_t) (fpath string, ok bool)

PathStorePath returns cached system path of specified PUID (path unique identifier).

func PrfReadYaml

func PrfReadYaml(fname string) (err error)

PrfReadYaml reads content of Profiles structure from YAML-file with given file name.

func PrfUpdate

func PrfUpdate()

PrfUpdate performs initial updates for profiles list.

func PrfWriteYaml

func PrfWriteYaml(fname string) error

PrfWriteYaml writes content of Profiles object in YAML format with header comment to file with given file name.

func RatFloat32

func RatFloat32(t *tiff.Tag) float32

func RatFloat64

func RatFloat64(t *tiff.Tag) float64

func ReadWhiteList

func ReadWhiteList(fname string) (err error)

ReadWhiteList reads content of white list from YAML-file with given file name.

func ReadYaml

func ReadYaml(fname string, data ...any) (err error)

ReadYaml reads "data" objects from YAML-file with given file name.

func RequestUAID

func RequestUAID(c *gin.Context) uint64

RequestUAID calculate user agent ID from given request.

func Ret400

func Ret400(c *gin.Context, code int, err error)

func Ret401

func Ret401(c *gin.Context, code int, err error)

func Ret403

func Ret403(c *gin.Context, code int, err error)

func Ret404

func Ret404(c *gin.Context, code int, err error)

func Ret500

func Ret500(c *gin.Context, code int, err error)

func RetErr

func RetErr(c *gin.Context, status, code int, err error)

func RetOk

func RetOk(c *gin.Context, data any)

func Router

func Router(r *gin.Engine)

func ScanCat

func ScanCat(prf *Profile, session *Session, puid Puid_t, cat string, percent float64, scanembed bool) (ret []any, err error)

ScanCat returns file properties list where number of files of given category is more then given percent.

func ScanDir

func ScanDir(prf *Profile, session *Session, dir string, isadmin bool, scanembed bool) (ret []any, skipped int, err error)

ScanDir returns file properties list for given file system directory, or directory in iso-disk.

func SpiCachesInfo

func SpiCachesInfo(c *gin.Context)

Get caches state snapshot.

func SpiCloudAdd

func SpiCloudAdd(c *gin.Context)

Add new cloud entry for profile.

func SpiCloudDel

func SpiCloudDel(c *gin.Context)

Remove cloud entry from profile with given identifier.

func SpiDriveAdd

func SpiDriveAdd(c *gin.Context)

Add new drive location for profile.

func SpiDriveDel

func SpiDriveDel(c *gin.Context)

Remove drive from profile with given identifier.

func SpiEditCopy

func SpiEditCopy(c *gin.Context)

APIHANDLER

func SpiEditDelete

func SpiEditDelete(c *gin.Context)

APIHANDLER

func SpiEditRename

func SpiEditRename(c *gin.Context)

APIHANDLER

func SpiEtmb

func SpiEtmb(c *gin.Context)

Hands out embedded thumbnails for given files if any.

func SpiFile

func SpiFile(c *gin.Context)

Hands out converted media files if them can be cached, or file system content as is.

func SpiFolder

func SpiFolder(c *gin.Context)

APIHANDLER

func SpiGetLog

func SpiGetLog(c *gin.Context)

Returns log items.

func SpiGpsRange

func SpiGpsRange(c *gin.Context)

APIHANDLER

func SpiGpsScan

func SpiGpsScan(c *gin.Context)

APIHANDLER

func SpiHasPath

func SpiHasPath(c *gin.Context)

Check access to given system path.

func SpiMemUsage

func SpiMemUsage(c *gin.Context)

Memory usage footprint.

func SpiMtmb

func SpiMtmb(c *gin.Context)

Hands out cached thumbnails for given files.

func SpiPage

func SpiPage(pref, fname string) gin.HandlerFunc

Distributes static pages.

func SpiPing

func SpiPing(c *gin.Context)

Check service response.

func SpiRefresh

func SpiRefresh(c *gin.Context)

func SpiReload

func SpiReload(c *gin.Context)

APIHANDLER

func SpiServInfo

func SpiServInfo(c *gin.Context)

Static service system information.

func SpiShareAdd

func SpiShareAdd(c *gin.Context)

APIHANDLER

func SpiShareDel

func SpiShareDel(c *gin.Context)

APIHANDLER

func SpiSignin

func SpiSignin(c *gin.Context)

func SpiTags

func SpiTags(c *gin.Context)

Extract embedded tags from given file.

func SpiTagsBreak

func SpiTagsBreak(c *gin.Context)

Break preparing thumbnails of pointed images.

func SpiTagsCheck

func SpiTagsCheck(c *gin.Context)

Check whether thumbnails of pointed images prepared.

func SpiTagsStart

func SpiTagsStart(c *gin.Context)

Start to preparing thumbnails of pointed images.

func SpiTile

func SpiTile(c *gin.Context)

Hands out thumbnails for given files if them cached.

func SpiTileBreak

func SpiTileBreak(c *gin.Context)

Break preparing tiles of pointed images.

func SpiTileCheck

func SpiTileCheck(c *gin.Context)

Check whether tiles of pointed images prepared.

func SpiTileStart

func SpiTileStart(c *gin.Context)

Start to preparing tiles of pointed images.

func SpiUserList

func SpiUserList(c *gin.Context)

APIHANDLER

func SqlSession

func SqlSession(f func(*Session) (any, error)) (any, error)

SqlSession execute sql wrapped in a single session.

func StripPort

func StripPort(addrport string) string

StripPort makes fast IP-address extract from valid host:port string.

func ThumbCacheTrim

func ThumbCacheTrim()

func ToHHMMSS

func ToHHMMSS(dur int64) string

func UpsertBuffer

func UpsertBuffer[T any](session *Session, table any, buf *[]Store[T]) (err error)

func WaitHandlers

func WaitHandlers()

WaitHandlers waits until all transactions will be done.

func WriteYaml

func WriteYaml(fname string, data ...any) (err error)

WriteYaml writes "data" objects to YAML-file with given file name. File writes in UTF-8 format with BOM, and "intro" comment.

Types

type AgentStore

type AgentStore struct {
	UAID uint64    `xorm:"unique"` // user agent ID
	CID  uint64    // client ID
	Addr string    // remote address
	UA   string    // user agent
	Lang string    // accept language
	Time time.Time `xorm:"created"`
}

AgentStore is storage record with user agent string and user host address.

type Asx

type Asx struct {
	XMLName xml.Name   `xml:"asx"`
	Text    string     `xml:",chardata"`
	Version string     `xml:"version,attr"`
	Title   string     `xml:"title,omitempty"`
	Param   []AsxParam `xml:"param"`
	Entry   []AsxEntry `xml:"entry"`
}

type AsxEntry

type AsxEntry struct {
	Text  string `xml:",chardata"`
	Title string `xml:"title,omitempty"`
	Ref   struct {
		Href string `xml:"href,attr"`
	} `xml:"ref"`
	Duration struct {
		Value string `xml:"value,attr"`
	} `xml:"duration"`
	Param     []AsxParam `xml:"param"`
	Author    string     `xml:"author,omitempty"`
	Copyright string     `xml:"copyright,omitempty"`
}

type AsxParam

type AsxParam struct {
	Text  string `xml:",chardata"`
	Name  string `xml:"name,attr"`
	Value string `xml:"value,attr"`
}

type AuthGetter

type AuthGetter func(c *gin.Context) (*Profile, int, error)

type AuthResp

type AuthResp struct {
	XMLName xml.Name `json:"-" yaml:"-" xml:"ret"`
	UID     uint64   `json:"uid" yaml:"uid" xml:"uid"`
	Access  string   `json:"access" yaml:"access" xml:"access"`
	Refrsh  string   `json:"refrsh" yaml:"refrsh" xml:"refrsh"`
	Expire  string   `json:"expire" yaml:"expire" xml:"expire"`
	Living  string   `json:"living" yaml:"living" xml:"living"`
}

func (*AuthResp) Setup

func (r *AuthResp) Setup(user *Profile)

type Bimap

type Bimap[K comparable, T comparable] struct {
	// contains filtered or unexported fields
}

Bimap is bidirectional threads safe map.

func NewBimap

func NewBimap[K comparable, T comparable]() *Bimap[K, T]

NewBimap returns pointer to new Bimap object.

func (*Bimap[K, T]) DeleteDir

func (m *Bimap[K, T]) DeleteDir(key K) (val T, ok bool)

DeleteDir deletes key-value pair pointed by key, and returns deleted value.

func (*Bimap[K, T]) DeleteRev

func (m *Bimap[K, T]) DeleteRev(val T) (key K, ok bool)

DeleteRev deletes key-value pair pointed by value, and returns deleted key.

func (*Bimap[K, T]) GetDir

func (m *Bimap[K, T]) GetDir(key K) (val T, ok bool)

GetDir returns element in direct order, i.e. value pointed by key.

func (*Bimap[K, T]) GetRev

func (m *Bimap[K, T]) GetRev(val T) (key K, ok bool)

GetRev returns element in reverse order, i.e. key pointed by value.

func (*Bimap[K, T]) Len

func (m *Bimap[K, T]) Len() int

Len returns number of key-value pairs.

func (*Bimap[K, T]) Set

func (m *Bimap[K, T]) Set(key K, val T)

Set inserts key-value pair into map.

type Cache

type Cache[K comparable, T any] struct {
	// contains filtered or unexported fields
}

Cache is LRU & FIFO threads safe cache.

func NewCache

func NewCache[K comparable, T any]() *Cache[K, T]

NewCache returns pointer to new Cache object.

func (*Cache[K, T]) Free

func (c *Cache[K, T]) Free(n int)

Free removes n first entries from cache.

func (*Cache[K, T]) Get

func (c *Cache[K, T]) Get(key K) (ret T, ok bool)

Get returns value pointed by given key, and brings the pair to top of cache.

func (*Cache[K, T]) Has

func (c *Cache[K, T]) Has(key K) (ok bool)

Has detects whether pair is present.

func (*Cache[K, T]) Len

func (c *Cache[K, T]) Len() int

Len returns number of key-value pairs.

func (*Cache[K, T]) OnRemove

func (c *Cache[K, T]) OnRemove(efn func(K, T))

OnRemove changes callback function that is called when removing a pair.

func (*Cache[K, T]) Peek

func (c *Cache[K, T]) Peek(key K) (ret T, ok bool)

Peek returns value pointed by given key.

func (*Cache[K, T]) Poke

func (c *Cache[K, T]) Poke(key K, val T)

func (*Cache[K, T]) Range

func (c *Cache[K, T]) Range(f func(K, T) bool)

Range makes copy of the state and then call given function for each pair until `false` returned.

func (*Cache[K, T]) Remove

func (c *Cache[K, T]) Remove(key K) (ok bool)

func (*Cache[K, T]) Set

func (c *Cache[K, T]) Set(key K, val T)

func (*Cache[K, T]) ToLimit

func (c *Cache[K, T]) ToLimit(limit int)

ToLimit brings cache to limited count of entries.

func (*Cache[K, T]) Until

func (c *Cache[K, T]) Until(f func(K, T) bool)

Until removes first some entries from cache until given func returns true.

type Cacher

type Cacher interface {
	Cache()
}

Cacher provides function to perform image converting.

type CatGrp

type CatGrp [FGnum]bool

CatGrp indicates access to each file group.

func (*CatGrp) IsZero

func (cg *CatGrp) IsZero() bool

IsZero used to check whether an object is zero to determine whether it should be omitted when marshaling to yaml.

func (*CatGrp) SetAll

func (cg *CatGrp) SetAll(v bool)

SetAll sets all elements to given boolean value.

type Claims

type Claims struct {
	jwt.RegisteredClaims
	UID uint64 `json:"uid,omitempty"`
}

Claims of JWT-tokens. Contains additional profile identifier.

func (*Claims) Validate

func (c *Claims) Validate() error

type DirKit

type DirKit struct {
	PuidProp `xorm:"extends" yaml:",inline"`
	FileProp `xorm:"extends" yaml:",inline"`
	DirProp  `xorm:"extends" yaml:",inline"`
}

DirKit is directory properties kit.

type DirProp

type DirProp struct {
	Scan    time.Time `json:"scan,omitempty" yaml:"scan,omitempty" xml:"scan,omitempty"`                           // directory scanning time in UNIX format, milliseconds.
	FGrp    FileGroup `xorm:"extends" json:"fgrp,omitempty" yaml:"fgrp,flow,omitempty" xml:"fgrp,omitempty"`       // directory file groups counters.
	Latency int       `xorm:"default 0" json:"latency,omitempty" yaml:"latency,omitempty" xml:"latency,omitempty"` // drive connection latency in ms, or -1 on error
}

DirProp is directory properties chunk.

func ScanFileInfoList

func ScanFileInfoList(prf *Profile, session *Session, vfiles []fs.FileInfo, vpaths []DiskPath, scanembed bool) (ret []any, lstp DirProp, err error)

ScanFileInfoList returns file properties list for given list of []fs.FileInfo and associated list of full file system paths. Elements of []fs.FileInfo list can be nil in case if file is unavailable, or if it categoty item.

func ScanFileNameList

func ScanFileNameList(prf *Profile, session *Session, vpaths []DiskPath, scanembed bool) (ret []any, lstp DirProp, err error)

ScanFileNameList returns file properties list for given list of full file system paths. File paths can be in different folders.

type DirStore

type DirStore Store[DirProp]

type DiskPath

type DiskPath struct {
	Path string `xorm:"'path'" json:"path" yaml:"path" xml:"path"`
	Name string `xorm:"'name'" json:"name" yaml:"name" xml:"name"`
}

DiskPath contains disk full path and icon label.

func MakeFilePath

func MakeFilePath(syspath string) DiskPath

MakeFilePath creates DiskPath for file system path.

type EmbedPath

type EmbedPath Puid_t

EmbedPath is path to get embedded JPEG thumbnail.

func (EmbedPath) Cache

func (puid EmbedPath) Cache()

type ExifKit

type ExifKit struct {
	ExtProp  `xorm:"extends" yaml:",inline"`
	ExifProp `xorm:"extends" yaml:",inline"`
}

ExifKit is file with EXIF tags.

type ExifProp

type ExifProp struct {
	ImgWdh int `json:"imgwdh,omitempty" yaml:"imgwdh,omitempty" xml:"imgwdh,omitempty"`
	ImgHgt int `json:"imghgt,omitempty" yaml:"imghgt,omitempty" xml:"imghgt,omitempty"`
	// Photo
	Model        string    `xorm:"'model'" json:"model,omitempty" yaml:"model,omitempty" xml:"model,omitempty"`
	Make         string    `xorm:"'make'" json:"make,omitempty" yaml:"make,omitempty" xml:"make,omitempty"`
	Software     string    `xorm:"'software'" json:"software,omitempty" yaml:"software,omitempty" xml:"software,omitempty"`
	DateTime     time.Time `xorm:"'datetime'" json:"datetime,omitempty" yaml:"datetime,omitempty" xml:"datetime,omitempty"`
	Orientation  int       `xorm:"'orientation'" json:"orientation,omitempty" yaml:"orientation,omitempty" xml:"orientation,omitempty"`
	ExposureTime string    `xorm:"'exposure_time'" json:"exposuretime,omitempty" yaml:"exposuretime,omitempty" xml:"exposuretime,omitempty"`
	ExposureProg int       `xorm:"'exposure_prog'" json:"exposureprog,omitempty" yaml:"exposureprog,omitempty" xml:"exposureprog,omitempty"`
	FNumber      float32   `xorm:"'fnumber'" json:"fnumber,omitempty" yaml:"fnumber,omitempty" xml:"fnumber,omitempty"`
	ISOSpeed     int       `xorm:"'iso_speed'" json:"isospeed,omitempty" yaml:"isospeed,omitempty" xml:"isospeed,omitempty"`
	ShutterSpeed float32   `xorm:"'shutter_speed'" json:"shutterspeed,omitempty" yaml:"shutterspeed,omitempty" xml:"shutterspeed,omitempty"`
	Aperture     float32   `xorm:"'aperture'" json:"aperture,omitempty" yaml:"aperture,omitempty" xml:"aperture,omitempty"`
	ExposureBias float32   `xorm:"'exposure_bias'" json:"exposurebias,omitempty" yaml:"exposurebias,omitempty" xml:"exposurebias,omitempty"`
	LightSource  int       `xorm:"'light_source'" json:"lightsource,omitempty" yaml:"lightsource,omitempty" xml:"lightsource,omitempty"`
	Focal        float32   `xorm:"'focal'" json:"focal,omitempty" yaml:"focal,omitempty" xml:"focal,omitempty"`
	Focal35mm    int       `xorm:"'focal35mm'" json:"focal35mm,omitempty" yaml:"focal35mm,omitempty" xml:"focal35mm,omitempty"`
	DigitalZoom  float32   `xorm:"'digital_zoom'" json:"digitalzoom,omitempty" yaml:"digitalzoom,omitempty" xml:"digitalzoom,omitempty"`
	Flash        int       `xorm:"'flash'" json:"flash,omitempty" yaml:"flash,omitempty" xml:"flash,omitempty"`
	UniqueID     string    `xorm:"'unique_id'" json:"uniqueid,omitempty" yaml:"uniqueid,omitempty" xml:"uniqueid,omitempty"`
	ThumbJpegLen int       `xorm:"'thumb_jpeg_len'" json:"thumbjpeglen,omitempty" yaml:"thumbjpeglen,omitempty" xml:"thumbjpeglen,omitempty"`
	// GPS
	Latitude   float64 `xorm:"'latitude'" json:"latitude,omitempty" yaml:"latitude,omitempty" xml:"latitude,omitempty"`
	Longitude  float64 `xorm:"'longitude'" json:"longitude,omitempty" yaml:"longitude,omitempty" xml:"longitude,omitempty"`
	Altitude   float32 `xorm:"'altitude'" json:"altitude,omitempty" yaml:"altitude,omitempty" xml:"altitude,omitempty"`
	Satellites string  `xorm:"'satellites'" json:"satellites,omitempty" yaml:"satellites,omitempty" xml:"satellites,omitempty"`
}

ExifProp is EXIF tags properties chunk.

func ExifExtract

func ExifExtract(session *Session, file io.Reader, puid Puid_t) (tp ExifProp, err error)

ExifExtract trys to extract EXIF metadata from file.

func ExifStoreGet

func ExifStoreGet(session *Session, puid Puid_t) (tp ExifProp, ok bool)

ExifStoreGet returns value from EXIF database.

func (*ExifProp) IsZero

func (tp *ExifProp) IsZero() bool

IsZero used to check whether an object is zero to determine whether it should be omitted when marshaling to yaml.

func (*ExifProp) Setup

func (tp *ExifProp) Setup(x *exif.Exif)

Setup fills fields from given EXIF structure.

type ExifStore

type ExifStore Store[ExifProp]

type ExtProp

type ExtProp struct {
	Tags ExtTag `xorm:"tags" json:"tags" yaml:"tags" xml:"tags"`
	ETmb Mime_t `xorm:"etmb" json:"etmb" yaml:"etmb" xml:"etmb"` // embedded thumbnail

	Width   int           `xorm:"width" json:"width,omitempty" yaml:"width,omitempty" xml:"width,omitempty"`     // image width in pixels
	Height  int           `xorm:"height" json:"height,omitempty" yaml:"height,omitempty" xml:"height,omitempty"` // image height in pixels
	PBLen   time.Duration `xorm:"pblen" json:"pblen,omitempty" yaml:"pblen,omitempty" xml:"pblen,omitempty"`     // playback length
	BitRate int           `xorm:"bitrate" json:"bitrate,omitempty" yaml:"bitrate,omitempty" xml:"bitrate,omitempty"`
}

func ExtStoreGet

func ExtStoreGet(session *Session, puid Puid_t) (xp ExtProp, ok bool)

ExtStoreGet returns value from embedded info database.

func TagsExtract

func TagsExtract(fpath string, session *Session, buf *StoreBuf, es *ExtStat, gettmb bool) (p any, xp ExtProp, err error)

type ExtStat

type ExtStat struct {
	ErrCount  uint64
	FileCount uint64
	ExtCount  uint64
	ImgCount  uint64
	ExifCount uint64
	Id3Count  uint64
	TmbCount  uint64
	Mp3Count  uint64
}

type ExtStore

type ExtStore Store[ExtProp]

type ExtTag

type ExtTag int
const (
	TagDis ExtTag = iota - 1 // file have no any tags

	TagNil  // tags have not scanned yet, indeterminate state
	TagImg  // image config only
	TagExif // image config + EXIF
	TagID3  // MP3/MP4/OGG/FLAC metadata
)

type FG_t

type FG_t int

FG_t is enum type for file groups.

const (
	FGother FG_t = 0
	FGvideo FG_t = 1
	FGaudio FG_t = 2
	FGimage FG_t = 3
	FGbooks FG_t = 4
	FGtexts FG_t = 5
	FGpacks FG_t = 6
	FGgroup FG_t = 7
)

File groups.

func GetFileGroup

func GetFileGroup(fpath string) FG_t

GetFileGroup returns file group integer value for given file name by it's extension.

type FT_t

type FT_t int

FT_t is enum type for properties file types.

const (
	FTunk  FT_t = 0 // unknown file type
	FTfile FT_t = 1
	FTdir  FT_t = 2
	FTdrv  FT_t = 3
	FTcld  FT_t = 4
	FTctgr FT_t = 5
)

File types.

type FileCache

type FileCache struct {
	*wpk.Package
	// contains filtered or unexported fields
}

FileCache describes package with cache functionality. Package splitted in two files - tags table file and data file with cached nested files.

var (
	// cache with images thumbnails which are placed in box 256x256.
	ThumbPkg *FileCache
	// cache with images tiles, size of each tile is placed as sufix
	// of path in format "full/path/to/file.ext?144x108".
	TilesPkg *FileCache
)

package caches

func InitCacheWriter

func InitCacheWriter(fpath string) (fc *FileCache, d time.Duration, err error)

InitCacheWriter opens existing cache with given file path placed in cache directory, or creates new cache file if no one found.

func (*FileCache) Close

func (fc *FileCache) Close() (err error)

Close saves actual tags table and closes opened cache.

func (*FileCache) GetData

func (fc *FileCache) GetData(fpath string) (md MediaData, err error)

GetData extracts file from the cache with given file name.

func (*FileCache) GetFile

func (fc *FileCache) GetFile(fpath string) (file wpk.RFile, mime string, t time.Time, err error)

GetFile extracts file from the cache with given file name.

func (*FileCache) PutFile

func (fc *FileCache) PutFile(fpath string, md MediaData) (err error)

PutFile puts file to package.

func (*FileCache) Sync

func (fc *FileCache) Sync() error

Sync writes actual file tags table and true signature with settings.

type FileGroup

type FileGroup struct {
	FGother uint `xorm:"'other' default 0" json:"other,omitempty" yaml:"other,omitempty" xml,omitempty,attr:"other"`
	FGvideo uint `xorm:"'video' default 0" json:"video,omitempty" yaml:"video,omitempty" xml,omitempty,attr:"video"`
	FGaudio uint `xorm:"'audio' default 0" json:"audio,omitempty" yaml:"audio,omitempty" xml,omitempty,attr:"audio"`
	FGimage uint `xorm:"'image' default 0" json:"image,omitempty" yaml:"image,omitempty" xml,omitempty,attr:"image"`
	FGbooks uint `xorm:"'books' default 0" json:"books,omitempty" yaml:"books,omitempty" xml,omitempty,attr:"books"`
	FGtexts uint `xorm:"'texts' default 0" json:"texts,omitempty" yaml:"texts,omitempty" xml,omitempty,attr:"texts"`
	FGpacks uint `xorm:"'packs' default 0" json:"packs,omitempty" yaml:"packs,omitempty" xml,omitempty,attr:"packs"`
	FGgroup uint `xorm:"'group' default 0" json:"group,omitempty" yaml:"group,omitempty" xml,omitempty,attr:"group"`
}

func (*FileGroup) Field

func (fg *FileGroup) Field(id FG_t) *uint

Field returns pointer to field value with given identifier.

func (*FileGroup) IsZero

func (fg *FileGroup) IsZero() bool

IsZero used to check whether an object is zero to determine whether it should be omitted when marshaling to yaml.

func (*FileGroup) Sum

func (fg *FileGroup) Sum() uint

Sum returns sum of all fields.

type FileKit

type FileKit struct {
	PuidProp `xorm:"extends" yaml:",inline"`
	FileProp `xorm:"extends" yaml:",inline"`
	TileProp `xorm:"extends" yaml:",inline"`
	ExtProp  `xorm:"extends" yaml:",inline"`
}

FileKit is common files properties kit.

type FileMask

type FileMask struct {
	Exts  []string `json:"extensions" yaml:"extensions" xml:"extensions"`
	Names []string `json:"filenames" yaml:"filenames" xml:"filenames"`
	Paths []string `json:"filepaths" yaml:"filepaths" xml:"filepaths"`
}

func (*FileMask) Fits

func (fm *FileMask) Fits(fpath string) bool

type FileProp

type FileProp struct {
	Name string    `xorm:"'name'" json:"name" yaml:"name" xml:"name"`
	Type FT_t      `xorm:"'type'" json:"type" yaml:"type" xml:"type"` // do not omit empty
	Size int64     `xorm:"'size' default 0" json:"size,omitempty" yaml:"size,omitempty" xml:"size,omitempty"`
	Time time.Time `xorm:"'time' DateTime default 0" json:"time,omitempty" yaml:"time,omitempty" xml:"time,omitempty"`
}

FileProp is common file properties chunk.

func (*FileProp) Setup

func (fp *FileProp) Setup(fi fs.FileInfo)

Setup fills fields from fs.FileInfo structure. Do not looks for share.

type GpsInfo

type GpsInfo struct {
	DateTime  time.Time `xorm:"DateTime" json:"time" yaml:"time" xml:"time,attr"` // photo creation date/time in Unix milliseconds
	Latitude  float64   `json:"lat" yaml:"lat" xml:"lat,attr"`
	Longitude float64   `json:"lon" yaml:"lon" xml:"lon,attr"`
	Altitude  float32   `json:"alt,omitempty" yaml:"alt,omitempty" xml:"alt,omitempty,attr"`
}

GpsInfo describes GPS-data from the photos: latitude, longitude, altitude and creation time.

func (*GpsInfo) FromProp

func (gi *GpsInfo) FromProp(tp *ExifProp)

FromProp fills fields with values from ExifProp.

type HdrRange

type HdrRange struct {
	Start int64
	End   int64
}

HdrRange describes one range chunk of the file to download.

func GetHdrRange

func GetHdrRange(r *http.Request) (ret []HdrRange)

GetHdrRange returns array of ranges of file to download from request header.

type Id3Kit

type Id3Kit struct {
	ExtProp `xorm:"extends" yaml:",inline"`
	Id3Prop `xorm:"extends" yaml:",inline"`
}

Id3Kit is music file tags properties kit.

type Id3Prop

type Id3Prop struct {
	Title    string `json:"title,omitempty" yaml:"title,omitempty" xml:"title,omitempty"`
	Album    string `json:"album,omitempty" yaml:"album,omitempty" xml:"album,omitempty"`
	Artist   string `json:"artist,omitempty" yaml:"artist,omitempty" xml:"artist,omitempty"`
	Composer string `json:"composer,omitempty" yaml:"composer,omitempty" xml:"composer,omitempty"`
	Genre    string `json:"genre,omitempty" yaml:"genre,omitempty" xml:"genre,omitempty"`
	Year     int    `json:"year,omitempty" yaml:"year,omitempty" xml:"year,omitempty"`
	TrackNum int    `xorm:"'tracknum'" json:"tracknum,omitempty" yaml:"tracknum,flow,omitempty" xml:"tracknum,omitempty,attr"`
	TrackSum int    `xorm:"'tracksum'" json:"tracksum,omitempty" yaml:"tracksum,flow,omitempty" xml:"tracksum,omitempty,attr"`
	DiscNum  int    `xorm:"'discnum'" json:"discnum,omitempty" yaml:"discnum,flow,omitempty" xml:"discnum,omitempty,attr"`
	DiscSum  int    `xorm:"'discsum'" json:"discsum,omitempty" yaml:"discsum,flow,omitempty" xml:"discsum,omitempty,attr"`
	Lyrics   string `json:"lyrics,omitempty" yaml:"lyrics,omitempty" xml:"lyrics,omitempty"`
	Comment  string `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
	ThumbLen int    `xorm:"'thumblen'" json:"thumblen,omitempty" yaml:"thumblen,omitempty" xml:"thumblen,omitempty"`
	TmbMime  Mime_t `xorm:"'tmbmime'" json:"tmbmime,omitempty" yaml:"tmbmime,omitempty" xml:"tmbmime,omitempty"`
}

Id3Prop is Music file tags properties chunk.

func Id3Extract

func Id3Extract(session *Session, file io.ReadSeeker, puid Puid_t) (tp Id3Prop, err error)

Id3Extract trys to extract ID3 metadata from file.

func Id3StoreGet

func Id3StoreGet(session *Session, puid Puid_t) (tp Id3Prop, ok bool)

Id3StoreGet returns value from tags database.

func (*Id3Prop) IsZero

func (tp *Id3Prop) IsZero() bool

IsZero used to check whether an object is zero to determine whether it should be omitted when marshaling to yaml.

func (*Id3Prop) Setup

func (tp *Id3Prop) Setup(m tag.Metadata)

Setup fills fields from tags metadata.

type Id3Store

type Id3Store Store[Id3Prop]

type MapPath

type MapPath struct {
	Shape  Shape   `json:"shape" yaml:"shape" xml:"shape"`
	Eject  bool    `json:"eject" yaml:"eject" xml:"eject"`
	Radius float64 `json:"radius,omitempty" yaml:"radius,omitempty" xml:"radius,omitempty"`
	Coord  []Point `json:"coord" yaml:"coord,flow" xml:"coord>point"`
}

MapPath describes any map path that can contains a points.

func (*MapPath) Contains

func (mp *MapPath) Contains(lat, lon float64) bool

type MediaData

type MediaData struct {
	Data []byte
	Mime Mime_t
	Time time.Time
}

MediaData is thumbnails cache element.

func CacheThumb

func CacheThumb(session *Session, syspath string) (md MediaData, err error)

CacheThumb tries to extract existing thumbnail from cache, otherwise makes new one and put it to cache.

func CacheTile

func CacheTile(session *Session, syspath string, wdh, hgt int) (md MediaData, err error)

CacheTile tries to extract existing tile from cache, otherwise makes new one and put it to cache.

func ExtractThmub

func ExtractThmub(syspath string) (md MediaData, err error)

ExtractThmub extract thumbnail from embedded file tags.

func ExtractThumbEXIF

func ExtractThumbEXIF(syspath string) (md MediaData, err error)

func HdCacheGet

func HdCacheGet(session *Session, puid Puid_t) (md MediaData, err error)

HdCacheGet returns image with given PUID converted to HD resolution from memory cache.

func Id3ExtractThumb

func Id3ExtractThumb(syspath string) (md MediaData, err error)

Id3ExtractThumb trys to extract thumbnail from file ID3 metadata.

func MediaCacheGet

func MediaCacheGet(session *Session, puid Puid_t) (md MediaData, err error)

MediaCacheGet returns media file with given PUID converted to acceptable for browser format from memory cache.

func (MediaData) Size

func (md MediaData) Size() int64

type Mime_t

type Mime_t int16
const (
	MimeDis Mime_t = iota - 1 // thumbnail is absent or file can not be cached for thumbnails.

	MimeNil  // file is not cached for thumbnails, have indeterminate state.
	MimeUnk  // image/*
	MimeGif  // image/gif
	MimePng  // image/png
	MimeJpeg // image/jpeg
	MimeWebp // image/webp
)

func CachedThumbMime

func CachedThumbMime(syspath string) Mime_t

CachedThumbMime returns MIME type of rendered thumbnail in package, or MimeNil if it not present.

func CachedTileMime

func CachedTileMime(syspath string, tm TM_t) Mime_t

CachedTileMime returns MIME type of rendered tile in package with given tile multiplier, or MimeNil if it not present.

func GetMimeVal

func GetMimeVal(mime, ext string) Mime_t

type OpenStore

type OpenStore struct {
	UAID    uint64    // client ID
	AID     uint64    `xorm:"default 0"` // access profile ID
	UID     uint64    `xorm:"default 0"` // user profile ID
	Path    string    // system path
	Latency int       // event latency, in milliseconds, or -1 if it file
	Time    time.Time `xorm:"created"` // time of event rise
}

OpenStore is storage record with some opened file or opened folder.

type PathStore

type PathStore struct {
	Puid Puid_t `xorm:"pk autoincr"`
	Path string `xorm:"notnull unique index"`
}

PathStore sqlite3 item of unlimited cache with puid/syspath values.

type Playlist

type Playlist struct {
	Tracks []Track
	Dest   string // playlist file destination
	// playlist description
	Title  string
	Group  string
	Album  string
	Artist string
	Genre  string
	Image  string
}

func (*Playlist) AbsPath

func (pl *Playlist) AbsPath(fpath string) string

func (*Playlist) ReadASX

func (pl *Playlist) ReadASX(r io.Reader) (num int64, err error)

func (*Playlist) ReadFrom

func (pl *Playlist) ReadFrom(r io.Reader) (num int64, err error)

func (*Playlist) ReadM3U

func (pl *Playlist) ReadM3U(r io.Reader) (num int64, err error)

func (*Playlist) ReadPLS

func (pl *Playlist) ReadPLS(r io.Reader) (num int64, err error)

func (*Playlist) ReadWPL

func (pl *Playlist) ReadWPL(r io.Reader) (num int64, err error)

func (*Playlist) ReadXSPF

func (pl *Playlist) ReadXSPF(r io.Reader) (num int64, err error)

func (*Playlist) WriteASX

func (pl *Playlist) WriteASX(w io.Writer) (num int64, err error)

func (*Playlist) WriteM3U

func (pl *Playlist) WriteM3U(w io.Writer) (num int64, err error)

func (*Playlist) WriteM3U8

func (pl *Playlist) WriteM3U8(w io.Writer) (num int64, err error)

func (*Playlist) WritePLS

func (pl *Playlist) WritePLS(w io.Writer) (num int64, err error)

func (*Playlist) WriteTo

func (pl *Playlist) WriteTo(w io.Writer) (num int64, err error)

func (*Playlist) WriteWPL

func (pl *Playlist) WriteWPL(w io.Writer) (num int64, err error)

func (*Playlist) WriteXSPF

func (pl *Playlist) WriteXSPF(w io.Writer) (num int64, err error)

type Point

type Point struct {
	Latitude  float64 `json:"lat" yaml:"lat" xml:"lat,attr"`
	Longitude float64 `json:"lon" yaml:"lon" xml:"lon,attr"`
}

type Profile

type Profile struct {
	ID       uint64 `json:"id" yaml:"id" xml:"id,attr"`
	Login    string `json:"login" yaml:"login" xml:"login"`
	Password string `json:"password" yaml:"password" xml:"password"`

	Local  []DiskPath `json:"local" yaml:"local" xml:"local>item"` // root directories list
	Remote []DiskPath `json:"remote" yaml:"remote" xml:"remote>item"`
	Shares []DiskPath `json:"shares" yaml:"shares" xml:"shares>item"`
	// contains filtered or unexported fields
}

Profile contains access configuration to resources.

func GetBasicAuth

func GetBasicAuth(credentials string) (user *Profile, code int, err error)

func GetBearerAuth

func GetBearerAuth(tokenstr string) (prf *Profile, code int, err error)

func GetUser

func GetUser(c *gin.Context) *Profile

func NewProfile

func NewProfile(login, password string) *Profile

NewProfile make new profile and insert it to the list.

func UserFromCookie

func UserFromCookie(c *gin.Context) (*Profile, int, error)

func UserFromForm

func UserFromForm(c *gin.Context) (*Profile, int, error)

func UserFromHeader

func UserFromHeader(c *gin.Context) (*Profile, int, error)

func UserFromQuery

func UserFromQuery(c *gin.Context) (*Profile, int, error)

func (*Profile) AddCloud

func (prf *Profile) AddCloud(syspath, name string) bool

AddCloud adds path to network roots list.

func (*Profile) AddLocal

func (prf *Profile) AddLocal(syspath, name string) bool

AddLocal adds system path to local roots list.

func (*Profile) AddShare

func (prf *Profile) AddShare(syspath string) bool

AddShare adds share with given system path.

func (*Profile) DelCloud

func (prf *Profile) DelCloud(syspath string) bool

DelCloud removes path from network roots list.

func (*Profile) DelLocal

func (prf *Profile) DelLocal(syspath string) bool

DelLocal removes system path from local roots list.

func (*Profile) DelShare

func (prf *Profile) DelShare(syspath string) bool

DelShare deletes share by given system path.

func (*Profile) FindLocal

func (prf *Profile) FindLocal()

FindLocal scans all available drives installed on local machine.

func (*Profile) GetPathGroup

func (prf *Profile) GetPathGroup(fpath string, fi fs.FileInfo) (grp FG_t)

func (*Profile) GetRootPath

func (prf *Profile) GetRootPath(session *Session, syspath string) (rootpath, rootname string)

GetRootPath returns path to nearest root path that contains given syspath, and its name.

func (*Profile) GetSharePath

func (prf *Profile) GetSharePath(session *Session, syspath string) (shrpath, shrname string)

GetSharePath returns path in nearest shared folder that contains given syspath, and its name.

func (*Profile) IsCloud

func (prf *Profile) IsCloud(syspath string) bool

IsCloud checks whether file path is cloud root path.

func (*Profile) IsLocal

func (prf *Profile) IsLocal(syspath string) bool

IsLocal checks whether file path is disk root path.

func (*Profile) IsShared

func (prf *Profile) IsShared(syspath string) bool

IsShared checks that syspath is become in any share.

func (*Profile) PathAccess

func (prf *Profile) PathAccess(syspath string, isadmin bool) bool

PathAccess returns file group access state for given file path.

func (*Profile) PathAdmin

func (prf *Profile) PathAdmin(syspath string) bool

PathAdmin returns whether profile has admin access to file path or category path.

func (*Profile) PathType

func (prf *Profile) PathType(fpath string, fi fs.FileInfo) FT_t

PathType returns type of file by given path.

func (*Profile) ScanLocal

func (prf *Profile) ScanLocal(session *Session, scanembed bool) (ret []any, err error)

ScanLocal scans paths from local roots list.

func (*Profile) ScanRemote

func (prf *Profile) ScanRemote(session *Session, scanembed bool) (ret []any, err error)

ScanRemote scans paths at network destination.

func (*Profile) ScanShares

func (prf *Profile) ScanShares(session *Session, scanembed bool) (ret []any, err error)

ScanShares scans actual shares from shares list.

type PuidProp

type PuidProp struct {
	PUID   Puid_t `xorm:"'puid'" json:"puid" yaml:"puid" xml:"puid,attr"`
	Free   bool   `xorm:"'free'" json:"free" yaml:"free" xml:"free,attr"`
	Shared bool   `xorm:"'shared'" json:"shared" yaml:"shared" xml:"shared,attr"`
	Static bool   `xorm:"'static'" json:"static" yaml:"static" xml:"static,attr"`
}

PuidProp encapsulated path unique ID value for some properties kit.

func (*PuidProp) Setup

func (pp *PuidProp) Setup(session *Session, syspath string)

type Puid_t

type Puid_t uint64

Puid_t represents integer form of path unique ID.

const (
	PuidTmb Puid_t = 0x2000_0000_0000_0000 // Embedded thumbnails qualifier
	PuidHD  Puid_t = 0x4000_0000_0000_0000 // HD-dimensions qualifier
	PuidImg Puid_t = 0x8000_0000_0000_0000 // Converted to acceptable browser format qualifier
)
const (
	PUIDhome   Puid_t = 1
	PUIDlocal  Puid_t = 2
	PUIDremote Puid_t = 3
	PUIDshares Puid_t = 4
	PUIDmedia  Puid_t = 5
	PUIDvideo  Puid_t = 6
	PUIDaudio  Puid_t = 7
	PUIDimage  Puid_t = 8
	PUIDbooks  Puid_t = 9
	PUIDtexts  Puid_t = 10
	PUIDmap    Puid_t = 11

	PUIDcache = 32 // first PUID of file system paths
)

Predefined PUIDs.

func PathStoreCache

func PathStoreCache(session *Session, fpath string) (puid Puid_t)

PathStoreCache returns cached PUID for specified system path, or make it and put into cache.

func PathStorePUID

func PathStorePUID(session *Session, fpath string) (puid Puid_t, ok bool)

PathStorePUID returns cached PUID for specified system path.

func UnfoldPath

func UnfoldPath(session *Session, shrpath string) (syspath string, puid Puid_t, err error)

UnfoldPath brings any share path to system file path.

func (Puid_t) MarshalJSON

func (pt Puid_t) MarshalJSON() ([]byte, error)

MarshalJSON is JSON marshaler interface implementation.

func (Puid_t) MarshalXML

func (pt Puid_t) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML is XML marshaler interface implementation.

func (Puid_t) MarshalYAML

func (pt Puid_t) MarshalYAML() (any, error)

MarshalYAML is YAML marshaler interface implementation.

func (*Puid_t) Rand

func (pt *Puid_t) Rand(bits int)

Rand generates random identifier of given length in bits, maximum 64 bits. Multiply x5 to convert length in base32 symbols to bits.

func (*Puid_t) Set

func (pt *Puid_t) Set(puid string) error

Set writes base32 string representation of ID into integer value.

func (Puid_t) String

func (pt Puid_t) String() string

String converts path unique ID to base32 string representation.

func (*Puid_t) UnmarshalJSON

func (pt *Puid_t) UnmarshalJSON(b []byte) error

UnmarshalJSON is JSON unmarshaler interface implementation.

func (*Puid_t) UnmarshalXML

func (pt *Puid_t) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML is XML unmarshaler interface implementation.

func (*Puid_t) UnmarshalYAML

func (pt *Puid_t) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML is YAML unmarshaler interface implementation.

type RFile

type RFile = jnt.RFile

func OpenFile

func OpenFile(fpath string) (file RFile, err error)

type RWList

type RWList[T comparable] struct {
	// contains filtered or unexported fields
}

func (*RWList[T]) Copy

func (rwl *RWList[T]) Copy() []T

func (*RWList[T]) Find

func (rwl *RWList[T]) Find(val T, from int) int

func (*RWList[T]) Init

func (rwl *RWList[T]) Init(capacity int)

func (*RWList[T]) Insert

func (rwl *RWList[T]) Insert(val T, i int)

func (*RWList[T]) Pop

func (rwl *RWList[T]) Pop() (val T, ok bool)

func (*RWList[T]) Push

func (rwl *RWList[T]) Push(val T)

func (*RWList[T]) Remove

func (rwl *RWList[T]) Remove(i int)

type RWMap

type RWMap[K comparable, T any] struct {
	// contains filtered or unexported fields
}

RWMap is threads safe map.

var Profiles RWMap[uint64, *Profile]

func (*RWMap[K, T]) Delete

func (rwm *RWMap[K, T]) Delete(key K)

Delete removes pair from map.

func (*RWMap[K, T]) Get

func (rwm *RWMap[K, T]) Get(key K) (ret T, ok bool)

Get returns value by pointed key.

func (*RWMap[K, T]) GetAndDelete

func (rwm *RWMap[K, T]) GetAndDelete(key K) (ret T, ok bool)

GetAndDelete removes pair from map and returns the value if it was.

func (*RWMap[K, T]) Has

func (rwm *RWMap[K, T]) Has(key K) (ok bool)

Has detects whether pair is present.

func (*RWMap[K, T]) Init

func (rwm *RWMap[K, T]) Init(capacity int)

func (*RWMap[K, T]) Len

func (rwm *RWMap[K, T]) Len() int

Len returns number of key-value pairs.

func (*RWMap[K, T]) Range

func (rwm *RWMap[K, T]) Range(f func(K, T) bool)

Range makes copy of the state and then call given function for each pair until `false` returned.

func (*RWMap[K, T]) Set

func (rwm *RWMap[K, T]) Set(key K, val T)

Set inserts given key-value pair.

type Session

type Session = xorm.Session

type Shape

type Shape string
const (
	Circle    Shape = "circle"
	Polygon   Shape = "polygon"
	Rectangle Shape = "rectangle"
)

type Sizer

type Sizer interface {
	Size() int64
}

Sizer is interface that determine structure size itself.

type Store

type Store[T any] struct {
	Puid Puid_t `xorm:"pk" json:"puid" yaml:"puid" xml:"puid,attr"`
	Prop T      `xorm:"extends" json:"prop" yaml:"prop" xml:"prop"`
}

Store is struct of sqlite3 item for cache with puid/T values.

type StoreBuf

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

func (*StoreBuf) Flush

func (sb *StoreBuf) Flush(session *Session) (err error)

func (*StoreBuf) Init

func (sb *StoreBuf) Init(limit int)

func (*StoreBuf) Push

func (sb *StoreBuf) Push(session *Session, val any) (err error)

type TM_t

type TM_t int

type TempCell

type TempCell[T any] struct {
	Data *T
	Wait *time.Timer
}

type ThumbPath

type ThumbPath Puid_t

ThumbPath is thumbnail path type for cache processing.

func (ThumbPath) Cache

func (puid ThumbPath) Cache()

Cache is Cacher implementation for ThumbPath type.

type TilePath

type TilePath struct {
	Puid Puid_t
	Wdh  int
	Hgt  int
}

TilePath is tile path type for cache processing.

func (TilePath) Cache

func (tile TilePath) Cache()

Cache is Cacher implementation for TilePath type.

type TileProp

type TileProp struct {
	MTmbVal Mime_t `json:"mtmb" yaml:"mtmb" xml:"mtmb"`
	MT02Val Mime_t `json:"mt02,omitempty" yaml:"mt02,omitempty" xml:"mt02,omitempty"`
	MT03Val Mime_t `json:"mt03,omitempty" yaml:"mt03,omitempty" xml:"mt03,omitempty"`
	MT04Val Mime_t `json:"mt04,omitempty" yaml:"mt04,omitempty" xml:"mt04,omitempty"`
	MT06Val Mime_t `json:"mt06,omitempty" yaml:"mt06,omitempty" xml:"mt06,omitempty"`
	MT08Val Mime_t `json:"mt08,omitempty" yaml:"mt08,omitempty" xml:"mt08,omitempty"`
	MT09Val Mime_t `json:"mt09,omitempty" yaml:"mt09,omitempty" xml:"mt09,omitempty"`
	MT10Val Mime_t `json:"mt10,omitempty" yaml:"mt10,omitempty" xml:"mt10,omitempty"`
	MT12Val Mime_t `json:"mt12,omitempty" yaml:"mt12,omitempty" xml:"mt12,omitempty"`
	MT15Val Mime_t `json:"mt15,omitempty" yaml:"mt15,omitempty" xml:"mt15,omitempty"`
	MT16Val Mime_t `json:"mt16,omitempty" yaml:"mt16,omitempty" xml:"mt16,omitempty"`
	MT18Val Mime_t `json:"mt18,omitempty" yaml:"mt18,omitempty" xml:"mt18,omitempty"`
	MT20Val Mime_t `json:"mt20,omitempty" yaml:"mt20,omitempty" xml:"mt20,omitempty"`
	MT24Val Mime_t `json:"mt24,omitempty" yaml:"mt24,omitempty" xml:"mt24,omitempty"`
	MT30Val Mime_t `json:"mt30,omitempty" yaml:"mt30,omitempty" xml:"mt30,omitempty"`
	MT36Val Mime_t `json:"mt36,omitempty" yaml:"mt36,omitempty" xml:"mt36,omitempty"`
}

TileProp is thumbnails properties.

func (*TileProp) SetTile

func (tp *TileProp) SetTile(tm TM_t, mime Mime_t) (ok bool)

SetTile updates image state to given value for tile with given tile multiplier.

func (*TileProp) Tile

func (tp *TileProp) Tile(tm TM_t) (mime Mime_t, ok bool)

Tile returns image MIME type with given tile multiplier.

type Track

type Track struct {
	Title    string
	Location string
	Duration int64 // duration in milliseconds
}

type Unix_t

type Unix_t uint64

Unix_t is UNIX time in milliseconds.

func UnixJS

func UnixJS(u time.Time) Unix_t

UnixJS converts time to UNIX-time in milliseconds, compatible with javascript time format.

func UnixJSNow

func UnixJSNow() Unix_t

UnixJSNow returns same result as Date.now() in javascript.

func (*Unix_t) FromDB

func (ut *Unix_t) FromDB(b []byte) (err error)

FromDB is Conversion interface implementation for XORM engine.

func (Unix_t) MarshalJSON

func (ut Unix_t) MarshalJSON() ([]byte, error)

MarshalJSON is JSON marshaler interface implementation.

func (Unix_t) MarshalXML

func (ut Unix_t) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML is XML marshaler interface implementation.

func (Unix_t) MarshalYAML

func (ut Unix_t) MarshalYAML() (any, error)

MarshalYAML is YAML marshaler interface implementation.

func (Unix_t) String

func (ut Unix_t) String() string

func (Unix_t) Time

func (ut Unix_t) Time() time.Time

func (Unix_t) ToDB

func (ut Unix_t) ToDB() ([]byte, error)

ToDB is Conversion interface implementation for XORM engine.

func (*Unix_t) UnmarshalJSON

func (ut *Unix_t) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON is JSON unmarshaler interface implementation.

func (*Unix_t) UnmarshalXML

func (ut *Unix_t) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML is XML unmarshaler interface implementation.

func (*Unix_t) UnmarshalYAML

func (ut *Unix_t) UnmarshalYAML(value *yaml.Node) (err error)

UnmarshalYAML is YAML unmarshaler interface implementation.

type Wpl

type Wpl struct {
	XMLName xml.Name `xml:"smil"`
	Text    string   `xml:",chardata"`
	Head    struct {
		Text  string    `xml:",chardata"`
		Meta  []WplMeta `xml:"meta"`
		Title string    `xml:"title"`
	} `xml:"head"`
	Body struct {
		Text string `xml:",chardata"`
		Seq  struct {
			Text  string     `xml:",chardata"`
			Media []WplMedia `xml:"media"`
		} `xml:"seq"`
	} `xml:"body"`
}

type WplMedia

type WplMedia struct {
	Text string `xml:",chardata"`
	Src  string `xml:"src,attr"`
	Tid  string `xml:"tid,attr,omitempty"`
}

type WplMeta

type WplMeta struct {
	Text    string `xml:",chardata"`
	Name    string `xml:"name,attr"`
	Content string `xml:"content,attr"`
}

type Xspf

type Xspf struct {
	XMLName xml.Name    `xml:"playlist"`
	Text    string      `xml:",chardata"`
	Version string      `xml:"version,attr"`
	Xmlns   string      `xml:"xmlns,attr"`
	Title   string      `xml:"title,omitempty"`
	Track   []XspfTrack `xml:"trackList>track"`
}

https://www.xspf.org/

type XspfTrack

type XspfTrack struct {
	Text     string `xml:",chardata"`
	Location string `xml:"location"`
	Title    string `xml:"title,omitempty"`
	Duration int64  `xml:"duration,omitempty"`
}

type YamlReadWriter

type YamlReadWriter interface {
	ReadYaml(string) error
	WriteYaml(string) error
}

YamlReadWriter allows to get common access to all structures with reading/writing itself to YAML-file.

Jump to

Keyboard shortcuts

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