1.0 version

This commit is contained in:
vxclutch
2026-05-27 19:00:09 -04:00
parent 7ee19a2883
commit 1234288e03
6 changed files with 70 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ import (
"lash/internal/errx" "lash/internal/errx"
"lash/internal/handlers" "lash/internal/handlers"
"net/http" "net/http"
"os"
) )
func New() http.Handler { func New() http.Handler {
@@ -15,12 +16,19 @@ func New() http.Handler {
errx.FatalPerror(err) errx.FatalPerror(err)
} }
share := handlers.ShareData{ contents, err := os.ReadFile(fp)
Version: lash.Version, if err != nil {
FileName: fp, errx.FatalPerror(err)
} }
file := handlers.FileData{} share := handlers.ShareData{
Version: lash.Version,
}
file := handlers.FileData{
Contents: contents,
FileName: fp,
}
mux.HandleFunc("/", share.Handler) mux.HandleFunc("/", share.Handler)
mux.HandleFunc("/api/receive-token", file.APIHandler) mux.HandleFunc("/api/receive-token", file.APIHandler)

View File

@@ -2,13 +2,15 @@ package handlers
import ( import (
"encoding/json" "encoding/json"
"fmt"
"lash" "lash"
"strconv"
"net/http" "net/http"
"strconv"
) )
type FileData struct { type FileData struct {
Contents []byte Contents []byte
FileName string
} }
type ValidateRequest struct { type ValidateRequest struct {
@@ -30,7 +32,7 @@ func (h FileData) APIHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
w.Header().Set("Content-Disposition", "attachment; filename=file.bin") w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", h.FileName))
w.Header().Set("Content-Type", "application/octet-stream") w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Length", strconv.Itoa(len(h.Contents))) w.Header().Set("Content-Length", strconv.Itoa(len(h.Contents)))

View File

@@ -34,6 +34,7 @@
return; return;
} }
try {
const response = await fetch('/api/receive-token', { const response = await fetch('/api/receive-token', {
method: 'POST', method: 'POST',
headers: { headers: {
@@ -41,6 +42,36 @@
}, },
body: JSON.stringify({ token }) body: JSON.stringify({ token })
}); });
if (!response.ok) {
status.textContent = 'Download failed.';
return;
}
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
const disposition = response.headers.get('Content-Disposition');
let filename = 'download.bin';
if (disposition && disposition.includes('filename=')) {
filename = disposition
.split('filename=')[1]
.replace(/"/g, '');
}
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
status.textContent = 'Download started.';
} catch (err) {
console.error(err);
status.textContent = 'An error occurred.';
}
}); });
</script> </script>
</body> </body>

5
todo Normal file
View File

@@ -0,0 +1,5 @@
maint: clean up source code
maint: comment source code
maint: document more
feat: improve flags
feat: replace uuid dep with custom id generator

View File

@@ -1 +1 @@
0.1.0 1.0.0