Extending webfinger response (issue:2851) (#3053)

* 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
This commit is contained in:
Jerin Thomas 2023-06-01 00:06:41 +05:30 committed by GitHub
parent c295e4f215
commit 1ed51859b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 1 deletions

View file

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"net/url" "net/url"
"path" "path"
"path/filepath"
"github.com/go-fed/activity/streams" "github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab" "github.com/go-fed/activity/streams/vocab"
@ -60,3 +61,50 @@ func Serialize(obj vocab.Type) ([]byte, error) {
return b, err return b, err
} }
// MakeLocalIRIForStreamURL will return a full IRI for the local server stream url.
func MakeLocalIRIForStreamURL() *url.URL {
host := data.GetServerURL()
u, err := url.Parse(host)
if err != nil {
log.Errorln("unable to parse local IRI stream url", err)
return nil
}
u.Path = path.Join(u.Path, "/hls/stream.m3u8")
return u
}
// MakeLocalIRIforLogo will return a full IRI for the local server logo.
func MakeLocalIRIforLogo() *url.URL {
host := data.GetServerURL()
u, err := url.Parse(host)
if err != nil {
log.Errorln("unable to parse local IRI stream url", err)
return nil
}
u.Path = path.Join(u.Path, "/logo/external")
return u
}
// GetLogoType will return the rel value for the webfinger response and
// the default static image is of type png.
func GetLogoType() string {
imageFilename := data.GetLogoPath()
if imageFilename == "" {
return "image/png"
}
logoType := "image/jpeg"
if filepath.Ext(imageFilename) == ".svg" {
logoType = "image/svg+xml"
} else if filepath.Ext(imageFilename) == ".gif" {
logoType = "image/gif"
} else if filepath.Ext(imageFilename) == ".png" {
logoType = "image/png"
}
return logoType
}

View file

@ -26,7 +26,9 @@ type Link struct {
// MakeWebfingerResponse will create a new Webfinger response. // MakeWebfingerResponse will create a new Webfinger response.
func MakeWebfingerResponse(account string, inbox string, host string) WebfingerResponse { func MakeWebfingerResponse(account string, inbox string, host string) WebfingerResponse {
accountIRI := MakeLocalIRIForAccount(account) accountIRI := MakeLocalIRIForAccount(account)
streamIRI := MakeLocalIRIForStreamURL()
logoIRI := MakeLocalIRIforLogo()
logoType := GetLogoType()
return WebfingerResponse{ return WebfingerResponse{
Subject: fmt.Sprintf("acct:%s@%s", account, host), Subject: fmt.Sprintf("acct:%s@%s", account, host),
Aliases: []string{ Aliases: []string{
@ -43,6 +45,16 @@ func MakeWebfingerResponse(account string, inbox string, host string) WebfingerR
Type: "text/html", Type: "text/html",
Href: accountIRI.String(), Href: accountIRI.String(),
}, },
{
Rel: "http://webfinger.net/rel/avatar",
Type: logoType,
Href: logoIRI.String(),
},
{
Rel: "alternate",
Type: "application/x-mpegURL",
Href: streamIRI.String(),
},
}, },
} }
} }