This commit is contained in:
vxclutch
2026-05-27 08:30:51 -04:00
parent 060200c998
commit 71ffad466b
12 changed files with 175 additions and 66 deletions

19
internal/app/filePath.go Normal file
View File

@@ -0,0 +1,19 @@
package app
import (
"errors"
"os"
"strings"
)
func GetFilePath() (string, error) {
fp := ""
for _, v := range os.Args[1:] {
if !strings.HasPrefix(v, "-") {
fp = v
return fp, nil
}
}
return "", errors.New("not enough arguments")
}

29
internal/app/routes.go Normal file
View File

@@ -0,0 +1,29 @@
package app
import (
"lash"
"lash/internal/errx"
"lash/internal/handlers"
"net/http"
)
func New() http.Handler {
mux := http.NewServeMux()
fp, err := GetFilePath()
if err != nil {
errx.FatalPerror(err)
}
share := handlers.ShareData{
Version: lash.Version,
FileName: fp,
}
file := handlers.FileData{}
mux.HandleFunc("/", share.Handler)
mux.HandleFunc("/api/receive-token", file.APIHandler)
return mux
}

7
internal/errx/error.go Normal file
View File

@@ -0,0 +1,7 @@
package errx
import "fmt"
func Error(err string) {
fmt.Println("error:", "lash:", err)
}

15
internal/errx/perror.go Normal file
View File

@@ -0,0 +1,15 @@
package errx
import (
"fmt"
"os"
)
func Perror(err error) {
fmt.Println("error:", "lash:", err)
}
func FatalPerror(err error) {
Perror(err)
os.Exit(1)
}

7
internal/errx/print.go Normal file
View File

@@ -0,0 +1,7 @@
package errx
import "fmt"
func Log(msg string, k... any) {
fmt.Printf("lash: " + msg + "\n", k...)
}

35
internal/handlers/file.go Normal file
View File

@@ -0,0 +1,35 @@
package handlers
import (
"encoding/json"
"lash"
"lash/internal/errx"
"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 {
errx.FatalPerror(err)
}
if t.Token == lash.Token {
errx.Log("Got token")
} else {
errx.Log("No Token")
}
}
func (h FileData) DownloadHandler(w http.ResponseWriter, r *http.Request) {
w.Write(h.Contents)
}

View File

@@ -0,0 +1,17 @@
package handlers
import (
"html/template"
"lash"
"net/http"
)
type ShareData struct {
Version string
FileName string
}
func (h ShareData) Handler(w http.ResponseWriter, r *http.Request) {
tmpl := template.Must(template.ParseFS(lash.Templates, "share.html"))
tmpl.ExecuteTemplate(w, "share.html", h)
}