Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
53
backend/internal/managementasset/assets.go
Normal file
53
backend/internal/managementasset/assets.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package managementasset
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
IndexFile = "index.html"
|
||||
ManagementFile = "management.html"
|
||||
)
|
||||
|
||||
// Source describes the filesystem and entry file used for the management UI.
|
||||
type Source struct {
|
||||
FileSystem http.FileSystem
|
||||
Entry string
|
||||
}
|
||||
|
||||
// Current returns the configured management UI source.
|
||||
func Current() (*Source, error) {
|
||||
if override := strings.TrimSpace(os.Getenv("MANAGEMENT_STATIC_PATH")); override != "" {
|
||||
cleaned := filepath.Clean(override)
|
||||
info, err := os.Stat(cleaned)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !info.IsDir() {
|
||||
return &Source{
|
||||
FileSystem: http.Dir(filepath.Dir(cleaned)),
|
||||
Entry: filepath.Base(cleaned),
|
||||
}, nil
|
||||
}
|
||||
|
||||
entry := IndexFile
|
||||
if _, err = os.Stat(filepath.Join(cleaned, entry)); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
entry = ManagementFile
|
||||
}
|
||||
return &Source{FileSystem: http.Dir(cleaned), Entry: entry}, nil
|
||||
}
|
||||
|
||||
files := embeddedFiles()
|
||||
if files == nil {
|
||||
return nil, fs.ErrNotExist
|
||||
}
|
||||
return &Source{FileSystem: http.FS(files), Entry: IndexFile}, nil
|
||||
}
|
||||
19
backend/internal/managementasset/assets_frontend.go
Normal file
19
backend/internal/managementasset/assets_frontend.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
//go:build frontend
|
||||
|
||||
package managementasset
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
//go:embed dist
|
||||
var frontendFiles embed.FS
|
||||
|
||||
func embeddedFiles() fs.FS {
|
||||
files, err := fs.Sub(frontendFiles, "dist")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return files
|
||||
}
|
||||
9
backend/internal/managementasset/assets_stub.go
Normal file
9
backend/internal/managementasset/assets_stub.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
//go:build !frontend
|
||||
|
||||
package managementasset
|
||||
|
||||
import "io/fs"
|
||||
|
||||
func embeddedFiles() fs.FS {
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in a new issue