Files
lash/internal/handlers/file.go
vxclutch 7ee19a2883 save
2026-05-27 18:52:37 -04:00

40 lines
758 B
Go

package handlers
import (
"encoding/json"
"lash"
"strconv"
"net/http"
)
type FileData struct {
Contents []byte
}
type ValidateRequest struct {
Token string
}
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 {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if t.Token != lash.Token {
http.Error(w, "Invalid Token", http.StatusUnauthorized)
return
}
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)
}