From ae3abf5723e90d43e3c72b11359dab18f0bbd518 Mon Sep 17 00:00:00 2001 From: Xeronith Date: Mon, 29 Aug 2022 16:00:05 +0430 Subject: [PATCH] refactor(app): :recycle: ostatus and mime types --- greataped/app/routes/follow.go | 2 +- greataped/app/routes/followers.go | 3 ++- greataped/app/routes/following.go | 3 ++- greataped/app/routes/helpers.go | 5 +++-- greataped/app/routes/inbox.go | 3 ++- greataped/app/routes/ostatus.go | 5 +++++ greataped/app/routes/outbox.go | 3 ++- 7 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 greataped/app/routes/ostatus.go diff --git a/greataped/app/routes/follow.go b/greataped/app/routes/follow.go index ce80509..47d699d 100644 --- a/greataped/app/routes/follow.go +++ b/greataped/app/routes/follow.go @@ -38,7 +38,7 @@ var Follow = route.New(HttpGet, "/u/:name/follow", func(x IContext) error { template := "" for _, link := range webfinger.Links { - if link.Rel == "http://ostatus.org/schema/1.0/subscribe" { + if link.Rel == OStatusSubscription { template = *link.Template break } diff --git a/greataped/app/routes/followers.go b/greataped/app/routes/followers.go index df777ea..f04f98d 100644 --- a/greataped/app/routes/followers.go +++ b/greataped/app/routes/followers.go @@ -8,6 +8,7 @@ import ( . "contracts" "encoding/json" "errors" + "server/mime" "server/route" "strconv" @@ -39,7 +40,7 @@ var Followers = route.New(HttpGet, "/u/:username/followers", func(x IContext) er } json, _ := result.Marshal() - x.Response().Header("Content-Type", "application/activity+json; charset=utf-8") + x.Response().Header("Content-Type", mime.ActivityJsonUtf8) return x.WriteString(string(json)) }) diff --git a/greataped/app/routes/following.go b/greataped/app/routes/following.go index 97b6c46..a4c9c9b 100644 --- a/greataped/app/routes/following.go +++ b/greataped/app/routes/following.go @@ -6,6 +6,7 @@ import ( "app/models/types" "config" . "contracts" + "server/mime" "server/route" ) @@ -28,6 +29,6 @@ var Following = route.New(HttpGet, "/u/:username/following", func(x IContext) er result := activitypub.NewOrderedCollection(id, items, len(items)) json, _ := result.Marshal() - x.Response().Header("Content-Type", "application/activity+json; charset=utf-8") + x.Response().Header("Content-Type", mime.ActivityJsonUtf8) return x.WriteString(string(json)) }) diff --git a/greataped/app/routes/helpers.go b/greataped/app/routes/helpers.go index 13a0702..36f85ce 100644 --- a/greataped/app/routes/helpers.go +++ b/greataped/app/routes/helpers.go @@ -6,6 +6,7 @@ import ( "config" "encoding/hex" "fmt" + "server/mime" "time" "github.com/mazen160/go-random" @@ -63,7 +64,7 @@ func createActor(user *repos.User) *activitypub.Actor { func createWebfinger(user *repos.User) *activitypub.Webfinger { subject := fmt.Sprintf("acct:%s@%s", user.Username, config.DOMAIN) href := fmt.Sprintf("%s://%s/u/%s", config.PROTOCOL, config.DOMAIN, user.Username) - _type := "application/activity+json" + _type := mime.ActivityJson template := fmt.Sprintf("%s://%s/authorize_interaction?uri={uri}", config.PROTOCOL, config.DOMAIN) return &activitypub.Webfinger{ @@ -77,7 +78,7 @@ func createWebfinger(user *repos.User) *activitypub.Webfinger { Type: &_type, }, { - Rel: "http://ostatus.org/schema/1.0/subscribe", + Rel: OStatusSubscription, Template: &template, }, }, diff --git a/greataped/app/routes/inbox.go b/greataped/app/routes/inbox.go index e39b677..27a2a76 100644 --- a/greataped/app/routes/inbox.go +++ b/greataped/app/routes/inbox.go @@ -8,6 +8,7 @@ import ( . "contracts" "encoding/json" "errors" + "server/mime" "server/route" "time" @@ -154,6 +155,6 @@ var InboxGet = route.New(HttpGet, "/u/:username/inbox", func(x IContext) error { } json, _ := outbox.Marshal() - x.Response().Header("Content-Type", "application/activity+json; charset=utf-8") + x.Response().Header("Content-Type", mime.ActivityJsonUtf8) return x.WriteString(string(json)) }) diff --git a/greataped/app/routes/ostatus.go b/greataped/app/routes/ostatus.go new file mode 100644 index 0000000..e15e7d5 --- /dev/null +++ b/greataped/app/routes/ostatus.go @@ -0,0 +1,5 @@ +package routes + +const ( + OStatusSubscription = "http://ostatus.org/schema/1.0/subscribe" +) diff --git a/greataped/app/routes/outbox.go b/greataped/app/routes/outbox.go index ea8e6c9..a01786f 100644 --- a/greataped/app/routes/outbox.go +++ b/greataped/app/routes/outbox.go @@ -8,6 +8,7 @@ import ( . "contracts" "encoding/json" "errors" + "server/mime" "server/route" "time" @@ -97,6 +98,6 @@ var OutboxGet = route.New(HttpGet, "/u/:username/outbox", func(x IContext) error outbox := activitypub.NewOrderedCollection(id, items, len(items)) json, _ := outbox.Marshal() - x.Response().Header("Content-Type", "application/activity+json; charset=utf-8") + x.Response().Header("Content-Type", mime.ActivityJsonUtf8) return x.WriteString(string(json)) })