@ -6,14 +6,12 @@ package activitypub
import (
"net/http"
"strings"
"code.gitea.io/gitea/modules/activitypub"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/api/v1/user"
ap "github.com/go-ap/activitypub"
)
@ -35,35 +33,29 @@ func Person(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/ActivityPub"
user := user . GetUserByParamsName ( ctx , "username" )
if user == nil {
return
}
username := ctx . Params ( "username" )
link := strings . TrimSuffix ( setting . AppURL , "/" ) + strings . TrimSuffix ( ctx . Req . URL . EscapedPath ( ) , "/" )
link := setting . AppURL + "api/v1/activitypub/user/" + ctx . ContextUser . Name
person := ap . PersonNew ( ap . IRI ( link ) )
person . Name = ap . NaturalLanguageValuesNew ( )
err := person . Name . Set ( "en" , ap . Content ( u ser. FullName ) )
err := person . Name . Set ( "en" , ap . Content ( ctx . ContextUser . FullName ) )
if err != nil {
ctx . Error ( http . StatusInternalServerError , "Set Name" , err )
return
}
person . PreferredUsername = ap . NaturalLanguageValuesNew ( )
err = person . PreferredUsername . Set ( "en" , ap . Content ( usern ame) )
err = person . PreferredUsername . Set ( "en" , ap . Content ( ctx. ContextUser . N ame) )
if err != nil {
ctx . Error ( http . StatusInternalServerError , "Set PreferredUsername" , err )
return
}
person . URL = ap . IRI ( setting. AppURL + username )
person . URL = ap . IRI ( ctx. ContextUser . HTMLURL ( ) )
person . Icon = ap . Image {
Type : ap . ImageType ,
MediaType : "image/png" ,
URL : ap . IRI ( u ser. AvatarLink ( ) ) ,
URL : ap . IRI ( ctx. ContextU ser. AvatarLink ( ) ) ,
}
person . Inbox = nil
@ -74,7 +66,7 @@ func Person(ctx *context.APIContext) {
person . PublicKey . ID = ap . IRI ( link + "#main-key" )
person . PublicKey . Owner = ap . IRI ( link )
publicKeyPem , err := activitypub . GetPublicKey ( u ser)
publicKeyPem , err := activitypub . GetPublicKey ( ctx. ContextU ser)
if err != nil {
ctx . Error ( http . StatusInternalServerError , "GetPublicKey" , err )
return
@ -84,12 +76,14 @@ func Person(ctx *context.APIContext) {
binary , err := person . MarshalJSON ( )
if err != nil {
ctx . Error ( http . StatusInternalServerError , "Serialize" , err )
return
}
var jsonmap map [ string ] interface { }
err = json . Unmarshal ( binary , & jsonmap )
if err != nil {
ctx . Error ( http . StatusInternalServerError , "Unmarshall" , err )
ctx . Error ( http . StatusInternalServerError , "Unmarshal" , err )
return
}
jsonmap [ "@context" ] = [ ] string { "https://www.w3.org/ns/activitystreams" , "https://w3id.org/security/v1" }