Add source from web
This commit is contained in:
parent
c22ab7b5b4
commit
7c4e5683c4
@ -122,7 +122,7 @@ Instead, the web interface can be locked behind a password set via `intake passw
|
|||||||
Parity features
|
Parity features
|
||||||
|
|
||||||
* [ ] source batching
|
* [ ] source batching
|
||||||
* [ ] web source add
|
* [x] web source add
|
||||||
* [x] first-party replacement for cron
|
* [x] first-party replacement for cron
|
||||||
* [x] NixOS module
|
* [x] NixOS module
|
||||||
* [x] NixOS vm demo
|
* [x] NixOS vm demo
|
||||||
|
@ -45,6 +45,13 @@
|
|||||||
{{ else }}
|
{{ else }}
|
||||||
<p>No sources found.</p>
|
<p>No sources found.</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
<p>
|
||||||
|
<form method="post" action="/source">
|
||||||
|
<label for="name">Add source:</label>
|
||||||
|
<input name="name" type="text">
|
||||||
|
<input type="submit">
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
</details>
|
</details>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ func RunServer(db core.DB, addr string, port string) error {
|
|||||||
handleFunc("GET /style.css", env.getStyle, logged)
|
handleFunc("GET /style.css", env.getStyle, logged)
|
||||||
handleFunc("GET /htmx.org@2.0.4.js", env.getScript, logged)
|
handleFunc("GET /htmx.org@2.0.4.js", env.getScript, logged)
|
||||||
handleFunc("POST /login", env.login, 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}", env.getSource, env.authed, logged)
|
||||||
handleFunc("GET /source/{source}/edit", env.getEditSource, env.authed, logged)
|
handleFunc("GET /source/{source}/edit", env.getEditSource, env.authed, logged)
|
||||||
handleFunc("POST /source/{source}/edit", env.editSource, env.authed, logged)
|
handleFunc("POST /source/{source}/edit", env.editSource, env.authed, logged)
|
||||||
|
@ -162,3 +162,16 @@ func (env *Env) editSource(writer http.ResponseWriter, req *http.Request) {
|
|||||||
writer.Header()["HX-Refresh"] = []string{"true"}
|
writer.Header()["HX-Refresh"] = []string{"true"}
|
||||||
writer.WriteHeader(http.StatusNoContent)
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user