Support pre-filling long field

This commit is contained in:
Ian Gulliver
2024-12-02 22:29:01 -08:00
parent eb8b820cb9
commit 695e947e4c
2 changed files with 8 additions and 2 deletions

View File

@@ -76,6 +76,11 @@ func (sl *ShortLinks) serveRoot(w http.ResponseWriter, r *http.Request) {
}
func (sl *ShortLinks) serveRootWithPath(w http.ResponseWriter, r *http.Request, path string) {
err := r.ParseForm()
if err != nil {
sendError(w, http.StatusBadRequest, "Parse form: %s", err)
return
}
log.Printf("%s %s %s %s %s", r.RemoteAddr, r.Method, r.Host, sl.getDomain(r.Host), r.URL)
if !sl.isWritable(r.Host) {
@@ -83,9 +88,10 @@ func (sl *ShortLinks) serveRootWithPath(w http.ResponseWriter, r *http.Request,
return
}
err := sl.tmpl.Execute(w, map[string]any{
err = sl.tmpl.Execute(w, map[string]any{
"path": path,
"host": sl.getDomain(r.Host),
"long": r.Form.Get("long"),
})
if err != nil {
sendError(w, http.StatusInternalServerError, "error executing template: %s", err)

View File

@@ -297,7 +297,7 @@ document.addEventListener('DOMContentLoaded', async () => {
<sl-icon id="short-icon" name="type" slot="suffix"></sl-icon>
</sl-input>
<sl-input id="long" label="⟶" type="url">
<sl-input id="long" value="{{ .long }}" label="⟶" type="url">
<sl-icon id="long-icon" name="type" slot="suffix"></sl-icon>
</sl-input>