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)
}

View File

@@ -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()

View File

@@ -1,20 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lash v{{.Version}}</title>
</head>
<body>
</body>
<h1>Enter Token</h1>
<input
type="text"
id="tokenInput"
placeholder="Enter token"
/>
<button id="submitBtn">
Submit
</button>
<p id="status"></p>
<script>
await fetch('/api/receive-token', {
const tokenInput = document.getElementById('tokenInput');
const submitBtn = document.getElementById('submitBtn');
const status = document.getElementById('status');
submitBtn.addEventListener('click', async () => {
const token = tokenInput.value.trim();
if (!token) {
status.textContent = 'Please enter a token.';
return;
}
const response = await fetch('/api/receive-token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: "foo" })
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ token })
});
});
</script>
</body>
</html>