Implement web punt

This commit is contained in:
Tim Van Baak 2025-02-06 20:14:54 -08:00
parent bc9f2847a1
commit 9fa1fd99be
4 changed files with 30 additions and 1 deletions

View File

@ -97,7 +97,7 @@ Instead, the web interface can be locked behind a password set via `intake passw
Parity features Parity features
* [x] web feed supports item TTS * [x] web feed supports item TTS
* [ ] item punt * [x] item punt
* [ ] web feed paging * [ ] web feed paging
* [ ] web fetch * [ ] web fetch
* [ ] set a working directory for item actions * [ ] set a working directory for item actions

View File

@ -9,6 +9,10 @@
<button <button
class="item-button" class="item-button"
title="Punt {{ .Source }}/{{ .Id }}" title="Punt {{ .Source }}/{{ .Id }}"
hx-target="closest article"
hx-select="article"
hx-disabled-elt="this"
hx-patch="/item/{{ .Source }}/{{ .Id }}/punt"
>&#8631;</button> >&#8631;</button>
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">&#8663;</a> {{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">&#8663;</a>
{{ end -}} {{ end -}}

View File

@ -40,6 +40,30 @@ func (env *Env) deleteItem(writer http.ResponseWriter, req *http.Request) {
html.Item(writer, html.ItemData{Item: item}) html.Item(writer, html.ItemData{Item: item})
} }
func (env *Env) puntItem(writer http.ResponseWriter, req *http.Request) {
source := req.PathValue("source")
id := req.PathValue("id")
item, err := core.GetItem(env.db, source, id)
if err != nil {
http.Error(writer, err.Error(), 500)
return
}
now := time.Now()
tomorrow := now.Add(time.Hour * 60)
morning := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), 6, 0, 0, 0, time.UTC)
til_then := int(morning.Unix()) - item.Created
item.Tts = til_then
if err := core.UpdateItems(env.db, []core.Item{item}); err != nil {
http.Error(writer, err.Error(), 500)
return
}
html.Item(writer, html.ItemData{Item: item})
}
func (env *Env) doAction(writer http.ResponseWriter, req *http.Request) { func (env *Env) doAction(writer http.ResponseWriter, req *http.Request) {
source := req.PathValue("source") source := req.PathValue("source")
id := req.PathValue("id") id := req.PathValue("id")

View File

@ -43,6 +43,7 @@ func RunServer(db core.DB, addr string, port string) {
handleFunc("GET /item/{source}/{id}", env.getItem, env.authed, logged) handleFunc("GET /item/{source}/{id}", env.getItem, env.authed, logged)
handleFunc("DELETE /item/{source}/{id}", env.deleteItem, env.authed, logged) handleFunc("DELETE /item/{source}/{id}", env.deleteItem, env.authed, logged)
handleFunc("POST /item/{source}/{id}/action/{action}", env.doAction, env.authed, logged) handleFunc("POST /item/{source}/{id}/action/{action}", env.doAction, env.authed, logged)
handleFunc("PATCH /item/{source}/{id}/punt", env.puntItem, env.authed, logged)
handleFunc("POST /mass-deactivate", env.massDeactivate, env.authed, logged) handleFunc("POST /mass-deactivate", env.massDeactivate, env.authed, logged)
log.Fatal(http.ListenAndServe(bind, nil)) log.Fatal(http.ListenAndServe(bind, nil))