From 2e10feff4f4c7b1af39025e2fbb3db8fbc27785a Mon Sep 17 00:00:00 2001 From: Mickael Kerjean Date: Wed, 11 May 2022 22:23:02 +1000 Subject: [PATCH] feature (manifest): generate application manifest server side the app manifest used to be statically generated meaning it would show Filestash whenever user tries to install as an app. Now admin can change that to show something else --- client/index.html | 2 +- client/manifest.json | 21 --------------------- server/ctrl/static.go | 29 +++++++++++++++++++++++++++++ server/main.go | 5 ++--- webpack.config.js | 1 - 5 files changed, 32 insertions(+), 26 deletions(-) delete mode 100644 client/manifest.json diff --git a/client/index.html b/client/index.html index 2cff8645..7194cff8 100644 --- a/client/index.html +++ b/client/index.html @@ -6,7 +6,7 @@ - + diff --git a/client/manifest.json b/client/manifest.json deleted file mode 100644 index 1454b7f6..00000000 --- a/client/manifest.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "Filestash", - "short_name": "Filestash", - "icons": [ - { - "src": "/assets/logo/android-chrome-192x192.png", - "type": "image/png", - "sizes": "192x192" - }, - { - "src": "/assets/logo/android-chrome-512x512.png", - "type": "image/png", - "sizes": "512x512" - } - ], - "theme_color": "#f2f3f5", - "background_color": "#f2f3f5", - "orientation": "any", - "display": "standalone", - "start_url": "/" -} diff --git a/server/ctrl/static.go b/server/ctrl/static.go index 6209b745..d056413d 100644 --- a/server/ctrl/static.go +++ b/server/ctrl/static.go @@ -121,6 +121,35 @@ func AboutHandler(ctx App, res http.ResponseWriter, req *http.Request) { }}) } +func ManifestHandler(ctx App, res http.ResponseWriter, req *http.Request) { + res.WriteHeader(http.StatusFound) + res.Write([]byte(fmt.Sprintf(`{ + "name": "%s", + "short_name": "%s", + "icons": [ + { + "src": "/assets/logo/android-chrome-192x192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "/assets/logo/android-chrome-512x512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "theme_color": "#f2f3f5", + "background_color": "#f2f3f5", + "orientation": "any", + "display": "standalone", + "start_url": "/" +}`, Config.Get("general.name"), Config.Get("general.name")))) +} + +func RobotsHandler(ctx App, res http.ResponseWriter, req *http.Request) { + res.Write([]byte("")) +} + func InitPluginList(code []byte) { listOfPackages := regexp.MustCompile(`github.com/mickael-kerjean/([^\"]+)`).FindAllString(string(code), -1) for _, packageName := range listOfPackages { diff --git a/server/main.go b/server/main.go index 21be8db4..7bb074f5 100644 --- a/server/main.go +++ b/server/main.go @@ -104,9 +104,8 @@ func Init(a *App) { r.HandleFunc("/report", NewMiddlewareChain(ReportHandler, middlewares, *a)).Methods("POST") middlewares = []Middleware{IndexHeaders} r.HandleFunc("/about", NewMiddlewareChain(AboutHandler, middlewares, *a)).Methods("GET") - r.HandleFunc("/robots.txt", func(res http.ResponseWriter, req *http.Request) { - res.Write([]byte("")) - }) + r.HandleFunc("/robots.txt", NewMiddlewareChain(RobotsHandler, []Middleware{}, *a)) + r.HandleFunc("/manifest.json", NewMiddlewareChain(ManifestHandler, []Middleware{}, *a)).Methods("GET") r.HandleFunc("/.well-known/security.txt", NewMiddlewareChain(WellKnownSecurityHandler, []Middleware{}, *a)).Methods("GET") r.HandleFunc("/healthz", NewMiddlewareChain(HealthHandler, []Middleware{}, *a)).Methods("GET") r.HandleFunc("/custom.css", NewMiddlewareChain(CustomCssHandler, []Middleware{}, *a)).Methods("GET") diff --git a/webpack.config.js b/webpack.config.js index f9af9356..c56d21d6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -67,7 +67,6 @@ const config = { }), new CopyWebpackPlugin([ { from: "locales/*.json", to: "assets/" }, - { from: "manifest.json", to: "assets/" }, { from: "worker/*.js", to: "assets/" }, { from: "assets/logo/*" }, { from: "assets/icons/*" },