1
0
mirror of https://github.com/nxshock/gallery.git synced 2024-11-27 00:11:00 +05:00
gallery/itemtype.go
2023-01-08 14:52:16 +05:00

48 lines
661 B
Go

package main
import (
"os"
"path/filepath"
"strings"
)
type ItemType int
const (
Unknown ItemType = iota
Directory
Picture
Video
)
type Path string
type Item struct {
ItemType
Path Path
}
func (p *Path) Base() string {
return filepath.Base(string(*p))
}
func getType(path string) (ItemType, error) {
stat, err := os.Stat(path)
if err != nil {
return Unknown, err
}
if stat.IsDir() {
return Directory, nil
}
switch strings.ToLower(filepath.Ext(path)) {
case ".jpg", ".jpeg", ".png", ".avif", ".bmp", ".gif":
return Picture, nil
case ".mov", ".mp4", ".avi", ".mkv", ".3gp", ".webm":
return Video, nil
}
return Unknown, nil
}