Add source from web

This commit is contained in:
Tim Van Baak 2025-02-20 16:09:29 -08:00
parent c22ab7b5b4
commit 7c4e5683c4
4 changed files with 22 additions and 1 deletions

View File

@ -122,7 +122,7 @@ Instead, the web interface can be locked behind a password set via `intake passw
Parity features
* [ ] source batching
* [ ] web source add
* [x] web source add
* [x] first-party replacement for cron
* [x] NixOS module
* [x] NixOS vm demo

View File

@ -45,6 +45,13 @@
{{ else }}
<p>No sources found.</p>
{{ end }}
<p>
<form method="post" action="/source">
<label for="name">Add source:</label>
<input name="name" type="text">
<input type="submit">
</form>
</p>
</details>
</nav>

View File

@ -39,6 +39,7 @@ func RunServer(db core.DB, addr string, port string) error {
handleFunc("GET /style.css", env.getStyle, logged)
handleFunc("GET /htmx.org@2.0.4.js", env.getScript, logged)
handleFunc("POST /login", env.login, logged)
handleFunc("POST /source", env.addSource, env.authed, logged)
handleFunc("GET /source/{source}", env.getSource, env.authed, logged)
handleFunc("GET /source/{source}/edit", env.getEditSource, env.authed, logged)
handleFunc("POST /source/{source}/edit", env.editSource, env.authed, logged)

View File

@ -162,3 +162,16 @@ func (env *Env) editSource(writer http.ResponseWriter, req *http.Request) {
writer.Header()["HX-Refresh"] = []string{"true"}
writer.WriteHeader(http.StatusNoContent)
}
func (env *Env) addSource(writer http.ResponseWriter, req *http.Request) {
if err := req.ParseForm(); err != nil {
http.Error(writer, err.Error(), 400)
return
}
name := req.PostForm.Get("name")
if err := core.AddSource(env.db, name); err != nil {
http.Error(writer, err.Error(), 500)
return
}
http.Redirect(writer, req, "/source/"+name+"/edit", http.StatusFound)
}