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

View File

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