Implement web punt
This commit is contained in:
parent
bc9f2847a1
commit
9fa1fd99be
@ -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
|
||||||
|
@ -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"
|
||||||
>↷</button>
|
>↷</button>
|
||||||
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">⇗</a>
|
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">⇗</a>
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
24
web/item.go
24
web/item.go
@ -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")
|
||||||
|
@ -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))
|
||||||
|
Loading…
Reference in New Issue
Block a user