From c4de82bf63001ae341aba1c4ee1a617c6a295654 Mon Sep 17 00:00:00 2001 From: dev-warrior777 <> Date: Wed, 29 Jan 2025 23:43:50 +0800 Subject: [PATCH] client,webserver: Make log downloads work in a webview. * Make distinct log file names with a timestamp * Explicitly set browser context to '_self' for a webview. --- client/webserver/api.go | 9 +++++++-- client/webserver/site/src/js/settings.ts | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/client/webserver/api.go b/client/webserver/api.go index c4111192f0..99d58c6a4b 100644 --- a/client/webserver/api.go +++ b/client/webserver/api.go @@ -2045,9 +2045,14 @@ func (s *WebServer) apiTakeAction(w http.ResponseWriter, r *http.Request) { writeJSON(w, simpleAck()) } -// apiExportAppLogs zips the application log and sends it back to the browser. +// apiExportAppLogs time stamps the application log, zips it and sends it back to +// the browser or webview as an attachment. Logfile names need to be distinct as +// webview will not overwite an existing file. func (s *WebServer) apiExportAppLogs(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Disposition", "attachment; filename=bwlog.zip") + timeStamp := time.Now().UnixMilli() + zipAttachment := fmt.Sprintf("attachment; filename=bwlog_%d.zip", timeStamp) + + w.Header().Set("Content-Disposition", zipAttachment) w.Header().Set("Content-Type", "application/octet-stream; type=zip") w.WriteHeader(http.StatusOK) diff --git a/client/webserver/site/src/js/settings.ts b/client/webserver/site/src/js/settings.ts index d2c40bdc8e..a00ce6f994 100644 --- a/client/webserver/site/src/js/settings.ts +++ b/client/webserver/site/src/js/settings.ts @@ -475,10 +475,16 @@ export default class SettingsPage extends BasePage { Doc.show(form) } + /* exportLogs zips the main app log and sends it back as an attachment */ async exportLogs () { const url = new URL(window.location.href) url.pathname = '/api/exportapplog' - window.open(url.toString()) + const target = '_self' + if (window.isWebview !== undefined) { + window.open(url.toString(), target) // explicit + } else { + window.open(url.toString()) + } } async submitGameCode () {