PWA: Add fs constants for "assets.json" and "manifest.json" #5274

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-10-18 09:23:53 +02:00
parent 5bfa9803f1
commit 627acaf64e
5 changed files with 15 additions and 9 deletions

View File

@@ -7,6 +7,8 @@ import (
"html/template" "html/template"
"os" "os"
"path/filepath" "path/filepath"
"github.com/photoprism/photoprism/pkg/fs"
) )
// ClientAssets holds hashed frontend asset filenames emitted by the build pipeline. // ClientAssets holds hashed frontend asset filenames emitted by the build pipeline.
@@ -137,9 +139,9 @@ func (a *ClientAssets) readFile(fileName string) string {
func (c *Config) ClientAssets() *ClientAssets { func (c *Config) ClientAssets() *ClientAssets {
result := NewClientAssets(c.StaticBuildPath(), c.StaticUri()) result := NewClientAssets(c.StaticBuildPath(), c.StaticUri())
if err := result.Load("assets.json"); err != nil { if err := result.Load(fs.AssetsJsonFile); err != nil {
log.Debugf("frontend: %s", err) log.Debugf("frontend: %s", err)
log.Errorf("frontend: cannot read assets.json") log.Errorf("frontend: cannot read %s", fs.AssetsJsonFile)
} }
return result return result
@@ -147,5 +149,5 @@ func (c *Config) ClientAssets() *ClientAssets {
// ClientManifestUri returns the frontend manifest.json URI. // ClientManifestUri returns the frontend manifest.json URI.
func (c *Config) ClientManifestUri() string { func (c *Config) ClientManifestUri() string {
return fmt.Sprintf("%s?%x", c.BaseUri("/manifest.json"), c.VersionChecksum()) return fmt.Sprintf("%s?%x", c.BaseUri("/"+fs.ManifestJsonFile), c.VersionChecksum())
} }

View File

@@ -6,6 +6,8 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/photoprism/photoprism/pkg/fs"
) )
func TestClientAssets_Load(t *testing.T) { func TestClientAssets_Load(t *testing.T) {
@@ -15,7 +17,7 @@ func TestClientAssets_Load(t *testing.T) {
testBuildPath := "testdata/static/build" testBuildPath := "testdata/static/build"
a := NewClientAssets(testBuildPath, c.StaticUri()) a := NewClientAssets(testBuildPath, c.StaticUri())
err := a.Load("assets.json") err := a.Load(fs.AssetsJsonFile)
assert.NoError(t, err) assert.NoError(t, err)
@@ -36,7 +38,7 @@ func TestClientAssets_Load(t *testing.T) {
testBuildPath := "testdata/foo" testBuildPath := "testdata/foo"
a := NewClientAssets(testBuildPath, c.StaticUri()) a := NewClientAssets(testBuildPath, c.StaticUri())
err := a.Load("assets.json") err := a.Load(fs.AssetsJsonFile)
assert.Error(t, err) assert.Error(t, err)

View File

@@ -84,7 +84,7 @@ func TestWebAppRoutes(t *testing.T) {
}) })
t.Run("GetManifest", func(t *testing.T) { t.Run("GetManifest", func(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/manifest.json", nil) req, _ := http.NewRequest("GET", "/"+fs.ManifestJsonFile, nil)
r.ServeHTTP(w, req) r.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code) assert.Equal(t, 200, w.Code)
assert.NotEmpty(t, w.Body.String()) assert.NotEmpty(t, w.Body.String())

View File

@@ -51,7 +51,7 @@ func registerWebAppRoutes(router *gin.Engine, conf *config.Config) {
} }
// Web App Manifest (served at /manifest.json under the base URI). // Web App Manifest (served at /manifest.json under the base URI).
router.Any(conf.BaseUri("/manifest.json"), manifest) router.Any(conf.BaseUri("/"+fs.ManifestJsonFile), manifest)
// Serve user interface service worker file. // Serve user interface service worker file.
swWorker := func(c *gin.Context) { swWorker := func(c *gin.Context) {

View File

@@ -41,6 +41,8 @@ const (
// Common file names used across packages (sorted by name). // Common file names used across packages (sorted by name).
const ( const (
AppJsFile = "app.js" AppJsFile = "app.js"
SwJsFile = "sw.js" AssetsJsonFile = "assets.json"
ManifestJsonFile = "manifest.json"
SwJsFile = "sw.js"
) )