2021-10-11 23:56:00 +02:00
|
|
|
package static
|
|
|
|
|
2021-10-12 00:04:16 +02:00
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"html/template"
|
2021-11-04 00:27:37 +01:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-06-20 01:35:55 +02:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2021-10-12 00:04:16 +02:00
|
|
|
)
|
2021-10-11 23:56:00 +02:00
|
|
|
|
2022-06-20 00:30:32 +02: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.
|
|
|
|
func GetWeb() embed.FS {
|
|
|
|
return webFiles
|
2021-10-11 23:56:00 +02:00
|
|
|
}
|
2021-10-12 00:04:16 +02:00
|
|
|
|
2022-06-20 01:35:55 +02:00
|
|
|
// GetWebIndexTemplate will return the bot/scraper metadata template.
|
|
|
|
func GetWebIndexTemplate() (*template.Template, error) {
|
|
|
|
webFiles := GetWeb()
|
|
|
|
name := "web/index.html"
|
|
|
|
t, err := template.ParseFS(webFiles, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "unable to open index.html template")
|
|
|
|
}
|
2021-10-12 00:04:16 +02:00
|
|
|
|
|
|
|
tmpl := template.Must(t, err)
|
|
|
|
return tmpl, err
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:embed offline.ts
|
|
|
|
var offlineVideoSegment []byte
|
|
|
|
|
|
|
|
// GetOfflineSegment will return the offline video segment data.
|
|
|
|
func GetOfflineSegment() []byte {
|
2021-11-04 00:27:37 +01:00
|
|
|
return getFileSystemStaticFileOrDefault("offline.ts", offlineVideoSegment)
|
|
|
|
}
|
|
|
|
|
|
|
|
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 00:04:16 +02:00
|
|
|
}
|