2021-09-22 03:08:34 +00:00
|
|
|
package static
|
|
|
|
|
2023-10-16 03:26:34 +00:00
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/fs"
|
|
|
|
)
|
2021-09-22 03:08:34 +00:00
|
|
|
|
2024-07-04 01:36:05 +00:00
|
|
|
//go:embed performer performer_male scene image tag studio group
|
2023-10-16 03:26:34 +00:00
|
|
|
var data embed.FS
|
2021-09-22 03:08:34 +00:00
|
|
|
|
2023-10-16 03:26:34 +00:00
|
|
|
const (
|
|
|
|
Performer = "performer"
|
|
|
|
PerformerMale = "performer_male"
|
2022-10-03 02:01:35 +00:00
|
|
|
|
2023-10-16 03:26:34 +00:00
|
|
|
Scene = "scene"
|
|
|
|
DefaultSceneImage = "scene/scene.svg"
|
2022-10-03 02:01:35 +00:00
|
|
|
|
2023-10-16 03:26:34 +00:00
|
|
|
Image = "image"
|
|
|
|
DefaultImageImage = "image/image.svg"
|
2023-04-17 05:28:32 +00:00
|
|
|
|
2023-10-16 03:26:34 +00:00
|
|
|
Tag = "tag"
|
|
|
|
DefaultTagImage = "tag/tag.svg"
|
2023-04-17 05:28:32 +00:00
|
|
|
|
2023-10-16 03:26:34 +00:00
|
|
|
Studio = "studio"
|
|
|
|
DefaultStudioImage = "studio/studio.svg"
|
|
|
|
|
2024-07-04 01:36:05 +00:00
|
|
|
Group = "group"
|
|
|
|
DefaultGroupImage = "group/group.png"
|
2023-10-16 03:26:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Sub returns an FS rooted at path, using fs.Sub.
|
|
|
|
// It will panic if an error occurs.
|
|
|
|
func Sub(path string) fs.FS {
|
|
|
|
ret, err := fs.Sub(data, path)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("creating static SubFS: %v", err))
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open opens the file at path for reading.
|
|
|
|
// It will panic if an error occurs.
|
|
|
|
func Open(path string) fs.File {
|
|
|
|
f, err := data.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("opening static file: %v", err))
|
|
|
|
}
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadAll returns the contents of the file at path.
|
|
|
|
// It will panic if an error occurs.
|
|
|
|
func ReadAll(path string) []byte {
|
|
|
|
f := Open(path)
|
|
|
|
ret, err := io.ReadAll(f)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("reading static file: %v", err))
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|