kopia lustrzana https://github.com/reiver/greatape
refactor(app): ♻️ ostatus and mime types
rodzic
acdd0f5809
commit
ae3abf5723
|
@ -38,7 +38,7 @@ var Follow = route.New(HttpGet, "/u/:name/follow", func(x IContext) error {
|
||||||
|
|
||||||
template := ""
|
template := ""
|
||||||
for _, link := range webfinger.Links {
|
for _, link := range webfinger.Links {
|
||||||
if link.Rel == "http://ostatus.org/schema/1.0/subscribe" {
|
if link.Rel == OStatusSubscription {
|
||||||
template = *link.Template
|
template = *link.Template
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
. "contracts"
|
. "contracts"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"server/mime"
|
||||||
"server/route"
|
"server/route"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ var Followers = route.New(HttpGet, "/u/:username/followers", func(x IContext) er
|
||||||
}
|
}
|
||||||
|
|
||||||
json, _ := result.Marshal()
|
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))
|
return x.WriteString(string(json))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"app/models/types"
|
"app/models/types"
|
||||||
"config"
|
"config"
|
||||||
. "contracts"
|
. "contracts"
|
||||||
|
"server/mime"
|
||||||
"server/route"
|
"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))
|
result := activitypub.NewOrderedCollection(id, items, len(items))
|
||||||
|
|
||||||
json, _ := result.Marshal()
|
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))
|
return x.WriteString(string(json))
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"config"
|
"config"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"server/mime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mazen160/go-random"
|
"github.com/mazen160/go-random"
|
||||||
|
@ -63,7 +64,7 @@ func createActor(user *repos.User) *activitypub.Actor {
|
||||||
func createWebfinger(user *repos.User) *activitypub.Webfinger {
|
func createWebfinger(user *repos.User) *activitypub.Webfinger {
|
||||||
subject := fmt.Sprintf("acct:%s@%s", user.Username, config.DOMAIN)
|
subject := fmt.Sprintf("acct:%s@%s", user.Username, config.DOMAIN)
|
||||||
href := fmt.Sprintf("%s://%s/u/%s", config.PROTOCOL, config.DOMAIN, user.Username)
|
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)
|
template := fmt.Sprintf("%s://%s/authorize_interaction?uri={uri}", config.PROTOCOL, config.DOMAIN)
|
||||||
|
|
||||||
return &activitypub.Webfinger{
|
return &activitypub.Webfinger{
|
||||||
|
@ -77,7 +78,7 @@ func createWebfinger(user *repos.User) *activitypub.Webfinger {
|
||||||
Type: &_type,
|
Type: &_type,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Rel: "http://ostatus.org/schema/1.0/subscribe",
|
Rel: OStatusSubscription,
|
||||||
Template: &template,
|
Template: &template,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
. "contracts"
|
. "contracts"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"server/mime"
|
||||||
"server/route"
|
"server/route"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -154,6 +155,6 @@ var InboxGet = route.New(HttpGet, "/u/:username/inbox", func(x IContext) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
json, _ := outbox.Marshal()
|
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))
|
return x.WriteString(string(json))
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package routes
|
||||||
|
|
||||||
|
const (
|
||||||
|
OStatusSubscription = "http://ostatus.org/schema/1.0/subscribe"
|
||||||
|
)
|
|
@ -8,6 +8,7 @@ import (
|
||||||
. "contracts"
|
. "contracts"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"server/mime"
|
||||||
"server/route"
|
"server/route"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -97,6 +98,6 @@ var OutboxGet = route.New(HttpGet, "/u/:username/outbox", func(x IContext) error
|
||||||
outbox := activitypub.NewOrderedCollection(id, items, len(items))
|
outbox := activitypub.NewOrderedCollection(id, items, len(items))
|
||||||
|
|
||||||
json, _ := outbox.Marshal()
|
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))
|
return x.WriteString(string(json))
|
||||||
})
|
})
|
||||||
|
|
Ładowanie…
Reference in New Issue