Upload logs handler

This commit is contained in:
Ben Sarmiento
2024-01-26 09:52:37 +01:00
parent 96ec870bb2
commit 4852b93c67
2 changed files with 67 additions and 0 deletions

View File

@@ -91,6 +91,8 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
// logs route
router.Get("/logs", hs.logsHandler)
router.Get("/logs/", hs.logsHandler)
router.Get("/logs/upload", hs.uploadLogsHandler)
router.Get("/logs/upload/", hs.uploadLogsHandler)
router.MethodNotAllowed(func(resp http.ResponseWriter, req *http.Request) {
hs.log.Debugf("Method not allowed: %s %s %v", req.Method, req.URL, req.Header)
@@ -453,3 +455,12 @@ func (hs *Handlers) logsHandler(resp http.ResponseWriter, req *http.Request) {
}
fmt.Fprint(resp, logs)
}
func (hs *Handlers) uploadLogsHandler(resp http.ResponseWriter, req *http.Request) {
url, err := hs.log.UploadLogFile()
if err != nil {
http.Error(resp, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(resp, req, url, http.StatusFound)
}