snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
93
server/assets/embed.go
Normal file
93
server/assets/embed.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed src/*
|
||||
ff embed.FS
|
||||
)
|
||||
|
||||
// Files return files from assets path or falls back to embedded files
|
||||
//
|
||||
// @todo try to find a way to merge this with auth/assets
|
||||
func Files(log *zap.Logger, aPath string) (files fs.FS) {
|
||||
var err error
|
||||
if len(aPath) > 0 {
|
||||
if files, err = fromPath(aPath); err != nil {
|
||||
// log warning but fallback to embedded assets
|
||||
log.Warn(
|
||||
fmt.Sprintf("failed to use custom assets path (HTTP_SERVER_ASSETS_PATH=%s)", aPath),
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if files == nil {
|
||||
aPath = "embedded"
|
||||
files, err = fs.Sub(ff, "src")
|
||||
if err != nil {
|
||||
// something is seriously wrong, we might as well panic
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func fromPath(path string) (assets fs.FS, err error) {
|
||||
// at least icon file should exist in the custom asset path
|
||||
// otherwise we default to embedded files
|
||||
const check = "icon.svg"
|
||||
|
||||
var (
|
||||
fi os.FileInfo
|
||||
)
|
||||
|
||||
if fi, err = os.Stat(path); err != nil {
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
if !fi.IsDir() {
|
||||
return nil, fmt.Errorf("expecting directory")
|
||||
}
|
||||
|
||||
assets = os.DirFS(path)
|
||||
if _, err = assets.Open(check); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func DirEntries(dir string) (fileNames, subDirs []string, err error) {
|
||||
dirEntries, err := fs.ReadDir(ff, path.Join("src", dir))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
for _, dirEntry := range dirEntries {
|
||||
fileInfo, err := dirEntry.Info()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// if the entry is a directory skip it
|
||||
if fileInfo.IsDir() {
|
||||
subDirs = append(subDirs, dirEntry.Name())
|
||||
continue
|
||||
}
|
||||
|
||||
fileNames = append(fileNames, dirEntry.Name())
|
||||
}
|
||||
|
||||
return fileNames, subDirs, err
|
||||
}
|
||||
Reference in New Issue
Block a user