Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

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

Gabe Kangas3c76a82ab1b3
diff --git a/activitypub/apmodels/actor.go b/activitypub/apmodels/actor.go
index 28e8949718..7efd5708eb 100644
--- a/activitypub/apmodels/actor.go
+++ b/activitypub/apmodels/actor.go
@@ -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)
}
diff --git a/activitypub/apmodels/actor_test.go b/activitypub/apmodels/actor_test.go
index b0158ac004..e4cae4f5b7 100644
--- a/activitypub/apmodels/actor_test.go
+++ b/activitypub/apmodels/actor_test.go
@@ -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)
}
diff --git a/activitypub/outbox/outbox.go b/activitypub/outbox/outbox.go
index ce79fbe06e..4837a0e210 100644
--- a/activitypub/outbox/outbox.go
+++ b/activitypub/outbox/outbox.go
@@ -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 {
}
if imageToAttach != "" {
previewURL.Path = imageToAttach
+ previewURL.RawQuery = "us=" + uniquenessString
apmodels.AddImageAttachmentToNote(note, previewURL.String())
}
}
diff --git a/controllers/admin/config.go b/controllers/admin/config.go
index 086e71d8b7..58bd084cd0 100644
--- a/controllers/admin/config.go
+++ b/controllers/admin/config.go
@@ -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) {
}
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) {
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())
diff --git a/core/data/config.go b/core/data/config.go
index a073b3e48a..ff8afeb0ea 100644
--- a/core/data/config.go
+++ b/core/data/config.go
@@ -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 {
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)