diff --git a/.gitignore b/.gitignore index cafaf74a0..7d30b9530 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .env .idea +*.iml .vscode .DS_Store npm-debug.log* diff --git a/backend/src/activitypub/ActivityPub.js b/backend/src/activitypub/ActivityPub.js index bcebf4d49..afb75086a 100644 --- a/backend/src/activitypub/ActivityPub.js +++ b/backend/src/activitypub/ActivityPub.js @@ -22,8 +22,8 @@ let activityPub = null export { activityPub } export default class ActivityPub { - constructor (domain, port, uri) { - if (domain === 'localhost') { this.domain = `${domain}:${port}` } else { this.domain = domain } + constructor (hostname, port, uri) { + if (hostname === 'localhost') { this.hostname = `${hostname}:${port}` } else { this.hostname = hostname } this.port = port this.dataSource = new NitroDataSource(uri) this.collections = new Collections(this.dataSource) @@ -33,7 +33,9 @@ export default class ActivityPub { if (!activityPub) { dotenv.config() const url = new URL(process.env.GRAPHQL_URI) - activityPub = new ActivityPub(url.hostname || 'localhost', url.port || 4000, url.origin) + // TODO Check why the hostname attribute in the prod env not containing the tld! Following line is a quick fix!! + const hostname = url.hostname.endsWith('.org') ? url.hostname : url.hostname.concat('.org') + activityPub = new ActivityPub(hostname || 'localhost', url.port || 4000, url.origin) // integrate into running graphql express server server.express.set('ap', activityPub) @@ -59,7 +61,7 @@ export default class ActivityPub { } }, async (err, response, toActorObject) => { if (err) return reject(err) - debug(`name = ${toActorName}@${this.domain}`) + debug(`name = ${toActorName}@${this.hostname}`) // save shared inbox toActorObject = JSON.parse(toActorObject) await this.dataSource.addSharedInboxEndpoint(toActorObject.endpoints.sharedInbox) @@ -184,7 +186,7 @@ export default class ActivityPub { } generateStatusId (slug) { - return `http://${this.domain}/activitypub/users/${slug}/status/${uuid()}` + return `https://${this.hostname}/activitypub/users/${slug}/status/${uuid()}` } async sendActivity (activity) { diff --git a/backend/src/activitypub/utils/activity.js b/backend/src/activitypub/utils/activity.js index 53bcd37ea..1e845792a 100644 --- a/backend/src/activitypub/utils/activity.js +++ b/backend/src/activitypub/utils/activity.js @@ -11,14 +11,14 @@ export function createNoteObject (text, name, id, published) { return { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': `https://${activityPub.domain}/activitypub/users/${name}/status/${createUuid}`, + 'id': `https://${activityPub.hostname}/activitypub/users/${name}/status/${createUuid}`, 'type': 'Create', - 'actor': `https://${activityPub.domain}/activitypub/users/${name}`, + 'actor': `https://${activityPub.hostname}/activitypub/users/${name}`, 'object': { - 'id': `https://${activityPub.domain}/activitypub/users/${name}/status/${id}`, + 'id': `https://${activityPub.hostname}/activitypub/users/${name}/status/${id}`, 'type': 'Note', 'published': published, - 'attributedTo': `https://${activityPub.domain}/activitypub/users/${name}`, + 'attributedTo': `https://${activityPub.hostname}/activitypub/users/${name}`, 'content': text, 'to': 'https://www.w3.org/ns/activitystreams#Public' } @@ -64,8 +64,8 @@ export async function getActorId (name) { export function sendAcceptActivity (theBody, name, targetDomain, url) { as.accept() - .id(`https://${activityPub.domain}/activitypub/users/${name}/status/` + crypto.randomBytes(16).toString('hex')) - .actor(`https://${activityPub.domain}/activitypub/users/${name}`) + .id(`https://${activityPub.hostname}/activitypub/users/${name}/status/` + crypto.randomBytes(16).toString('hex')) + .actor(`https://${activityPub.hostname}/activitypub/users/${name}`) .object(theBody) .prettyWrite((err, doc) => { if (!err) { @@ -79,8 +79,8 @@ export function sendAcceptActivity (theBody, name, targetDomain, url) { export function sendRejectActivity (theBody, name, targetDomain, url) { as.reject() - .id(`https://${activityPub.domain}/activitypub/users/${name}/status/` + crypto.randomBytes(16).toString('hex')) - .actor(`https://${activityPub.domain}/activitypub/users/${name}`) + .id(`https://${activityPub.hostname}/activitypub/users/${name}/status/` + crypto.randomBytes(16).toString('hex')) + .actor(`https://${activityPub.hostname}/activitypub/users/${name}`) .object(theBody) .prettyWrite((err, doc) => { if (!err) { diff --git a/backend/src/activitypub/utils/actor.js b/backend/src/activitypub/utils/actor.js index 0b8cc7454..92f1797b4 100644 --- a/backend/src/activitypub/utils/actor.js +++ b/backend/src/activitypub/utils/actor.js @@ -6,21 +6,21 @@ export function createActor (name, pubkey) { 'https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1' ], - 'id': `https://${activityPub.domain}/activitypub/users/${name}`, + 'id': `https://${activityPub.hostname}/activitypub/users/${name}`, 'type': 'Person', 'preferredUsername': `${name}`, 'name': `${name}`, - 'following': `https://${activityPub.domain}/activitypub/users/${name}/following`, - 'followers': `https://${activityPub.domain}/activitypub/users/${name}/followers`, - 'inbox': `https://${activityPub.domain}/activitypub/users/${name}/inbox`, - 'outbox': `https://${activityPub.domain}/activitypub/users/${name}/outbox`, - 'url': `https://${activityPub.domain}/activitypub/@${name}`, + 'following': `https://${activityPub.hostname}/activitypub/users/${name}/following`, + 'followers': `https://${activityPub.hostname}/activitypub/users/${name}/followers`, + 'inbox': `https://${activityPub.hostname}/activitypub/users/${name}/inbox`, + 'outbox': `https://${activityPub.hostname}/activitypub/users/${name}/outbox`, + 'url': `https://${activityPub.hostname}/activitypub/@${name}`, 'endpoints': { - 'sharedInbox': `https://${activityPub.domain}/activitypub/inbox` + 'sharedInbox': `https://${activityPub.hostname}/activitypub/inbox` }, 'publicKey': { - 'id': `https://${activityPub.domain}/activitypub/users/${name}#main-key`, - 'owner': `https://${activityPub.domain}/activitypub/users/${name}`, + 'id': `https://${activityPub.hostname}/activitypub/users/${name}#main-key`, + 'owner': `https://${activityPub.hostname}/activitypub/users/${name}`, 'publicKeyPem': pubkey } } @@ -28,12 +28,12 @@ export function createActor (name, pubkey) { export function createWebFinger (name) { return { - 'subject': `acct:${name}@${activityPub.domain}`, + 'subject': `acct:${name}@${activityPub.hostname}`, 'links': [ { 'rel': 'self', 'type': 'application/activity+json', - 'href': `https://${activityPub.domain}/users/${name}` + 'href': `https://${activityPub.hostname}/activitypub/users/${name}` } ] } diff --git a/backend/src/activitypub/utils/collection.js b/backend/src/activitypub/utils/collection.js index 4c46adbde..e0a8518eb 100644 --- a/backend/src/activitypub/utils/collection.js +++ b/backend/src/activitypub/utils/collection.js @@ -5,10 +5,10 @@ const debug = require('debug')('ea:utils:collections') export function createOrderedCollection (name, collectionName) { return { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': `https://${activityPub.domain}/activitypub/users/${name}/${collectionName}`, + 'id': `https://${activityPub.hostname}/activitypub/users/${name}/${collectionName}`, 'summary': `${name}s ${collectionName} collection`, 'type': 'OrderedCollection', - 'first': `https://${activityPub.domain}/activitypub/users/${name}/${collectionName}?page=true`, + 'first': `https://${activityPub.hostname}/activitypub/users/${name}/${collectionName}?page=true`, 'totalItems': 0 } } @@ -16,11 +16,11 @@ export function createOrderedCollection (name, collectionName) { export function createOrderedCollectionPage (name, collectionName) { return { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': `https://${activityPub.domain}/activitypub/users/${name}/${collectionName}?page=true`, + 'id': `https://${activityPub.hostname}/activitypub/users/${name}/${collectionName}?page=true`, 'summary': `${name}s ${collectionName} collection`, 'type': 'OrderedCollectionPage', 'totalItems': 0, - 'partOf': `https://${activityPub.domain}/activitypub/users/${name}/${collectionName}`, + 'partOf': `https://${activityPub.hostname}/activitypub/users/${name}/${collectionName}`, 'orderedItems': [] } } diff --git a/backend/src/activitypub/utils/index.js b/backend/src/activitypub/utils/index.js index c48e15e3d..72298d73f 100644 --- a/backend/src/activitypub/utils/index.js +++ b/backend/src/activitypub/utils/index.js @@ -20,7 +20,7 @@ export function extractIdFromActivityId (uri) { return splitted[splitted.indexOf('status') + 1] } -export function constructIdFromName (name, fromDomain = activityPub.domain) { +export function constructIdFromName (name, fromDomain = activityPub.hostname) { return `http://${fromDomain}/activitypub/users/${name}` } @@ -76,7 +76,7 @@ export function signAndSend (activity, fromName, targetDomain, url) { 'Host': targetDomain, 'Date': date, 'Signature': createSignature({ privateKey, - keyId: `http://${activityPub.domain}/activitypub/users/${fromName}#main-key`, + keyId: `http://${activityPub.hostname}/activitypub/users/${fromName}#main-key`, url, headers: { 'Host': targetDomain,