From 7ee19a288326bad654ac8aaa605cb3b7d3c9f4a6 Mon Sep 17 00:00:00 2001 From: vxclutch Date: Wed, 27 May 2026 18:52:37 -0400 Subject: [PATCH] save --- internal/handlers/file.go | 20 ++++++++------ lash.go | 5 ++-- templates/share.html | 55 +++++++++++++++++++++++++++++---------- 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/internal/handlers/file.go b/internal/handlers/file.go index 1c40337..ca9b78e 100644 --- a/internal/handlers/file.go +++ b/internal/handlers/file.go @@ -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) } diff --git a/lash.go b/lash.go index a019efa..0931b3b 100644 --- a/lash.go +++ b/lash.go @@ -3,7 +3,7 @@ package lash import ( "embed" - // "github.com/google/uuid" + "github.com/google/uuid" ) //go:embed templates/*.html @@ -12,5 +12,4 @@ var Templates embed.FS //go:embed version var Version string -// var Token string = uuid.New().String() -var Token string = "foo" +var Token string = uuid.New().String() diff --git a/templates/share.html b/templates/share.html index 52e7899..41bc86d 100644 --- a/templates/share.html +++ b/templates/share.html @@ -1,20 +1,47 @@ - - - -Lash v{{.Version}} - + + + + Lash v{{.Version}} + - - + +

Enter Token

- + + + +

+ + +