From 12d6e57d736fb8f349306efa728bd7561645aaa7 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 7 Nov 2019 16:50:37 -0500 Subject: [PATCH] add a limited /api for the robotrons --- docs/changelog.txt | 4 ++++ go.mod | 2 +- go.sum | 4 ++-- web.go | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 7e963c7..e3d05bf 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,5 +1,9 @@ changelog +-- next + ++ Add a limited /api for the robotrons. + -- 0.8.1 ++ Make it easier to upgrade by decoupling data dir from ".". diff --git a/go.mod b/go.mod index ff88420..bd40416 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 golang.org/x/net v0.0.0-20190620200207-3b0461eec859 humungus.tedunangst.com/r/go-sqlite3 v1.1.3 - humungus.tedunangst.com/r/webs v0.6.21 + humungus.tedunangst.com/r/webs v0.6.23 ) go 1.11 diff --git a/go.sum b/go.sum index 333974f..b0ac814 100644 --- a/go.sum +++ b/go.sum @@ -34,5 +34,5 @@ gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 h1:FVCohIoYO7IJoDDVpV2pdq7SgrMH6wHnuTyrdr gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw= humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI= humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= -humungus.tedunangst.com/r/webs v0.6.21 h1:bxI4ZFpxSZw06AbQsaTii5011wjxceF2MOfqJrFnM/w= -humungus.tedunangst.com/r/webs v0.6.21/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= +humungus.tedunangst.com/r/webs v0.6.23 h1:t1VxbiyXYTPQSad/cAJ/+ph1h02yfu+1FwXp8SWt8JY= +humungus.tedunangst.com/r/webs v0.6.23/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= diff --git a/web.go b/web.go index 0a92020..6e7cd9d 100644 --- a/web.go +++ b/web.go @@ -1913,6 +1913,18 @@ func webhydra(w http.ResponseWriter, r *http.Request) { } } +func apihandler(w http.ResponseWriter, r *http.Request) { + u := login.GetUserInfo(r) + action := r.FormValue("action") + log.Printf("api request '%s' on behalf of %s", action, u.Username) + switch action { + case "honk": + submithonk(w, r) + default: + http.Error(w, "unknown action", http.StatusNotFound) + } +} + func serve() { db := opendatabase() login.Init(db) @@ -1953,6 +1965,8 @@ func serve() { mux := mux.NewRouter() mux.Use(login.Checker) + mux.Handle("/api", login.TokenRequired(http.HandlerFunc(apihandler))) + posters := mux.Methods("POST").Subrouter() getters := mux.Methods("GET").Subrouter()