mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-07-30 01:13:16 -04:00
fix: generate manifest in go backend
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -381,3 +383,85 @@ func asyncCall(e *core.RequestEvent, fn func() *router.ApiError) *router.ApiErro
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func HandlerWebsiteManifest(e *core.RequestEvent) error {
|
||||
scheme := "http"
|
||||
if e.Request.TLS != nil {
|
||||
scheme = "https"
|
||||
}
|
||||
baseUrl := fmt.Sprintf("%s://%s", scheme, e.Request.Host)
|
||||
|
||||
manifest := map[string]any{
|
||||
"name": "UpSnap",
|
||||
"short_name": "UpSnap",
|
||||
"description": "A simple wake on lan web app written with SvelteKit, Go and PocketBase.",
|
||||
"theme_color": "#55BCD9",
|
||||
"background_color": "#55BCD9",
|
||||
"display": "standalone",
|
||||
"scope": baseUrl,
|
||||
"start_url": baseUrl,
|
||||
"icons": []map[string]string{
|
||||
{
|
||||
"src": "/icon_192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "any",
|
||||
},
|
||||
{
|
||||
"src": "/icon_512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "any",
|
||||
},
|
||||
{
|
||||
"src": "/maskable_192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable",
|
||||
},
|
||||
{
|
||||
"src": "/maskable_512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable",
|
||||
},
|
||||
{
|
||||
"src": "/gopher.svg",
|
||||
"sizes": "any",
|
||||
"type": "image/svg+xml",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
publicSettings, err := e.App.FindFirstRecordByFilter("settings_public", "")
|
||||
if err != nil {
|
||||
return writeManifest(e, manifest)
|
||||
}
|
||||
|
||||
// override title if set
|
||||
if title := publicSettings.GetString("website_title"); title != "" {
|
||||
manifest["name"] = title
|
||||
manifest["short_name"] = title
|
||||
}
|
||||
|
||||
// override icons if set
|
||||
if favicon := publicSettings.GetString("favicon"); favicon != "" {
|
||||
|
||||
manifest["icons"] = []map[string]string{
|
||||
{
|
||||
"src": fmt.Sprintf("%s/api/files/settings_public/%s/%s", baseUrl, publicSettings.Id, favicon),
|
||||
"sizes": "any",
|
||||
"purpose": "any",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return writeManifest(e, manifest)
|
||||
}
|
||||
|
||||
func writeManifest(e *core.RequestEvent, manifest map[string]any) error {
|
||||
e.Response.Header().Set("Content-Type", "application/manifest+json")
|
||||
e.Response.Header().Set("Cache-Control", "no-cache, no-store")
|
||||
enc := json.NewEncoder(e.Response)
|
||||
return enc.Encode(manifest)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ func StartPocketBase(distDirFS fs.FS) {
|
||||
se.Router.GET("/api/upsnap/scan", HandlerScan).Bind(apis.RequireSuperuserAuth())
|
||||
se.Router.POST("/api/upsnap/init-superuser", HandlerInitSuperuser) // https://github.com/pocketbase/pocketbase/discussions/6198
|
||||
se.Router.POST("/api/upsnap/validate-cron", HandlerValidateCron)
|
||||
se.Router.GET("/api/upsnap/manifest.webmanifest", HandlerWebsiteManifest)
|
||||
|
||||
if err := importSettings(app); err != nil {
|
||||
return err
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
%sveltekit.head%
|
||||
<script>
|
||||
const darkTheme = 'dim';
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<link rel="manifest" href={backendUrl + 'api/upsnap/manifest.webmanifest'} />
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
href={$settingsPub?.id && $settingsPub?.favicon
|
||||
|
||||
Reference in New Issue
Block a user