Skip to content

Node.js based forum software built for the modern web

fix: interpolate parameters into template string, add schema for new route

Julian Lam15725b38021a
diff --git a/public/openapi/write.yaml b/public/openapi/write.yaml
index f22cf9f2cc..2b529e98cc 100644
--- a/public/openapi/write.yaml
+++ b/public/openapi/write.yaml
@@ -276,6 +276,8 @@ paths:
$ref: 'write/search/chats/roomId/users.yaml'
/search/chats/{roomId}/messages:
$ref: 'write/search/chats/roomId/messages.yaml'
+ /intents/query/{handle}:
+ $ref: 'write/intents/query/handle.yaml'
/admin/settings/{setting}:
$ref: 'write/admin/settings/setting.yaml'
/admin/analytics:
diff --git a/public/openapi/write/intents/query/handle.yaml b/public/openapi/write/intents/query/handle.yaml
new file mode 100644
index 0000000000..3b34107f5c
--- /dev/null
+++ b/public/openapi/write/intents/query/handle.yaml
@@ -0,0 +1,36 @@
+get:
+ tags:
+ - intents
+ summary: Query supported intents for a handle
+ description: This operation queries a handle to determine which ActivityPub intents it supports. The handle is resolved via WebFinger and the ActivityPub actor is fetched to extract supported intent endpoints.
+ parameters:
+ - in: path
+ name: handle
+ required: true
+ schema:
+ type: string
+ description: The ActivityPub handle to query, in the format @username@domain or username@domain
+ example: foobar%40example.org
+ responses:
+ '200':
+ description: Intent query successful
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ status:
+ $ref: ../../../components/schemas/Status.yaml#/Status
+ response:
+ type: object
+ properties:
+ intents:
+ type: array
+ items:
+ type: object
+ description: Map of supported intent names to their ActivityPub endpoint templates
+ additionalProperties:
+ type: string
+ example: 'https://example.org/ap?resource={object}'
+ '429':
+ description: Rate limit exceeded
diff --git a/public/src/modules/intents.js b/public/src/modules/intents.js
index 76c8ad98a7..6b762afe43 100644
--- a/public/src/modules/intents.js
+++ b/public/src/modules/intents.js
@@ -181,11 +181,21 @@ export function trigger(intent, parameters) {
modal.on('click', '[data-action="execute-intent"]', function () {
const handle = $(this).attr('data-handle');
const intents = map.get(handle);
- const template = intents && intents[requiredIntent];
+ let url = intents && intents[requiredIntent];
+
+ // Replace template placeholders with URL-encoded parameter values
+ if (url && parameters && typeof parameters === 'object') {
+ Object.keys(parameters).forEach((prop) => {
+ const value = parameters[prop];
+ const match = `{${prop}}`;
+ if (url.includes(match)) {
+ url = url.replaceAll(match, encodeURIComponent(value));
+ }
+ });
+ }
- // todo: replace placeholders in the template with data from parameters. The properties and placeholders are identically named.
- if (template) {
- window.location.href = template;
+ if (url) {
+ window.location.href = url;
}
});
diff --git a/test/api/schema.js b/test/api/schema.js
index ac84d640a5..334a7061ca 100644
--- a/test/api/schema.js
+++ b/test/api/schema.js
@@ -362,7 +362,7 @@ async function setupData() {
// Retrieve CSRF token using cookie, to test Write API
csrfToken = await helpers.getCsrfToken(jar);
- // Pre-seed ActivityPub cache so contrived actor assertions pass
+ // Pre-seed ActivityPub & webfinger cache so contrived actor assertions pass
activitypub._cache.set(`0;https://example.org/foobar`, {
id: 'https://example.org/foobar',
name: 'foobar',
@@ -372,6 +372,7 @@ async function setupData() {
publicKeyPem: 'secretcat',
},
});
+ activitypub.helpers._webfingerCache.set('[email protected]', { actorUri: 'https://example.org/foobar' });
}
describe('schema', () => {
@@ -577,7 +578,7 @@ describe('schema', () => {
return;
}
- assert.strictEqual(this.result.response.statusCode, 200, `HTTP 200 expected (path: ${method} ${path}`);
+ assert.strictEqual(this.result.response.statusCode, 200, `HTTP 200 expected (path: ${method} ${path})`);
const hasJSON = http200.content && http200.content['application/json'];
if (hasJSON) {