1ed51859b0
* Extending webfinger response #2851 1. Added Logo - rel: avatar as there wasn't any appropriate value in [Link relations registry](https://www.iana.org/assignments/link-relations/) - type: default value image/png or else it is determined file type extension 2. Added Stream - rel: stream as there wasn't appropriate value in [Link relations registry](https://www.iana.org/assignments/link-relations/) - type: video/H264 based on [IANA media types](https://www.iana.org/assignments/media-types/media-types.xhtml#video) Changes after review: 1. Updated the rel type for avatar based on webfinger rel. 2. Updated the rel type for stream link and href value that closely associates to it. * adding period after comments * updating typo
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package apmodels
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// WebfingerResponse represents a Webfinger response.
|
|
type WebfingerResponse struct {
|
|
Aliases []string `json:"aliases"`
|
|
Subject string `json:"subject"`
|
|
Links []Link `json:"links"`
|
|
}
|
|
|
|
// WebfingerProfileRequestResponse represents a Webfinger profile request response.
|
|
type WebfingerProfileRequestResponse struct {
|
|
Self string
|
|
}
|
|
|
|
// Link represents a Webfinger response Link entity.
|
|
type Link struct {
|
|
Rel string `json:"rel"`
|
|
Type string `json:"type"`
|
|
Href string `json:"href"`
|
|
}
|
|
|
|
// MakeWebfingerResponse will create a new Webfinger response.
|
|
func MakeWebfingerResponse(account string, inbox string, host string) WebfingerResponse {
|
|
accountIRI := MakeLocalIRIForAccount(account)
|
|
streamIRI := MakeLocalIRIForStreamURL()
|
|
logoIRI := MakeLocalIRIforLogo()
|
|
logoType := GetLogoType()
|
|
return WebfingerResponse{
|
|
Subject: fmt.Sprintf("acct:%s@%s", account, host),
|
|
Aliases: []string{
|
|
accountIRI.String(),
|
|
},
|
|
Links: []Link{
|
|
{
|
|
Rel: "self",
|
|
Type: "application/activity+json",
|
|
Href: accountIRI.String(),
|
|
},
|
|
{
|
|
Rel: "http://webfinger.net/rel/profile-page",
|
|
Type: "text/html",
|
|
Href: accountIRI.String(),
|
|
},
|
|
{
|
|
Rel: "http://webfinger.net/rel/avatar",
|
|
Type: logoType,
|
|
Href: logoIRI.String(),
|
|
},
|
|
{
|
|
Rel: "alternate",
|
|
Type: "application/x-mpegURL",
|
|
Href: streamIRI.String(),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
// MakeWebFingerRequestResponseFromData converts WebFinger data to an easier
|
|
// to use model.
|
|
func MakeWebFingerRequestResponseFromData(data []map[string]interface{}) WebfingerProfileRequestResponse {
|
|
response := WebfingerProfileRequestResponse{}
|
|
for _, link := range data {
|
|
if link["rel"] == "self" {
|
|
return WebfingerProfileRequestResponse{
|
|
Self: link["href"].(string),
|
|
}
|
|
}
|
|
}
|
|
|
|
return response
|
|
}
|