This commit is contained in:
vxclutch
2026-05-27 18:52:37 -04:00
parent 6da1bb9fc1
commit 7ee19a2883
3 changed files with 55 additions and 25 deletions

View File

@@ -3,7 +3,7 @@ package handlers
import (
"encoding/json"
"lash"
"lash/internal/errx"
"strconv"
"net/http"
)
@@ -17,19 +17,23 @@ type ValidateRequest struct {
func (h FileData) APIHandler(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
var t ValidateRequest
err := decoder.Decode(&t)
if err != nil {
errx.FatalPerror(err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if t.Token == lash.Token {
errx.Log("Got token")
} else {
errx.Log("No Token")
if t.Token != lash.Token {
http.Error(w, "Invalid Token", http.StatusUnauthorized)
return
}
}
func (h FileData) DownloadHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Disposition", "attachment; filename=file.bin")
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Length", strconv.Itoa(len(h.Contents)))
w.WriteHeader(http.StatusOK)
w.Write(h.Contents)
}