jlelse
/
jsonpub
Archived
1
Fork 0

Add support for default actor name for webfinger

This commit is contained in:
Jan-Lukas Else 2020-03-12 23:53:29 +01:00
parent 057a9df07a
commit 0db4c4f6b6
2 changed files with 14 additions and 4 deletions

View File

@ -46,8 +46,11 @@ func Serve() {
re := regexp.MustCompile(`^acct:(.*)@` + regexp.QuoteMeta(urlBaseUrl.Host) + `$`)
name = re.ReplaceAllString(name, "$1")
actor := actors[name]
// error out if this actor does not exist
if actor == nil {
if actor == nil && len(defaultActor) > 0 {
// return default actor
actor = actors[defaultActor]
} else if actor == nil {
// error out if this actor does not exist
w.WriteHeader(http.StatusNotFound)
return
}
@ -169,4 +172,4 @@ func sendWebmention(client *webmention.Client, actor *Actor, mentioningLink, men
return
}
log.Println("Sent webmention to " + mentionedLink)
}
}

View File

@ -10,6 +10,7 @@ var slash = string(os.PathSeparator)
var baseURL string
var storage = "storage"
var actors = make(map[string]*Actor)
var defaultActor = ""
const libName = "jsonpub"
const version = "0.0.1"
@ -66,4 +67,10 @@ func SetupActors() {
os.Exit(1)
}
}
}
defaultName := os.Getenv("DEFAULT_NAME")
if len(defaultName) < 1 {
fmt.Printf("DEFAULT_NAME not configured")
} else {
defaultActor = defaultName
}
}