save
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user