iteminfo

package
v0.0.0-...-da0c8bd Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LargeFileSizeThreshold = 75 * 1024 * 1024 // 75MB
)

Variables

View Source
var AllFiletypeOptions = []string{
	"image",
	"audio",
	"archive",
	"video",
	"doc",
	"text",
}
View Source
var BundleExtensions = map[string]bool{
	".app":       true,
	".bundle":    true,
	".framework": true,
	".plugin":    true,
	".kext":      true,
	".pkg":       true,
	".mpkg":      true,
	".apk":       true,
	".aab":       true,
	".appx":      true,
	".msix":      true,
	".deb":       true,
	".snap":      true,
	".flatpak":   true,
	".dmg":       true,
	".iso":       true,
}

Known bundle-style extensions that are technically directories but treated as files

View Source
var MuPdfConvertable = map[string]bool{
	".pdf":  true,
	".xps":  true,
	".epub": true,
	".mobi": true,
	".fb2":  true,
	".cbz":  true,
	".svg":  true,
	".txt":  true,
	".docx": true,
	".pptx": true,
	".xlsx": true,
	".hwp":  true,
	".hwpx": true,
	".md":   true,
}
View Source
var ONLYOFFICE_READONLY_FILE_EXTENSIONS = map[string]bool{
	"pages":   true,
	"numbers": true,
	"key":     true,
}
View Source
var ResizableImageTypes = map[string]bool{
	".jpg":   true,
	".jpeg":  true,
	".png":   true,
	".gif":   true,
	".bmp":   true,
	".tiff":  true,
	".tif":   true,
	".heic":  true,
	".heif":  true,
	".webp":  true,
	".pbm":   true,
	".pgm":   true,
	".ppm":   true,
	".pam":   true,
	".other": false,
}
View Source
var SubtitleExts = map[string]bool{
	".vtt": true,
	".srt": true,
	".lrc": true,
	".sbv": true,
	".ass": true,
	".ssa": true,
	".sub": true,
	".smi": true,
}

Functions

func CanEditOnlyOffice

func CanEditOnlyOffice(modify bool, extention string) bool

func CouldHaveAlbumArt

func CouldHaveAlbumArt(extension string) bool

func DetectTypeByHeader

func DetectTypeByHeader(realPath string) string

DetectTypeByHeader detects the MIME type of a file based on its header.

func ExtendedMimeTypeCheck

func ExtendedMimeTypeCheck(extension string) string

func HasAlbumArt

func HasAlbumArt(filePath string, extension string) bool

func HasDocConvertableExtension

func HasDocConvertableExtension(name, mimetype string) bool

func Is3DModel

func Is3DModel(extension string) bool

Is3DModel reports whether the extension is a known 3D model format.

func IsArchive

func IsArchive(extension string) bool

func IsDirectory

func IsDirectory(fileInfo os.FileInfo) bool

IsDirectory determines if a path should be treated as a directory. It treats known bundle-style directories as files instead.

func IsDoc

func IsDoc(extension string) bool

func IsMatchingDetectedType

func IsMatchingDetectedType(detectedType string, extension string, matchType string) bool

IsMatchingDetectedType checks if the detected MIME type matches the search type. This uses the actual detected type rather than just the extension, which is more accurate for ambiguous extensions like .ts (TypeScript vs MPEG Transport Stream)

func IsMatchingType

func IsMatchingType(extension string, matchType string) bool

func IsOnlyOffice

func IsOnlyOffice(name string) bool

func IsRawImage

func IsRawImage(extension string) bool

IsRawImage reports whether the extension is a known raw camera image format.

func IsText

func IsText(extension string) bool

func Model3DMimeType

func Model3DMimeType(extension string) string

Model3DMimeType returns the MIME type for a 3D model extension, or "" if not a 3D model.

func RawImageMimeType

func RawImageMimeType(extension string) string

RawImageMimeType returns the MIME type for a raw image extension, or "" if not raw.

func ResolveSymlinks(path string) (string, bool, error)

ResolveSymlinks resolves symlinks in the given path and returns the final resolved path, whether it's a directory (considering bundle logic), and any error.

func ShouldBubbleUpToFolderPreview

func ShouldBubbleUpToFolderPreview(item ItemInfo) bool

ShouldBubbleUpToFolderPreview checks if a file type should be used for folder previews. Only images, videos, and audio files with album art should bubble up. Text files, office documents, and PDFs should NOT bubble up to folder previews. This ensures consistency between indexing and preview generation.

func ToInt

func ToInt(str string) int

func UpdateSize

func UpdateSize(given string) int

Types

type ExtendedFileInfo

type ExtendedFileInfo struct {
	FileInfo
	Content      string                `json:"content,omitempty"`      // text content of a file, if requested
	Subtitles    []utils.SubtitleTrack `json:"subtitles,omitempty"`    // subtitles for video files
	Metadata     *MediaMetadata        `json:"metadata,omitempty"`     // media metadata for audio/video files (includes duration)
	Checksums    map[string]string     `json:"checksums,omitempty"`    // checksums for the file
	Token        string                `json:"token,omitempty"`        // token for the file -- used for sharing
	OnlyOfficeId string                `json:"onlyOfficeId,omitempty"` // id for onlyoffice files
	Source       string                `json:"source,omitempty"`       // associated index source for the file
	Hash         string                `json:"hash,omitempty"`         // hash for the file -- used for sharing
	HasMetadata  bool                  `json:"hasMetadata"`            // whether the file or folder has metadata
	RealPath     string                `json:"-"`
}

for efficiency, a response will be a pointer to the data extra calculated fields can be added here

func (*ExtendedFileInfo) GetSubtitles

func (i *ExtendedFileInfo) GetSubtitles(parentInfo *FileInfo)

GetSubtitles detects external subtitle files for video files. Embedded subtitles should be detected by ffmpeg and passed as embeddedSubs parameter.

type ExtendedItemInfo

type ExtendedItemInfo struct {
	ItemInfo
	Metadata *MediaMetadata `json:"metadata,omitempty"` // optional media metadata (audio/video only)
}

ExtendedItemInfo extends ItemInfo with optional metadata that's only populated on-demand This avoids adding memory overhead to indexed items

type FFProbeOutput

type FFProbeOutput struct {
	Streams []struct {
		Index       int               `json:"index"`
		CodecType   string            `json:"codec_type"`
		CodecName   string            `json:"codec_name"`
		Tags        map[string]string `json:"tags,omitempty"`
		Disposition map[string]int    `json:"disposition,omitempty"`
	} `json:"streams"`
}

type FileInfo

type FileInfo struct {
	ItemInfo
	Files   []ExtendedItemInfo `json:"files,omitempty"`   // files in the directory with optional metadata
	Folders []ItemInfo         `json:"folders,omitempty"` // folders in the directory
	Path    string             `json:"path,omitempty"`    // path scoped to the associated index
}

FileInfo describes a file. reduced item is non-recursive reduced "Items", used to pass flat items array

func (*FileInfo) SortItems

func (info *FileInfo) SortItems()

type ItemInfo

type ItemInfo struct {
	Name       string    `json:"name"`               // name of the file
	Size       int64     `json:"size"`               // length in bytes for regular files
	ModTime    time.Time `json:"modified"`           // modification time
	Type       string    `json:"type"`               // type of the file, either "directory" or a file mimetype
	Hidden     bool      `json:"hidden"`             // whether the file is hidden
	HasPreview bool      `json:"hasPreview"`         // whether the file has a thumbnail preview
	IsShared   bool      `json:"isShared,omitempty"` // whether the file or folder is shared
}

func (ItemInfo) ContainsSearchTerm

func (fi ItemInfo) ContainsSearchTerm(searchTerm string, options SearchOptions) bool

returns true if the file name contains the search term returns file type if the file name contains the search term returns size of file/dir if the file name contains the search term

func (*ItemInfo) DetectType

func (i *ItemInfo) DetectType(realPath string, saveContent bool)

DetectType detects the MIME type of a file and updates the ItemInfo struct.

type MediaMetadata

type MediaMetadata struct {
	Title    string `json:"title,omitempty"`    // track/video title
	Artist   string `json:"artist,omitempty"`   // track artist
	Album    string `json:"album,omitempty"`    // album name
	Year     int    `json:"year,omitempty"`     // release year
	Genre    string `json:"genre,omitempty"`    // music/video genre
	Track    int    `json:"track,omitempty"`    // track number
	Duration int    `json:"duration,omitempty"` // duration in seconds
	AlbumArt []byte `json:"albumArt,omitempty"` // album art image data (automatically base64-encoded in JSON)
}

MediaMetadata contains metadata extracted from audio and video files

type SearchOptions

type SearchOptions struct {
	Conditions  map[string]bool
	LargerThan  int
	SmallerThan int
	Terms       []string
}

func ParseSearch

func ParseSearch(value string) SearchOptions

Jump to

Keyboard shortcuts

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