2023-02-10 15:53:01 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
2024-01-16 20:56:43 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/api"
|
2023-02-10 15:53:01 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2024-01-10 12:21:43 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/header"
|
2023-02-10 15:53:01 +01:00
|
|
|
)
|
|
|
|
|
2024-01-10 12:46:00 +01:00
|
|
|
// registerPWARoutes adds routes for bootstrapping and configuring the progressive web app user interface.
|
2023-02-10 15:53:01 +01:00
|
|
|
func registerPWARoutes(router *gin.Engine, conf *config.Config) {
|
|
|
|
// Loads Progressive Web App (PWA) on all routes beginning with "library".
|
|
|
|
pwa := func(c *gin.Context) {
|
2024-01-16 16:17:16 +01:00
|
|
|
// Prevent CDNs from caching this endpoint.
|
|
|
|
if header.IsCdn(c.Request) {
|
2024-01-16 20:56:43 +01:00
|
|
|
api.AbortNotFound(c)
|
2024-01-16 16:17:16 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-10 15:53:01 +01:00
|
|
|
values := gin.H{
|
|
|
|
"signUp": gin.H{"message": config.MsgSponsor, "url": config.SignUpURL},
|
|
|
|
"config": conf.ClientPublic(),
|
|
|
|
}
|
|
|
|
c.HTML(http.StatusOK, conf.TemplateName(), values)
|
|
|
|
}
|
|
|
|
router.Any(conf.BaseUri("/library/*path"), pwa)
|
|
|
|
|
|
|
|
// Progressive Web App (PWA) Manifest.
|
|
|
|
manifest := func(c *gin.Context) {
|
2024-01-10 12:21:43 +01:00
|
|
|
c.Header(header.CacheControl, header.CacheControlNoStore)
|
2024-01-17 14:16:02 +01:00
|
|
|
c.Header(header.ContentType, header.ContentTypeJsonUtf8)
|
2023-02-10 15:53:01 +01:00
|
|
|
c.IndentedJSON(200, conf.AppManifest())
|
|
|
|
}
|
|
|
|
router.Any(conf.BaseUri("/manifest.json"), manifest)
|
|
|
|
|
|
|
|
// Progressive Web App (PWA) Service Worker.
|
|
|
|
swWorker := func(c *gin.Context) {
|
2024-01-10 12:21:43 +01:00
|
|
|
c.Header(header.CacheControl, header.CacheControlNoStore)
|
2023-02-10 15:53:01 +01:00
|
|
|
c.File(filepath.Join(conf.BuildPath(), "sw.js"))
|
|
|
|
}
|
|
|
|
router.Any("/sw.js", swWorker)
|
|
|
|
|
|
|
|
if swUri := conf.BaseUri("/sw.js"); swUri != "/sw.js" {
|
|
|
|
router.Any(swUri, swWorker)
|
|
|
|
}
|
|
|
|
}
|