Browse Source

Force uniqueness with previews and logos on the fediverse. Closes #1777 and closes #1776

pull/1789/head
Gabe Kangas 3 years ago
parent
commit
d1e39c4c1e
No known key found for this signature in database
GPG Key ID: 9A56337728BC81EA
  1. 2
      activitypub/apmodels/actor.go
  2. 7
      activitypub/apmodels/actor_test.go
  3. 3
      activitypub/outbox/outbox.go
  4. 7
      controllers/admin/config.go
  5. 17
      core/data/config.go

2
activitypub/apmodels/actor.go

@ -161,8 +161,10 @@ func MakeServiceForAccount(accountName string) vocab.ActivityStreamsService { @@ -161,8 +161,10 @@ func MakeServiceForAccount(accountName string) vocab.ActivityStreamsService {
// Profile properties
// Avatar
uniquenessString := data.GetLogoUniquenessString()
userAvatarURLString := data.GetServerURL() + "/logo/external"
userAvatarURL, err := url.Parse(userAvatarURLString)
userAvatarURL.RawQuery = "uc=" + uniquenessString
if err != nil {
log.Errorln("unable to parse user avatar url", userAvatarURLString, err)
}

7
activitypub/apmodels/actor_test.go

@ -159,7 +159,12 @@ func TestMakeServiceForAccount(t *testing.T) { @@ -159,7 +159,12 @@ func TestMakeServiceForAccount(t *testing.T) {
}
expectedAvatar := "https://my.cool.site.biz/logo/external"
if person.GetActivityStreamsIcon().At(0).GetActivityStreamsImage().GetActivityStreamsUrl().Begin().GetIRI().String() != expectedAvatar {
u, err := url.Parse(person.GetActivityStreamsIcon().At(0).GetActivityStreamsImage().GetActivityStreamsUrl().Begin().GetIRI().String())
if err != nil {
t.Error(err)
}
u.RawQuery = ""
if u.String() != expectedAvatar {
t.Errorf("actor.Avatar = %v, want %v", person.GetActivityStreamsIcon().At(0).GetActivityStreamsImage().GetActivityStreamsUrl().Begin().GetIRI().String(), expectedAvatar)
}

3
activitypub/outbox/outbox.go

@ -69,7 +69,7 @@ func SendLive() error { @@ -69,7 +69,7 @@ func SendLive() error {
var imageToAttach string
previewGif := filepath.Join(config.WebRoot, "preview.gif")
thumbnailJpg := filepath.Join(config.WebRoot, "thumbnail.jpg")
uniquenessString := shortid.MustGenerate()
if utils.DoesFileExists(previewGif) {
imageToAttach = "preview.gif"
} else if utils.DoesFileExists(thumbnailJpg) {
@ -77,6 +77,7 @@ func SendLive() error { @@ -77,6 +77,7 @@ func SendLive() error {
}
if imageToAttach != "" {
previewURL.Path = imageToAttach
previewURL.RawQuery = "us=" + uniquenessString
apmodels.AddImageAttachmentToNote(note, previewURL.String())
}
}

7
controllers/admin/config.go

@ -19,6 +19,7 @@ import ( @@ -19,6 +19,7 @@ import (
"github.com/owncast/owncast/models"
"github.com/owncast/owncast/utils"
log "github.com/sirupsen/logrus"
"github.com/teris-io/shortid"
)
// ConfigValue is a container object that holds a value, is encoded, and saved to the database.
@ -242,7 +243,7 @@ func SetLogo(w http.ResponseWriter, r *http.Request) { @@ -242,7 +243,7 @@ func SetLogo(w http.ResponseWriter, r *http.Request) {
}
imgPath := filepath.Join("data", "logo"+extension)
if err := os.WriteFile(imgPath, bytes, 0600); err != nil {
if err := os.WriteFile(imgPath, bytes, 0o600); err != nil {
controllers.WriteSimpleResponse(w, false, err.Error())
return
}
@ -252,6 +253,10 @@ func SetLogo(w http.ResponseWriter, r *http.Request) { @@ -252,6 +253,10 @@ func SetLogo(w http.ResponseWriter, r *http.Request) {
return
}
if err := data.SetLogoUniquenessString(shortid.MustGenerate()); err != nil {
log.Error("Error saving logo uniqueness string: ", err)
}
// Update Fediverse followers about this change.
if err := outbox.UpdateFollowersWithAccountUpdates(); err != nil {
controllers.WriteSimpleResponse(w, false, err.Error())

17
core/data/config.go

@ -18,6 +18,7 @@ const ( @@ -18,6 +18,7 @@ const (
streamTitleKey = "stream_title"
streamKeyKey = "stream_key"
logoPathKey = "logo_path"
logoUniquenessKey = "logo_uniqueness"
serverSummaryKey = "server_summary"
serverWelcomeMessageKey = "server_welcome_message"
serverNameKey = "server_name"
@ -125,6 +126,22 @@ func SetLogoPath(logo string) error { @@ -125,6 +126,22 @@ func SetLogoPath(logo string) error {
return _datastore.SetString(logoPathKey, logo)
}
// SetLogoUniquenessString will set the logo cache busting string.
func SetLogoUniquenessString(uniqueness string) error {
return _datastore.SetString(logoUniquenessKey, uniqueness)
}
// GetLogoUniquenessString will return the logo cache busting string.
func GetLogoUniquenessString() string {
uniqueness, err := _datastore.GetString(logoUniquenessKey)
if err != nil {
log.Traceln(logoUniquenessKey, err)
return ""
}
return uniqueness
}
// GetServerSummary will return the server summary text.
func GetServerSummary() string {
summary, err := _datastore.GetString(serverSummaryKey)

Loading…
Cancel
Save