jlelse
/
jsonpub
Archived
1
Fork 0

Log inbox to file

This commit is contained in:
Jan-Lukas Else 2020-02-24 21:51:33 +01:00
parent b284e4e922
commit eac57a4d40
1 changed files with 15 additions and 6 deletions

21
http.go
View File

@ -7,6 +7,7 @@ import (
"log"
"net/http"
"net/url"
"os"
"regexp"
"willnorris.com/go/webmention"
)
@ -50,13 +51,21 @@ func Serve() {
w.WriteHeader(http.StatusInternalServerError)
return
}
actor := actors[mux.Vars(r)["actor"]]
if actor == nil {
// actor doesn't exist
w.WriteHeader(http.StatusNotFound)
return
}
f, err := os.OpenFile(storage+slash+"actors"+slash+actor.Name+slash+"inbox", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
defer func() { _ = f.Close() }()
_, _ = f.Write(b)
_, _ = f.WriteString("\n---\n")
if activity["type"] == "Follow" {
actor := actors[mux.Vars(r)["actor"]]
// error out if this actor does not exist
if actor == nil {
w.WriteHeader(http.StatusNotFound)
return
}
actor.Accept(activity)
} else if activity["type"] == "Undo" {
// TODO: Implement unfollow