From d91ce83d392801fd592adeb08a7674b4017ffe82 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 24 Mar 2023 18:37:55 +0100 Subject: Add filter:html.client.json-ld.result hook --- server/tests/fixtures/peertube-plugin-test/main.js | 15 +++++++++++++++ server/tests/plugins/filter-hooks.ts | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'server/tests') diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index 84b479548..36dd08d27 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js @@ -312,6 +312,8 @@ async function register ({ registerHook, registerSetting, settingsManager, stora } }) + // --------------------------------------------------------------------------- + registerHook({ target: 'filter:html.embed.video.allowed.result', handler: (result, params) => { @@ -332,6 +334,19 @@ async function register ({ registerHook, registerSetting, settingsManager, stora } }) + // --------------------------------------------------------------------------- + + registerHook({ + target: 'filter:html.client.json-ld.result', + handler: (jsonld, context) => { + if (!context || !context.video) return jsonld + + return Object.assign(jsonld, { recordedAt: 'http://example.com/recordedAt' }) + } + }) + + // --------------------------------------------------------------------------- + registerHook({ target: 'filter:api.server.stats.get.result', handler: (result) => { diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 4d26ff8b7..43749b0b5 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -605,6 +605,27 @@ describe('Test plugin filter hooks', function () { }) }) + describe('Client HTML filters', function () { + let videoUUID: string + + before(async function () { + this.timeout(60000) + + const { uuid } = await servers[0].videos.quickUpload({ name: 'html video' }) + videoUUID = uuid + }) + + it('Should run filter:html.client.json-ld.result', async function () { + const res = await makeGetRequest({ url: servers[0].url, path: '/w/' + videoUUID, expectedStatus: HttpStatusCode.OK_200 }) + expect(res.text).to.contain('"recordedAt":"http://example.com/recordedAt"') + }) + + it('Should not run filter:html.client.json-ld.result with an account', async function () { + const res = await makeGetRequest({ url: servers[0].url, path: '/a/root', expectedStatus: HttpStatusCode.OK_200 }) + expect(res.text).not.to.contain('"recordedAt":"http://example.com/recordedAt"') + }) + }) + describe('Search filters', function () { before(async function () { -- cgit v1.2.3