Skip to content

Commit

Permalink
multi: Squash commits.
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-warrior777 committed Feb 2, 2025
1 parent d0a6977 commit 1396cd6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
22 changes: 11 additions & 11 deletions client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc boo
}

return &webserver.Config{
DataDir: filepath.Join(cfg.AppData, "srv"),
Core: c,
MarketMaker: mmCore,
Addr: cfg.WebAddr,
CustomSiteDir: cfg.SiteDir,
Logger: log,
UTC: utc,
CertFile: certFile,
KeyFile: keyFile,
Language: cfg.Language,
Tor: cfg.Tor,
DataDir: filepath.Join(cfg.AppData, "srv"),
Core: c,
MarketMaker: mmCore,
Addr: cfg.WebAddr,
CustomSiteDir: cfg.SiteDir,
Logger: log,
UTC: utc,
CertFile: certFile,
KeyFile: keyFile,
Language: cfg.Language,
Tor: cfg.Tor,
MainLogFilePath: cfg.LogPath,
}
}
Expand Down
35 changes: 29 additions & 6 deletions client/webserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
package webserver

import (
"archive/zip"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"os"
"time"

"decred.org/dcrdex/client/asset"
Expand Down Expand Up @@ -2042,17 +2045,37 @@ func (s *WebServer) apiTakeAction(w http.ResponseWriter, r *http.Request) {
writeJSON(w, simpleAck())
}

// 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) {
fmt.Printf("=== apiExportAppLogs->\n")
w.Header().Set("Content-Disposition", "attachment; filename=bwlogs.zip")
w.Header().Set("Content-Type", "text/plain")
timeString := time.Now().Format("2006-01-02T15_04_05")
zipAttachment := fmt.Sprintf("attachment; filename=bwlog_%s.zip", timeString)

w.Header().Set("Content-Disposition", zipAttachment)
w.Header().Set("Content-Type", "application/octet-stream; type=zip")
w.WriteHeader(http.StatusOK)

fmt.Printf("=== %s\n", s.mainLogFilePath)
zipWriter := zip.NewWriter(w)
defer zipWriter.Close()

lf, err := os.Open(s.mainLogFilePath)
if err != nil {
log.Errorf("error opening bisonw log file: %v", err)
return
}
defer lf.Close()

// TODO(warrior) .. get the file ;-)
iow, err := zipWriter.Create("bwlog.txt") // only 1 file in zip header
if err != nil {
log.Errorf("error creating an io.Writer: %v", err)
return
}

fmt.Printf("=== <-apiExportAppLogs\n")
if _, err := io.Copy(iow, lf); err != nil {
log.Errorf("error copying bisonw log to zip writer: %v", err)
return
}
}

func (s *WebServer) redeemGameCode(w http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 6 additions & 0 deletions client/webserver/site/src/css/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@
display: inline-block;
}

.ico-wide-headed-down-arrow::before {
content: "\e919";
display: inline-block;
transform: rotate(270deg);
}

.ico-arrowup::before {
content: "\e90c";
display: inline-block;
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/html/settings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<button id="exportSeed" class="fs15">[[[View Application Seed]]]</button>
</div>
<div id="exportLogs" class="py-3 mb-3 border-bottom pointer hoverbg">
<span class="ico-arrowdown"></span> [[[export_logs]]]
<span class="ico-wide-headed-down-arrow"></span> [[[export_logs]]]
</div>
<div id="gameCodeLink" class="py-3 mb-3 border-bottom pointer hoverbg">
<span class="ico-ticket"></span> [[[Redeem game code]]]
Expand Down
12 changes: 7 additions & 5 deletions client/webserver/site/src/js/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +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 () {
console.log('exportLogs->')

const url = new URL(window.location.href)
url.pathname = '/api/exportapplog'
window.open(url.toString())

console.log('exportLogs<-')
const target = '_self'
if (window.isWebview !== undefined) {
window.open(url.toString(), target) // explicit
} else {
window.open(url.toString())
}
}

async submitGameCode () {
Expand Down
6 changes: 3 additions & 3 deletions client/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ type Config struct {
// should be used by default since site files from older distributions may
// be present on the disk. When NoEmbed is true, this also implies reloading
// and execution of html templates on each request.
NoEmbed bool
HttpProf bool
Tor bool
NoEmbed bool
HttpProf bool
Tor bool
MainLogFilePath string
}

Expand Down

0 comments on commit 1396cd6

Please sign in to comment.