photoprism/pkg/media/report.go
Michael Mayer 92e6c4fe1e Download: Add Disabled, Originals, MediaRaw & MediaSidecar Flags #2234
Extends DownloadSettings with 4 additional options:
- Name: File name pattern for downloaded files (existed)
- Disabled: Disables downloads
- Originals: Only download files stored in "originals" folder
- MediaRaw: Include RAW image files
- MediaSidecar: Include metadata sidecar files (JSON, XMP, YAML)
2022-04-15 09:42:07 +02:00

77 lines
1.2 KiB
Go

package media
import (
"sort"
"strings"
"unicode"
"github.com/photoprism/photoprism/pkg/fs"
)
// Report returns a file format documentation table.
func Report(m fs.TypesExt, withDesc, withType, withExt bool) (rows [][]string, cols []string) {
cols = make([]string, 0, 4)
cols = append(cols, "Format")
t := 0
if withDesc {
cols = append(cols, "Description")
}
if withType {
if withDesc {
t = 2
} else {
t = 1
}
cols = append(cols, "Type")
}
if withExt {
cols = append(cols, "Extensions")
}
rows = make([][]string, 0, len(m))
ucFirst := func(str string) string {
for i, v := range str {
return string(unicode.ToUpper(v)) + str[i+1:]
}
return ""
}
for f, ext := range m {
sort.Slice(ext, func(i, j int) bool {
return ext[i] < ext[j]
})
v := make([]string, 0, 4)
v = append(v, strings.ToUpper(f.String()))
if withDesc {
v = append(v, fs.TypeInfo[f])
}
if withType {
v = append(v, ucFirst(string(Formats[f])))
}
if withExt {
v = append(v, strings.Join(ext, ", "))
}
rows = append(rows, v)
}
sort.Slice(rows, func(i, j int) bool {
if t > 0 && rows[i][t] == rows[j][t] {
return rows[i][0] < rows[j][0]
} else {
return rows[i][t] < rows[j][t]
}
})
return rows, cols
}