2021-10-12 00:56:00 +03:00
|
|
|
package static
|
|
|
|
|
2021-10-12 01:04:16 +03:00
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"html/template"
|
2022-06-21 07:43:53 +03:00
|
|
|
"io/fs"
|
|
|
|
"log"
|
2021-11-04 02:27:37 +03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-06-20 02:35:55 +03:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2021-10-12 01:04:16 +03:00
|
|
|
)
|
2021-10-12 00:56:00 +03:00
|
|
|
|
2022-06-20 01:30:32 +03:00
|
|
|
//go:embed web/*
|
|
|
|
//go:embed web/_next/static
|
|
|
|
//go:embed web/_next/static/chunks/pages/*.js
|
|
|
|
//go:embed web/_next/static/*/*.js
|
|
|
|
var webFiles embed.FS
|
|
|
|
|
|
|
|
// GetWeb will return an embedded filesystem reference to the admin web app.
|
2022-06-21 07:43:53 +03:00
|
|
|
func GetWeb() fs.FS {
|
|
|
|
wf, err := fs.Sub(webFiles, "web")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return wf
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:embed img/emoji/*
|
|
|
|
var emojiFiles embed.FS
|
|
|
|
|
|
|
|
// GetEmoji will return the emoji files.
|
|
|
|
func GetEmoji() fs.FS {
|
|
|
|
ef, err := fs.Sub(emojiFiles, "img/emoji")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return ef
|
2021-10-12 00:56:00 +03:00
|
|
|
}
|
2021-10-12 01:04:16 +03:00
|
|
|
|
2022-06-20 02:35:55 +03:00
|
|
|
// GetWebIndexTemplate will return the bot/scraper metadata template.
|
|
|
|
func GetWebIndexTemplate() (*template.Template, error) {
|
|
|
|
webFiles := GetWeb()
|
2022-06-21 07:43:53 +03:00
|
|
|
name := "index.html"
|
2022-06-20 02:35:55 +03:00
|
|
|
t, err := template.ParseFS(webFiles, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "unable to open index.html template")
|
|
|
|
}
|
2021-10-12 01:04:16 +03:00
|
|
|
|
|
|
|
tmpl := template.Must(t, err)
|
|
|
|
return tmpl, err
|
|
|
|
}
|
|
|
|
|
2023-01-27 04:11:38 +03:00
|
|
|
//go:embed offline.tsclip
|
2021-10-12 01:04:16 +03:00
|
|
|
var offlineVideoSegment []byte
|
|
|
|
|
|
|
|
// GetOfflineSegment will return the offline video segment data.
|
|
|
|
func GetOfflineSegment() []byte {
|
2023-01-27 04:11:38 +03:00
|
|
|
return getFileSystemStaticFileOrDefault("offline.tsclip", offlineVideoSegment)
|
2021-11-04 02:27:37 +03:00
|
|
|
}
|
|
|
|
|
2022-06-21 07:43:53 +03:00
|
|
|
//go:embed img/logo.png
|
|
|
|
var logo []byte
|
|
|
|
|
|
|
|
// GetLogo will return the logo data.
|
|
|
|
func GetLogo() []byte {
|
|
|
|
return getFileSystemStaticFileOrDefault("img/logo.png", logo)
|
|
|
|
}
|
|
|
|
|
2021-11-04 02:27:37 +03:00
|
|
|
func getFileSystemStaticFileOrDefault(path string, defaultData []byte) []byte {
|
|
|
|
fullPath := filepath.Join("static", path)
|
|
|
|
data, err := os.ReadFile(fullPath) //nolint: gosec
|
|
|
|
if err != nil {
|
|
|
|
return defaultData
|
|
|
|
}
|
|
|
|
|
|
|
|
return data
|
2021-10-12 01:04:16 +03:00
|
|
|
}
|
2023-08-17 04:19:09 +03:00
|
|
|
|
|
|
|
//go:embed metadata.html.tmpl
|
|
|
|
var botMetadataTemplate embed.FS
|
|
|
|
|
|
|
|
// GetBotMetadataTemplate will return the bot/scraper metadata template.
|
|
|
|
func GetBotMetadataTemplate() (*template.Template, error) {
|
|
|
|
name := "metadata.html.tmpl"
|
|
|
|
t, err := template.ParseFS(botMetadataTemplate, name)
|
|
|
|
tmpl := template.Must(t, err)
|
|
|
|
return tmpl, err
|
|
|
|
}
|