Skip to content

Commit

Permalink
client,webserver: basic pattern done #2
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-warrior777 committed Feb 2, 2025
1 parent 68da202 commit d0a6977
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc boo
KeyFile: keyFile,
Language: cfg.Language,
Tor: cfg.Tor,
MainLogFilePath: cfg.LogPath,
}
}

Expand Down
11 changes: 10 additions & 1 deletion client/webserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,16 @@ func (s *WebServer) apiTakeAction(w http.ResponseWriter, r *http.Request) {
}

func (s *WebServer) apiExportAppLogs(w http.ResponseWriter, r *http.Request) {
fmt.Printf("apiExportAppLogs")
fmt.Printf("=== apiExportAppLogs->\n")
w.Header().Set("Content-Disposition", "attachment; filename=bwlogs.zip")
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)

fmt.Printf("=== %s\n", s.mainLogFilePath)

// TODO(warrior) .. get the file ;-)

fmt.Printf("=== <-apiExportAppLogs\n")
}

func (s *WebServer) redeemGameCode(w http.ResponseWriter, r *http.Request) {
Expand Down
1 change: 1 addition & 0 deletions client/webserver/locales/en-us.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,5 @@ var EnUS = map[string]*intl.Translation{
"Wallet Balances": {T: "Wallet Balances"},
"Placements": {T: "Placements"},
"delete_bot": {T: "Delete Bot"},
"export_logs": {T: "Export Logs"},
}
3 changes: 3 additions & 0 deletions client/webserver/site/src/html/settings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<p class="grey">[[[seed_implore_msg]]]</p>
<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]]]
</div>
<div id="gameCodeLink" class="py-3 mb-3 border-bottom pointer hoverbg">
<span class="ico-ticket"></span> [[[Redeem game code]]]
</div>
Expand Down
12 changes: 12 additions & 0 deletions client/webserver/site/src/js/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ export default class SettingsPage extends BasePage {
})
forms.bind(page.exportSeedAuth, page.exportSeedSubmit, () => this.submitExportSeedReq())

Doc.bind(page.exportLogs, 'click', () => this.exportLogs())

Doc.bind(page.gameCodeLink, 'click', () => this.showForm(page.gameCodeForm))
Doc.bind(page.gameCodeSubmit, 'click', () => this.submitGameCode())

Expand Down Expand Up @@ -473,6 +475,16 @@ export default class SettingsPage extends BasePage {
Doc.show(form)
}

async exportLogs () {
console.log('exportLogs->')

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

console.log('exportLogs<-')
}

async submitGameCode () {
const page = this.page
Doc.hide(page.gameCodeErr)
Expand Down
7 changes: 5 additions & 2 deletions client/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ type Config struct {
NoEmbed bool
HttpProf bool
Tor bool
MainLogFilePath string
}

type valStamp struct {
Expand Down Expand Up @@ -276,7 +277,8 @@ type WebServer struct {
bondBufMtx sync.Mutex
bondBuf map[uint32]valStamp

useDEXBranding bool
useDEXBranding bool
mainLogFilePath string
}

// New is the constructor for a new WebServer. CustomSiteDir in the Config can
Expand Down Expand Up @@ -403,6 +405,7 @@ func New(cfg *Config) (*WebServer, error) {
tor: cfg.Tor,
bondBuf: map[uint32]valStamp{},
useDEXBranding: useDEXBranding,
mainLogFilePath: cfg.MainLogFilePath,
}
s.lang.Store(lang)

Expand Down Expand Up @@ -574,7 +577,7 @@ func New(cfg *Config) (*WebServer, error) {
apiAuth.Post("/txhistory", s.apiTxHistory)
apiAuth.Post("/takeaction", s.apiTakeAction)
apiAuth.Post("/redeemgamecode", s.redeemGameCode)
apiAuth.Post("/exportapplogs", s.apiExportAppLogs)
apiAuth.Get("/exportapplog", s.apiExportAppLogs)

apiAuth.Post("/stakestatus", s.apiStakeStatus)
apiAuth.Post("/setvsp", s.apiSetVSP)
Expand Down

0 comments on commit d0a6977

Please sign in to comment.