Skip to content

Commit

Permalink
Added in fixes from glitch that I missed for fetching user inboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomCasavant committed Nov 8, 2024
1 parent 492ef3e commit 3210abb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/activitypub.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ export async function signAndSend(message, name, domain, db, targetDomain, inbox
console.log(`Sent message to an inbox at ${targetDomain}!`);
console.log('Response Status Code:', response.status);
console.log('Response body:', data);
return response

Check failure on line 22 in src/activitypub.js

View workflow job for this annotation

GitHub Actions / Linting

Insert `;`
} catch (error) {
console.log('Error:', error.message);
console.log('Stacktrace: ', error.stack);
return error

Check failure on line 26 in src/activitypub.js

View workflow job for this annotation

GitHub Actions / Linting

Insert `;`
}
}

Expand Down Expand Up @@ -144,7 +146,7 @@ export async function createFollowMessage(account, domain, target, db) {
const guid = crypto.randomBytes(16).toString('hex');
const followMessage = {
'@context': 'https://www.w3.org/ns/activitystreams',
id: guid,
id: `https://${domain}/m/${guid}`,
type: 'Follow',
actor: `https://${domain}/u/${account}`,
object: target,
Expand Down Expand Up @@ -182,8 +184,9 @@ export async function createUnfollowMessage(account, domain, target, db) {
}

export async function getInboxFromActorProfile(profileUrl) {
const response = await signedGetJSON(`${profileUrl}.json`);
const response = await signedGetJSON(`${profileUrl}`);
const data = await response.json();
console.log(data);

if (data?.inbox) {
return data.inbox;
Expand All @@ -196,7 +199,7 @@ export async function lookupActorInfo(actorUsername) {
const parsedDomain = actorUsername.split('@').slice(-1);
const parsedUsername = actorUsername.split('@').slice(-2, -1);
try {
const response = await fetch(`https://${parsedDomain}/.well-known/webfinger/?resource=acct:${parsedUsername}@${parsedDomain}`);
const response = await fetch(`https://${parsedDomain}/.well-known/webfinger?resource=acct:${parsedUsername}@${parsedDomain}`);
const data = await response.json();
const selfLink = data.links.find((o) => o.rel === 'self');
if (!selfLink || !selfLink.href) {
Expand Down Expand Up @@ -276,4 +279,4 @@ export function synthesizeActivity(note) {
actor: note.attributedTo,
object: note,
};
}
}

Check failure on line 282 in src/activitypub.js

View workflow job for this annotation

GitHub Actions / Linting

Insert `⏎`
4 changes: 2 additions & 2 deletions src/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ export async function signedFetch(url, init = {}) {
*/
function _signedFetchJSON(url, method = 'GET', init = {}) {
const { body, headers = {}, ...rest } = init;
const contentTypeHeader = body ? { 'Content-Type': 'application/json' } : {};
const contentTypeHeader = body ? { 'Content-Type': 'application/activity+json' } : {};

return signedFetch(url, {
body,
headers: {
...headers,
Accept: 'application/json',
Accept: 'application/activity+json',
...contentTypeHeader,
},
...rest,
Expand Down

0 comments on commit 3210abb

Please sign in to comment.