sync for backup
This commit is contained in:
parent
1fbdf7fc9d
commit
a9916acea5
92 changed files with 35330 additions and 882 deletions
|
@ -1,24 +0,0 @@
|
|||
package ap
|
||||
|
||||
import "strings"
|
||||
|
||||
// Header used for making requests for AP resources
|
||||
// Not used yet
|
||||
const OUTBOUND_REQUEST_HEADER = "application/ld+json, application/json;q=0.9, application/javascript;q=0.5, text/javascript;q=0.5, text/plain;q=0.2, */*;q=0.1"
|
||||
|
||||
var contentHeadersToCheck = []string{
|
||||
"application/json",
|
||||
"application/ld+json",
|
||||
}
|
||||
|
||||
// Check a given string if it contains any of the content types specified in
|
||||
// the contentHeadersToCheck slice
|
||||
// Used for differentiating requests for the ActivityPub version of some data vs frontend version
|
||||
func ContainsApContentHeader(toCheck string) bool {
|
||||
for _, h := range contentHeadersToCheck {
|
||||
if strings.Contains(toCheck, h) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package ap
|
||||
|
||||
import "net/url"
|
||||
|
||||
type IdType struct {
|
||||
Id *url.URL
|
||||
}
|
||||
|
||||
type ValueType[T any] struct {
|
||||
Value T
|
||||
}
|
||||
|
||||
type Media struct {
|
||||
Type url.URL
|
||||
MediaType string
|
||||
Url url.URL
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package ap
|
||||
|
||||
const (
|
||||
KEY_ID = "@id" // Value of type string
|
||||
KEY_TYPE = "@type" // Value of type string slice / activitystreams object url slice
|
||||
KEY_VALUE = "@value" // Could be any type really
|
||||
)
|
||||
|
||||
const (
|
||||
KEY_MASTO_DEVICES = "http://joinmastodon.org/ns#devices"
|
||||
KEY_MASTO_DISCOVERABLE = "http://joinmastodon.org/ns#discoverable"
|
||||
KEY_MASTO_FEATURED = "http://joinmastodon.org/ns#featured"
|
||||
KEY_MASTO_FEATURED_TAGS = "http://joinmastodon.org/ns#featuredTags"
|
||||
KEY_MASTO_INDEXABLE = "http://joinmastodon.org/ns#indexable"
|
||||
KEY_MASTO_MEMORIAL = "http://joinmastodon.org/ns#memorial"
|
||||
)
|
||||
|
||||
const (
|
||||
KEY_W3_INBOX = "http://www.w3.org/ns/ldp#inbox"
|
||||
KEY_W3_SECURITY_PUBLICKEY = "https://w3id.org/security#publicKey"
|
||||
KEY_W3_SECURITY_OWNER = "https://w3id.org/security#owner"
|
||||
KEY_W3_SECURITY_PUBLICKEYPEM = "https://w3id.org/security#publicKeyPem"
|
||||
)
|
||||
|
||||
const (
|
||||
KEY_ACTIVITYSTREAMS_ALSOKNOWNAS = "https://www.w3.org/ns/activitystreams#alsoKnownAs"
|
||||
KEY_ACTIVITYSTREAMS_ATTACHMENTS = "https://www.w3.org/ns/activitystreams#attachment"
|
||||
KEY_ACTIVITYSTREAMS_NAME = "https://www.w3.org/ns/activitystreams#name"
|
||||
KEY_ACTIVITYSTREAMS_ENDPOINTS = "https://www.w3.org/ns/activitystreams#endpoints"
|
||||
KEY_ACTIVITYSTREAMS_SHAREDINBOX = "https://www.w3.org/ns/activitystreams#sharedInbox"
|
||||
KEY_ACTIVITYSTREAMS_FOLLOWERS = "https://www.w3.org/ns/activitystreams#followers"
|
||||
KEY_ACTIVITYSTREAMS_FOLLOWING = "https://www.w3.org/ns/activitystreams#following"
|
||||
KEY_ACTIVITYSTREAMS_ICON = "https://www.w3.org/ns/activitystreams#icon"
|
||||
KEY_ACTIVITYSTREAMS_MEDIATYPE = "https://www.w3.org/ns/activitystreams#mediaType"
|
||||
KEY_ACTIVITYSTREAMS_URL = "https://www.w3.org/ns/activitystreams#url"
|
||||
KEY_ACTIVITYSTREAMS_IMAGE = "https://www.w3.org/ns/activitystreams#image"
|
||||
KEY_ACTIVITYSTREAMS_RESTRICTED_FOLLOW = "https://www.w3.org/ns/activitystreams#manuallyApprovesFollowers"
|
||||
KEY_ACTIVITYSTREAMS_OUTBOX = "https://www.w3.org/ns/activitystreams#outbox"
|
||||
KEY_ACTIVITYSTREAMS_PREFFEREDUSERNAME = "https://www.w3.org/ns/activitystreams#preferredUsername"
|
||||
KEY_ACTIVITYSTREAMS_PUBLISHED = "https://www.w3.org/ns/activitystreams#published"
|
||||
KEY_ACTIVITYSTREAMS_SUMMARY = "https://www.w3.org/ns/activitystreams#summary"
|
||||
KEY_ACTIVITYSTREAMS_TAG = "https://www.w3.org/ns/activitystreams#tag"
|
||||
KEY_ACTIVITYSTREAMS_CC = "https://www.w3.org/ns/activitystreams#cc"
|
||||
KEY_ACTIVITYSTREAMS_TO = "https://www.w3.org/ns/activitystreams#to"
|
||||
KEY_ACTIVITYSTREAMS_OBJECT = "https://www.w3.org/ns/activitystreams#object"
|
||||
|
||||
// Object types (I think)
|
||||
// Those are values the object type can have
|
||||
|
||||
KEY_ACTIVITYSTREAMS_ACTOR = "https://www.w3.org/ns/activitystreams#actor"
|
||||
KEY_ACTIVITYSTREAMS_FOLLOW = "https://www.w3.org/ns/activitystreams#Follow"
|
||||
KEY_ACTIVITYSTREAMS_PERSON = "https://www.w3.org/ns/activitystreams#Person"
|
||||
KEY_ACTIVITYSTREAMS_CREATE = "https://www.w3.org/ns/activitystreams#Create"
|
||||
)
|
||||
|
||||
const (
|
||||
KEY_SCHEMA_VALUE = "http://schema.org#value"
|
||||
)
|
|
@ -1,49 +0,0 @@
|
|||
package ap
|
||||
|
||||
// Just steal this one from sharkey
|
||||
// Also use this one for all AP objects for now
|
||||
// Can make a function to extract context from an expanded object later
|
||||
// TODO: Consider if such a function is worth it or if it would hinder learning
|
||||
var allContext = map[string]any{
|
||||
"@context": []any{
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
map[string]any{
|
||||
"fedibird": "http://fedibird.com/ns#",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"schema": "http://schema.org#",
|
||||
"misskey": "https://misskey-hub.net/ns#",
|
||||
"firefish": "https://joinfirefish.org/ns#",
|
||||
"sharkey": "https://joinsharkey.org/ns#",
|
||||
"vcard": "http://www.w3.org/2006/vcard/ns#",
|
||||
|
||||
"Key": "sec:Key",
|
||||
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"sensitive": "as:sensitive",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"quoteUrl": "as:quoteUrl",
|
||||
|
||||
"quoteUri": "fedibird:quoteUri",
|
||||
|
||||
"Emoji": "toot:Emoji",
|
||||
"featured": "toot:featured",
|
||||
"discoverable": "toot:discoverable",
|
||||
|
||||
"PropertyValue": "schema:PropertyValue",
|
||||
"value": "schema:value",
|
||||
|
||||
"_misskey_content": "misskey:_misskey_content",
|
||||
"_misskey_quote": "misskey:_misskey_quote",
|
||||
"_misskey_reaction": "misskey:_misskey_reaction",
|
||||
"_misskey_votes": "misskey:_misskey_votes",
|
||||
"_misskey_summary": "misskey:_misskey_summary",
|
||||
"isCat": "misskey:isCat",
|
||||
|
||||
"speakAsCat": "firefish:speakAsCat",
|
||||
|
||||
"backgroundUrl": "sharkey:backgroundUrl",
|
||||
"listenbrainz": "sharkey:listenbrainz",
|
||||
},
|
||||
},
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
[
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron",
|
||||
"@type": [
|
||||
"https://www.w3.org/ns/activitystreams#Person"
|
||||
],
|
||||
"http://joinmastodon.org/ns#devices": [
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron/collections/devices"
|
||||
}
|
||||
],
|
||||
"http://joinmastodon.org/ns#discoverable": [
|
||||
{
|
||||
"@value": true
|
||||
}
|
||||
],
|
||||
"http://joinmastodon.org/ns#featured": [
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron/collections/featured"
|
||||
}
|
||||
],
|
||||
"http://joinmastodon.org/ns#featuredTags": [
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron/collections/tags"
|
||||
}
|
||||
],
|
||||
"http://joinmastodon.org/ns#indexable": [
|
||||
{
|
||||
"@value": true
|
||||
}
|
||||
],
|
||||
"http://joinmastodon.org/ns#memorial": [
|
||||
{
|
||||
"@value": false
|
||||
}
|
||||
],
|
||||
"http://www.w3.org/ns/ldp#inbox": [
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron/inbox"
|
||||
}
|
||||
],
|
||||
"https://w3id.org/security#publicKey": [
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron#main-key",
|
||||
"https://w3id.org/security#owner": [
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron"
|
||||
}
|
||||
],
|
||||
"https://w3id.org/security#publicKeyPem": [
|
||||
{
|
||||
"@value": "-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvXc4vkECU2/CeuSo1wtn Foim94Ne1jBMYxTZ9wm2YTdJq1oiZKif06I2fOqDzY/4q/S9uccrE9Bkajv1dnkO Vm31QjWlhVpSKynVxEWjVBO5Ienue8gND0xvHIuXf87o61poqjEoepvsQFElA5ym ovljWGSA/jpj7ozygUZhCXtaS2W5AD5tnBQUpcO0lhItYPYTjnmzcc4y2NbJV8hz 2s2G8qKv8fyimE23gY1XrPJg+cRF+g4PqFXujjlJ7MihD9oqtLGxbu7o1cifTn3x BfIdPythWu5b4cujNsB3m3awJjVmx+MHQ9SugkSIYXV0Ina77cTNS0M2PYiH1PFR TwIDAQAB -----END PUBLIC KEY----- "
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#alsoKnownAs": [
|
||||
{
|
||||
"@id": "https://tooting.ai/users/Gargron"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#attachment": [
|
||||
{
|
||||
"@type": [
|
||||
"http://schema.org#PropertyValue"
|
||||
],
|
||||
"http://schema.org#value": [
|
||||
{
|
||||
"@value": "\u003ca href=\"https://www.patreon.com/mastodon\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\" translate=\"no\"\u003e\u003cspan class=\"invisible\"\u003ehttps://www.\u003c/span\u003e\u003cspan class=\"\"\u003epatreon.com/mastodon\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#name": [
|
||||
{
|
||||
"@value": "Patreon"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"@type": [
|
||||
"http://schema.org#PropertyValue"
|
||||
],
|
||||
"http://schema.org#value": [
|
||||
{
|
||||
"@value": "\u003ca href=\"https://github.com/Gargron\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\" translate=\"no\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003egithub.com/Gargron\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#name": [
|
||||
{
|
||||
"@value": "GitHub"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#endpoints": [
|
||||
{
|
||||
"https://www.w3.org/ns/activitystreams#sharedInbox": [
|
||||
{
|
||||
"@id": "https://mastodon.social/inbox"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#followers": [
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron/followers"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#following": [
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron/following"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#icon": [
|
||||
{
|
||||
"@type": [
|
||||
"https://www.w3.org/ns/activitystreams#Image"
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#mediaType": [
|
||||
{
|
||||
"@value": "image/png"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#url": [
|
||||
{
|
||||
"@id": "https://files.mastodon.social/accounts/avatars/000/000/001/original/a0a49d80c3de5f75.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#image": [
|
||||
{
|
||||
"@type": [
|
||||
"https://www.w3.org/ns/activitystreams#Image"
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#mediaType": [
|
||||
{
|
||||
"@value": "image/jpeg"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#url": [
|
||||
{
|
||||
"@id": "https://files.mastodon.social/accounts/headers/000/000/001/original/d13e4417706a5fec.jpg"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#manuallyApprovesFollowers": [
|
||||
{
|
||||
"@value": false
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#name": [
|
||||
{
|
||||
"@value": "Eugen Rochko"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#outbox": [
|
||||
{
|
||||
"@id": "https://mastodon.social/users/Gargron/outbox"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#preferredUsername": [
|
||||
{
|
||||
"@value": "Gargron"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#published": [
|
||||
{
|
||||
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
|
||||
"@value": "2016-03-16T00:00:00Z"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#summary": [
|
||||
{
|
||||
"@value": "\u003cp\u003eFounder of \u003cspan class=\"h-card\" translate=\"no\"\u003e\u003ca href=\"https://mastodon.social/@Mastodon\" class=\"u-url mention\"\u003e@\u003cspan\u003eMastodon\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e. Film photography, prog metal, Dota 2. Likes all things analog.\u003c/p\u003e"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#tag": [],
|
||||
"https://www.w3.org/ns/activitystreams#url": [
|
||||
{
|
||||
"@id": "https://mastodon.social/@Gargron"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
[
|
||||
{
|
||||
"@id": "https://activitypub.academy/1e8a5594-eff7-4946-86fe-84d82d0a14ae",
|
||||
"@type": [
|
||||
"https://www.w3.org/ns/activitystreams#Follow"
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#actor": [
|
||||
{
|
||||
"@id": "https://activitypub.academy/users/dadacio_dashdorrol"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#object": [
|
||||
{
|
||||
"@id": "https://woem.men/users/9n39zo1rfckr00q5"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,41 +0,0 @@
|
|||
[
|
||||
{
|
||||
"@id": "https://woem.men/notes/9ttp29lhge2u0454",
|
||||
"@type": [
|
||||
"https://www.w3.org/ns/activitystreams#Note"
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#attachment": [],
|
||||
"https://www.w3.org/ns/activitystreams#attributedTo": [
|
||||
{
|
||||
"@id": "https://woem.men/users/9n39zo1rfckr00q5"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#cc": [
|
||||
{
|
||||
"@id": "https://woem.men/users/9n39zo1rfckr00q5/followers"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#content": [
|
||||
{
|
||||
"@value": "\u003cp\u003eTest post, ignore\u003c/p\u003e"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#published": [
|
||||
{
|
||||
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
|
||||
"@value": "2024-05-28T08:22:59.861Z"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#sensitive": [
|
||||
{
|
||||
"@value": false
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#tag": [],
|
||||
"https://www.w3.org/ns/activitystreams#to": [
|
||||
{
|
||||
"@id": "https://www.w3.org/ns/activitystreams#Public"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,70 +0,0 @@
|
|||
[
|
||||
{
|
||||
"@id": "https://woem.men/notes/9ttp29lhge2u0454/activity",
|
||||
"@type": [
|
||||
"https://www.w3.org/ns/activitystreams#Create"
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#actor": [
|
||||
{
|
||||
"@id": "https://woem.men/users/9n39zo1rfckr00q5"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#cc": [
|
||||
{
|
||||
"@id": "https://woem.men/users/9n39zo1rfckr00q5/followers"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#object": [
|
||||
{
|
||||
"@id": "https://woem.men/notes/9ttp29lhge2u0454",
|
||||
"@type": [
|
||||
"https://www.w3.org/ns/activitystreams#Note"
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#attachment": [],
|
||||
"https://www.w3.org/ns/activitystreams#attributedTo": [
|
||||
{
|
||||
"@id": "https://woem.men/users/9n39zo1rfckr00q5"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#cc": [
|
||||
{
|
||||
"@id": "https://woem.men/users/9n39zo1rfckr00q5/followers"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#content": [
|
||||
{
|
||||
"@value": "\u003cp\u003eTest post, ignore\u003c/p\u003e"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#published": [
|
||||
{
|
||||
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
|
||||
"@value": "2024-05-28T08:22:59.861Z"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#sensitive": [
|
||||
{
|
||||
"@value": false
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#tag": [],
|
||||
"https://www.w3.org/ns/activitystreams#to": [
|
||||
{
|
||||
"@id": "https://www.w3.org/ns/activitystreams#Public"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#published": [
|
||||
{
|
||||
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
|
||||
"@value": "2024-05-28T08:22:59.861Z"
|
||||
}
|
||||
],
|
||||
"https://www.w3.org/ns/activitystreams#to": [
|
||||
{
|
||||
"@id": "https://www.w3.org/ns/activitystreams#Public"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,62 +0,0 @@
|
|||
package ap
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
ActivityStreamsAlsoKnownAs IdType
|
||||
ActivityStreamsAttachment struct {
|
||||
Type *url.URL
|
||||
Value string
|
||||
Name string
|
||||
}
|
||||
ActivityStreamsSharedInbox IdType
|
||||
ActivityStreamsFollowers IdType
|
||||
ActivityStreamsFollowing IdType
|
||||
ActivityStreamsImage Media
|
||||
ActivityStreamsIcon Media
|
||||
ActivityStreamsRestrictedFollow ValueType[bool]
|
||||
ActivityStreamsName ValueType[string]
|
||||
ActivityStreamsOutbox IdType
|
||||
ActivityStreamsPrefferedUsername ValueType[string]
|
||||
ActivityStreamsPublished struct {
|
||||
Type string
|
||||
Value time.Time
|
||||
}
|
||||
ActivityStreamsSummary ValueType[string]
|
||||
ActivityStreamsUrl IdType
|
||||
// NOTE: I do not know if this is consistent at all. Do not trust yet
|
||||
ActivityStreamsTag struct {
|
||||
Type string
|
||||
Id string
|
||||
Name string
|
||||
}
|
||||
ActivityStreamsTo IdType
|
||||
ActivityStreamsCC IdType
|
||||
|
||||
ActivityStreamsActor IdType
|
||||
// NOTE: Technically, objects can have a LOT of data. I don't care. Treat them as ID type
|
||||
// Just fetch whatever the ID is later on separately and throw away anything else but the ID
|
||||
ActivityStreamsObject IdType
|
||||
ActivityStreamsFollow IdType
|
||||
)
|
||||
|
||||
type (
|
||||
MastoDevices IdType
|
||||
MastoDiscoverable ValueType[bool]
|
||||
MastoFeatured IdType
|
||||
MastoFeaturedTags IdType
|
||||
MastoIndexable ValueType[bool]
|
||||
MastoMemorial ValueType[bool]
|
||||
)
|
||||
|
||||
type (
|
||||
W3Inbox IdType
|
||||
W3SecurityPublicKey struct {
|
||||
Id *url.URL
|
||||
Owner *url.URL
|
||||
KeyPem string
|
||||
}
|
||||
)
|
59
ap/parser.go
59
ap/parser.go
|
@ -1,59 +0,0 @@
|
|||
package ap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/piprate/json-gold/ld"
|
||||
)
|
||||
|
||||
type ApThing map[string]any
|
||||
|
||||
type RemoteDocumentLoader struct{}
|
||||
|
||||
// Try and parse a remote ActivityPub object into a more usable form
|
||||
// Result is a map[string]any where the keys defined in /ap/constants.go should be usable,
|
||||
// depending on the type of object
|
||||
// The general approach for fetching an object will be to fetch the main object
|
||||
// and only store the ID for sub-objects to fetch them later
|
||||
func ParseFromUrl(u *url.URL) (ApThing, error) {
|
||||
opts := ld.NewJsonLdOptions("")
|
||||
processor := ld.NewJsonLdProcessor()
|
||||
// TODO: Add custom document parser (copy default implementation) that includes verification
|
||||
|
||||
// Explanation:
|
||||
// Expansion removes the context from a document (json-ld activitypub data)
|
||||
// and turns every field into something along the lines of
|
||||
// "https://example.com/ns#ObjectType": <Insert data for that object here>
|
||||
// This makes it easier to deal with things as they now have a very consistent naming scheme
|
||||
// See /ap/constants.go for those
|
||||
|
||||
parsed, err := processor.Expand(u.String(), opts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to process remote document: %w", err)
|
||||
}
|
||||
if len(parsed) == 0 {
|
||||
return nil, fmt.Errorf("document has a length of 0")
|
||||
}
|
||||
typed, ok := parsed[0].(ApThing)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("couldn't cast data to ApThing")
|
||||
}
|
||||
return typed, nil
|
||||
}
|
||||
|
||||
// Compact an AP object down into a compressed json-ld form
|
||||
// That compacted form should be accepted by all AP servers
|
||||
// It also handles context for any fields
|
||||
// Content should only use keys defined in /ap/constants.go though
|
||||
// Other things might get lost in translation
|
||||
func Compact(content map[string]any) ([]byte, error) {
|
||||
opts := ld.NewJsonLdOptions("")
|
||||
processor := ld.NewJsonLdProcessor()
|
||||
res, err := processor.Compact(content, allContext, opts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to compact data: %w", err)
|
||||
}
|
||||
return json.Marshal(res)
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
package ap
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Try and parse a value into an IdType
|
||||
// Returns nil if failed
|
||||
func TryParseIdType(rawIn any) *IdType {
|
||||
switch in := rawIn.(type) {
|
||||
case []any:
|
||||
if len(in) == 0 {
|
||||
return nil
|
||||
}
|
||||
m, ok := in[0].(map[string]any)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return TryParseIdType(m)
|
||||
case map[string]any:
|
||||
vRaw, ok := in[KEY_ID]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
v, ok := vRaw.(string)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
u, err := url.Parse(v)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return &IdType{
|
||||
Id: u,
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func TryParseValueType[T any](rawIn any) *ValueType[T] {
|
||||
switch in := rawIn.(type) {
|
||||
case map[string]any:
|
||||
vRaw, ok := in[KEY_ID]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
v, ok := vRaw.(T)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return &ValueType[T]{
|
||||
Value: v,
|
||||
}
|
||||
case []any:
|
||||
if len(in) == 0 {
|
||||
return nil
|
||||
}
|
||||
v, ok := in[0].(map[string]any)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return TryParseValueType[T](v)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func TryParseActivityStreamsPublicKey(rawIn any) *W3SecurityPublicKey {
|
||||
switch in := rawIn.(type) {
|
||||
case map[string]any:
|
||||
asIdType := TryParseIdType(in)
|
||||
if asIdType == nil {
|
||||
return nil
|
||||
}
|
||||
ownerType := TryParseIdType(in[KEY_W3_SECURITY_OWNER])
|
||||
if ownerType == nil {
|
||||
return nil
|
||||
}
|
||||
keyValue := TryParseValueType[string](in[KEY_W3_SECURITY_PUBLICKEYPEM])
|
||||
if keyValue == nil {
|
||||
return nil
|
||||
}
|
||||
return &W3SecurityPublicKey{
|
||||
Id: asIdType.Id,
|
||||
Owner: ownerType.Id,
|
||||
KeyPem: keyValue.Value,
|
||||
}
|
||||
case []any:
|
||||
if len(in) == 0 {
|
||||
return nil
|
||||
}
|
||||
return TryParseActivityStreamsPublicKey(in[0])
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func TryParseActivityStreamsAttachment(rawIn any) *ActivityStreamsAttachment {
|
||||
switch in := rawIn.(type) {
|
||||
case []any:
|
||||
if len(in) == 0 {
|
||||
return nil
|
||||
}
|
||||
return TryParseActivityStreamsAttachment(in[0])
|
||||
case map[string]any:
|
||||
rawType, ok := in[KEY_TYPE]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
strType, ok := rawType.(string)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
urlType, err := url.Parse(strType)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
value := TryParseValueType[string](in[KEY_SCHEMA_VALUE])
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
name := TryParseValueType[string](in[KEY_ACTIVITYSTREAMS_NAME])
|
||||
if name == nil {
|
||||
return nil
|
||||
}
|
||||
return &ActivityStreamsAttachment{
|
||||
Type: urlType,
|
||||
Name: name.Value,
|
||||
Value: value.Value,
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func TryParseActivityStreamsPublished(rawIn any) *ActivityStreamsPublished {
|
||||
switch in := rawIn.(type) {
|
||||
case []any:
|
||||
if len(in) == 0 {
|
||||
return nil
|
||||
}
|
||||
return TryParseActivityStreamsPublished(in[0])
|
||||
case map[string]any:
|
||||
rawType, ok := in[KEY_TYPE]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
strType, ok := rawType.(string)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
value := TryParseValueType[string](in)
|
||||
tv, err := time.Parse("2006-01-02T04:05:06Z", value.Value)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return &ActivityStreamsPublished{
|
||||
Type: strType,
|
||||
Value: tv,
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Since I do not know if tags are consistent with the struct yet,
|
||||
// This funtion does not do anything yet and should not be used
|
||||
func TryParseActivityStreamsTag(rawIn any) *ActivityStreamsTag {
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue