Skip to content

Commit

Permalink
Run again prettier after fix (middleware)
Browse files Browse the repository at this point in the history
  • Loading branch information
srosset81 committed Sep 15, 2023
1 parent e72245f commit 07fb3c5
Show file tree
Hide file tree
Showing 147 changed files with 2,096 additions and 2,098 deletions.
11 changes: 5 additions & 6 deletions src/middleware/packages/activitypub/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const appendPrefix = (types) =>
Object.fromEntries(Object.entries(types).map(([key, value]) => [key, AS_PREFIX + value]));
const appendPrefix = types => Object.fromEntries(Object.entries(types).map(([key, value]) => [key, AS_PREFIX + value]));

const AS_PREFIX = 'https://www.w3.org/ns/activitystreams#';

Expand Down Expand Up @@ -33,15 +32,15 @@ const ACTIVITY_TYPES = {
TRAVAL: 'Travel',
UNDO: 'Undo',
UPDATE: 'Update',
VIEW: 'View',
VIEW: 'View'
};

const ACTOR_TYPES = {
APPLICATION: 'Application',
GROUP: 'Group',
ORGANIZATION: 'Organization',
PERSON: 'Person',
SERVICE: 'Service',
SERVICE: 'Service'
};

const OBJECT_TYPES = {
Expand All @@ -56,7 +55,7 @@ const OBJECT_TYPES = {
PROFILE: 'Profile',
RELATIONSHIP: 'Relationship',
TOMBSTONE: 'Tombstone',
VIDEO: 'Video',
VIDEO: 'Video'
};

module.exports = {
Expand All @@ -67,5 +66,5 @@ module.exports = {
OBJECT_TYPES,
FULL_ACTIVITY_TYPES: appendPrefix(ACTIVITY_TYPES),
FULL_ACTOR_TYPES: appendPrefix(ACTOR_TYPES),
FULL_OBJECT_TYPES: appendPrefix(OBJECT_TYPES),
FULL_OBJECT_TYPES: appendPrefix(OBJECT_TYPES)
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ActivitiesHandlerMixin = {
methods: {
matchActivity(ctx, pattern, activityOrObject) {
return matchActivity(ctx, pattern, activityOrObject);
},
}
},
events: {
async 'activitypub.outbox.posted'(ctx) {
Expand Down Expand Up @@ -73,8 +73,8 @@ const ActivitiesHandlerMixin = {
}
}
}
},
},
}
}
};

module.exports = ActivitiesHandlerMixin;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
dereferenceItems: false,
sort: { predicate: 'as:published', order: 'DESC' },
permissions: null,
controlledActions: {},
controlledActions: {}
},
dependencies: ['activitypub.registry'],
async started() {
Expand All @@ -27,8 +27,8 @@ module.exports = {
controlledActions: {
get: `${this.name}.get`,
post: `${this.name}.post`,
...this.settings.controlledActions,
},
...this.settings.controlledActions
}
});
},
actions: {
Expand All @@ -37,12 +37,12 @@ module.exports = {
},
post() {
throw new E.ForbiddenError();
},
}
},
methods: {
async getCollectionUri(webId) {
// TODO make this work
return this.broker.call('activitypub.registry.getUri', { path: this.settings.path, webId });
},
},
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { parseHeader, parseJson, saveDatasetMeta } = require('@semapps/middlewares');

const addCollectionUriMiddleware = (collectionUri) => (req, res, next) => {
const addCollectionUriMiddleware = collectionUri => (req, res, next) => {
let fullCollectionUri = collectionUri;
// TODO find a tool to parse this automatically
if (collectionUri.includes('/:username')) {
Expand All @@ -25,8 +25,8 @@ const getCollectionRoute = (collectionUri, controlledActions) => {
'GET /': [
...middlewares,
addCollectionUriMiddleware(collectionUri),
(controlledActions && controlledActions.get) || 'activitypub.collection.get',
],
(controlledActions && controlledActions.get) || 'activitypub.collection.get'
]
};
if (controlledActions && controlledActions.post) {
aliases['POST /'] = [...middlewares, addCollectionUriMiddleware(collectionUri), controlledActions.post];
Expand All @@ -38,7 +38,7 @@ const getCollectionRoute = (collectionUri, controlledActions) => {
authorization: false,
authentication: true,
bodyParsers: false,
aliases,
aliases
};
};

Expand Down
20 changes: 10 additions & 10 deletions src/middleware/packages/activitypub/services/activity-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const ActivityMappingService = {
settings: {
mappers: [],
handlebars: {
helpers: {},
helpers: {}
},
matchAnnouncedActivities: false,
matchAnnouncedActivities: false
},
async started() {
this.mappers = [];
Expand All @@ -36,7 +36,7 @@ const ActivityMappingService = {

activity = {
actor: activity.actor, // Ensure the actor is defined
...announcedActivity,
...announcedActivity
};
}

Expand All @@ -57,7 +57,7 @@ const ActivityMappingService = {
: {};
} catch (e) {
this.logger.warn(
`Could not get profile of actor ${activity.actor} (webId ${ctx.meta.webId} / dataset ${ctx.meta.dataset})`,
`Could not get profile of actor ${activity.actor} (webId ${ctx.meta.webId} / dataset ${ctx.meta.dataset})`
);
}

Expand All @@ -74,7 +74,7 @@ const ActivityMappingService = {
return [key, value[locale](templateParams)];
}
throw new Error(`No ${locale} locale found for key ${key}`);
}),
})
);
}
}
Expand All @@ -87,15 +87,15 @@ const ActivityMappingService = {
this.mappers.push({
match,
mapping: this.compileObject(mapping),
priority,
priority
});

// Reorder cached mappings
this.prioritizeMappers();
},
getMappers() {
return this.mappers;
},
}
},
methods: {
matchActivity(ctx, pattern, activityOrObject) {
Expand All @@ -113,11 +113,11 @@ const ActivityMappingService = {
return [key, Handlebars.compile(value)];
}
return [key, this.compileObject(value)];
}),
})
)
);
},
},
}
}
};

module.exports = ActivityMappingService;
50 changes: 25 additions & 25 deletions src/middleware/packages/activitypub/services/activitypub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ const ActivityPubService = {
queueServiceUrl: null,
like: {
attachToObjectTypes: null,
attachToActorTypes: null,
attachToActorTypes: null
},
follow: {
attachToActorTypes: null,
attachToActorTypes: null
},
reply: {
attachToObjectTypes: null,
},
attachToObjectTypes: null
}
},
dependencies: ['api'],
created() {
Expand All @@ -37,79 +37,79 @@ const ActivityPubService = {
this.broker.createService(CollectionService, {
settings: {
jsonContext,
podProvider,
},
podProvider
}
});

this.broker.createService(RegistryService, {
settings: {
baseUri,
jsonContext,
podProvider,
},
podProvider
}
});

this.broker.createService(ActorService, {
settings: {
baseUri,
jsonContext,
selectActorData,
podProvider,
},
podProvider
}
});

this.broker.createService(ObjectService, {
settings: {
baseUri,
podProvider,
},
podProvider
}
});

this.broker.createService(ActivityService, {
settings: {
baseUri,
jsonContext,
},
jsonContext
}
});

this.broker.createService(FollowService, {
settings: {
baseUri,
attachToActorTypes: follow.attachToActorTypes || Object.values(ACTOR_TYPES),
},
attachToActorTypes: follow.attachToActorTypes || Object.values(ACTOR_TYPES)
}
});

this.broker.createService(InboxService, {
settings: {
baseUri,
podProvider,
},
podProvider
}
});

this.broker.createService(LikeService, {
settings: {
baseUri,
attachToObjectTypes: like.attachToObjectTypes || Object.values(OBJECT_TYPES),
attachToActorTypes: like.attachToActorTypes || Object.values(ACTOR_TYPES),
},
attachToActorTypes: like.attachToActorTypes || Object.values(ACTOR_TYPES)
}
});

this.broker.createService(ReplyService, {
settings: {
baseUri,
attachToObjectTypes: reply.attachToObjectTypes || Object.values(OBJECT_TYPES),
},
attachToObjectTypes: reply.attachToObjectTypes || Object.values(OBJECT_TYPES)
}
});

this.broker.createService(OutboxService, {
mixins: queueServiceUrl ? [QueueService(queueServiceUrl)] : undefined,
settings: {
baseUri,
jsonContext,
podProvider,
},
podProvider
}
});
},
}
};

module.exports = ActivityPubService;
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const ActivityService = {
// Activities shouldn't be handled manually
patch: 'activitypub.activity.forbidden',
put: 'activitypub.activity.forbidden',
delete: 'activitypub.activity.forbidden',
},
delete: 'activitypub.activity.forbidden'
}
},
dependencies: ['ldp.container'],
actions: {
Expand Down Expand Up @@ -53,7 +53,7 @@ const ActivityService = {
if (recipient.startsWith(this.settings.baseUri)) {
const collection = await ctx.call('activitypub.collection.get', {
collectionUri: recipient,
webId: activity.actor,
webId: activity.actor
});
if (collection && collection.items) output.push(...defaultToArray(collection.items));
}
Expand All @@ -73,21 +73,21 @@ const ActivityService = {
async getLocalRecipients(ctx) {
const { activity } = ctx.params;
const recipients = await this.actions.getRecipients({ activity }, { parentCtx: ctx });
return recipients.filter((recipientUri) => this.isLocalActor(recipientUri));
return recipients.filter(recipientUri => this.isLocalActor(recipientUri));
},
isPublic(ctx) {
const { activity } = ctx.params;
// We accept all three representations, as required by https://www.w3.org/TR/activitypub/#public-addressing
const publicRepresentations = [PUBLIC_URI, 'Public', 'as:Public'];
return defaultToArray(activity.to)
? defaultToArray(activity.to).some((r) => publicRepresentations.includes(r))
? defaultToArray(activity.to).some(r => publicRepresentations.includes(r))
: false;
},
}
},
methods: {
isLocalActor(uri) {
return uri.startsWith(this.settings.baseUri);
},
}
},
hooks: {
before: {
Expand All @@ -98,14 +98,14 @@ const ActivityService = {
},
create(ctx) {
ctx.params.resource = objectIdToCurrent(ctx.params.resource);
},
}
},
after: {
get(ctx, res) {
return objectCurrentToId(res);
},
},
},
}
}
}
};

module.exports = ActivityService;
Loading

0 comments on commit 07fb3c5

Please sign in to comment.