initial steps towards fetch tracking

This commit is contained in:
Ted Unangst 2019-11-08 14:50:57 -05:00
parent 307d23e3d2
commit 797685377d
4 changed files with 19 additions and 1 deletions

View File

@ -12,6 +12,7 @@ create table doovers(dooverid integer primary key, dt text, tries integer, useri
create table onts (ontology text, honkid integer);
create table honkmeta (honkid integer, genus text, json text);
create table hfcs (hfcsid integer primary key, userid integer, json text);
create table tracks (xid text, fetches text);
create index idx_honksxid on honks(xid);
create index idx_honksconvoy on honks(convoy);
@ -26,6 +27,7 @@ create index idx_ontology on onts(ontology);
create index idx_onthonkid on onts(honkid);
create index idx_honkmetaid on honkmeta(honkid);
create index idx_hfcsuser on hfcs(userid);
create index idx_trackhonkid on tracks(xid);
create table config (key text, value text);

View File

@ -9,6 +9,7 @@ create table doovers(dooverid integer primary key, dt text, tries integer, useri
create table onts (ontology text, honkid integer);
create table honkmeta (honkid integer, genus text, json text);
create table hfcs (hfcsid integer primary key, userid integer, json text);
create table tracks (xid text, fetches text);
create index idx_honksxid on honks(xid);
create index idx_honksconvoy on honks(convoy);
@ -23,6 +24,7 @@ create index idx_ontology on onts(ontology);
create index idx_onthonkid on onts(honkid);
create index idx_honkmetaid on honkmeta(honkid);
create index idx_hfcsuser on hfcs(userid);
create index idx_trackhonkid on tracks(xid);
create table config (key text, value text);

View File

@ -24,7 +24,7 @@ import (
"time"
)
var myVersion = 31
var myVersion = 32
func doordie(db *sql.DB, s string, args ...interface{}) {
_, err := db.Exec(s, args...)
@ -351,6 +351,11 @@ func upgradedb() {
doordie(db, "update config set value = 31 where key = 'dbversion'")
fallthrough
case 31:
doordie(db, "create table tracks (xid text, fetches text)")
doordie(db, "create index idx_trackhonkid on tracks(xid)")
doordie(db, "update config set value = 32 where key = 'dbversion'")
fallthrough
case 32:
default:
log.Fatalf("can't upgrade unknown version %d", dbversion)

9
web.go
View File

@ -854,6 +854,14 @@ func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) {
}
}
func trackback(xid string, r *http.Request) {
agent := r.UserAgent()
who := originate(agent)
sig := r.Header.Get("Signature")
log.Printf("(%s) fetched %s (%s)", who, xid, sig)
}
func showonehonk(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
user, err := butwhatabout(name)
@ -870,6 +878,7 @@ func showonehonk(w http.ResponseWriter, r *http.Request) {
if friendorfoe(r.Header.Get("Accept")) {
j, ok := gimmejonk(xid)
if ok {
trackback(xid, r)
w.Header().Set("Content-Type", theonetruename)
w.Write(j)
} else {