mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 02:10:40 +00:00
Make sure Person endpoint has Content-Type application/activity+json and includes PreferredUsername, URL, and Icon
Setting the correct Content-Type is essential for federating with Mastodon
This commit is contained in:
parent
ed2a6f5348
commit
f88979326c
1 changed files with 23 additions and 6 deletions
|
@ -43,13 +43,27 @@ func Person(ctx *context.APIContext) {
|
|||
link := strings.TrimSuffix(setting.AppURL, "/") + strings.TrimSuffix(ctx.Req.URL.EscapedPath(), "/")
|
||||
person := ap.PersonNew(ap.IRI(link))
|
||||
|
||||
name := ap.NaturalLanguageValuesNew()
|
||||
err := name.Set("en", ap.Content(username))
|
||||
person.Name = ap.NaturalLanguageValuesNew()
|
||||
err := person.Name.Set("en", ap.Content(user.FullName))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "Set name", err)
|
||||
ctx.Error(http.StatusInternalServerError, "Set Name", err)
|
||||
return
|
||||
}
|
||||
person.Name = name
|
||||
|
||||
person.PreferredUsername = ap.NaturalLanguageValuesNew()
|
||||
err = person.PreferredUsername.Set("en", ap.Content(username))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "Set PreferredUsername", err)
|
||||
return
|
||||
}
|
||||
|
||||
person.URL = ap.IRI(setting.AppURL + username)
|
||||
|
||||
person.Icon = ap.Image{
|
||||
Type: ap.ImageType,
|
||||
MediaType: "image/png",
|
||||
URL: ap.IRI(user.AvatarLink()),
|
||||
}
|
||||
|
||||
person.Inbox = nil
|
||||
person.Inbox, _ = ap.Inbox.AddTo(person)
|
||||
|
@ -77,9 +91,12 @@ func Person(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "Unmarshall", err)
|
||||
}
|
||||
|
||||
jsonmap["@context"] = "https://www.w3.org/ns/activitystreams"
|
||||
jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"}
|
||||
|
||||
ctx.JSON(http.StatusOK, jsonmap)
|
||||
ctx.Resp.Header().Add("Content-Type", "application/activity+json")
|
||||
ctx.Resp.WriteHeader(http.StatusOK)
|
||||
binary, _ = json.Marshal(jsonmap)
|
||||
ctx.Resp.Write(binary)
|
||||
}
|
||||
|
||||
// PersonInbox function
|
||||
|
|
Loading…
Reference in a new issue