Skip to content

Commit 0ae847b

Browse files
Merge branch 'master' into 3698-main-screen-localization
2 parents 13ed5a5 + 1601eb9 commit 0ae847b

File tree

22 files changed

+954
-17
lines changed

22 files changed

+954
-17
lines changed

collector/extensions/index.js

+26
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,32 @@ function extensions(app) {
154154
return;
155155
}
156156
);
157+
158+
app.post(
159+
"/ext/drupalwiki",
160+
[verifyPayloadIntegrity, setDataSigner],
161+
async function (request, response) {
162+
try {
163+
const { loadAndStoreSpaces } = require("../utils/extensions/DrupalWiki");
164+
const { success, reason, data } = await loadAndStoreSpaces(
165+
reqBody(request),
166+
response
167+
);
168+
response.status(200).json({ success, reason, data });
169+
} catch (e) {
170+
console.error(e);
171+
response.status(400).json({
172+
success: false,
173+
reason: e.message,
174+
data: {
175+
title: null,
176+
author: null,
177+
},
178+
});
179+
}
180+
return;
181+
}
182+
);
157183
}
158184

159185
module.exports = extensions;

collector/extensions/resync/index.js

+46-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { getLinkText } = require("../../processLink");
22

33
/**
44
* Fetches the content of a raw link. Returns the content as a text string of the link in question.
5-
* @param {object} data - metadata from document (eg: link)
5+
* @param {object} data - metadata from document (eg: link)
66
* @param {import("../../middleware/setDataSigner").ResponseWithSigner} response
77
*/
88
async function resyncLink({ link }, response) {
@@ -24,7 +24,7 @@ async function resyncLink({ link }, response) {
2424
* Fetches the content of a YouTube link. Returns the content as a text string of the video in question.
2525
* We offer this as there may be some videos where a transcription could be manually edited after initial scraping
2626
* but in general - transcriptions often never change.
27-
* @param {object} data - metadata from document (eg: link)
27+
* @param {object} data - metadata from document (eg: link)
2828
* @param {import("../../middleware/setDataSigner").ResponseWithSigner} response
2929
*/
3030
async function resyncYouTube({ link }, response) {
@@ -44,9 +44,9 @@ async function resyncYouTube({ link }, response) {
4444
}
4545

4646
/**
47-
* Fetches the content of a specific confluence page via its chunkSource.
47+
* Fetches the content of a specific confluence page via its chunkSource.
4848
* Returns the content as a text string of the page in question and only that page.
49-
* @param {object} data - metadata from document (eg: chunkSource)
49+
* @param {object} data - metadata from document (eg: chunkSource)
5050
* @param {import("../../middleware/setDataSigner").ResponseWithSigner} response
5151
*/
5252
async function resyncConfluence({ chunkSource }, response) {
@@ -76,9 +76,9 @@ async function resyncConfluence({ chunkSource }, response) {
7676
}
7777

7878
/**
79-
* Fetches the content of a specific confluence page via its chunkSource.
79+
* Fetches the content of a specific confluence page via its chunkSource.
8080
* Returns the content as a text string of the page in question and only that page.
81-
* @param {object} data - metadata from document (eg: chunkSource)
81+
* @param {object} data - metadata from document (eg: chunkSource)
8282
* @param {import("../../middleware/setDataSigner").ResponseWithSigner} response
8383
*/
8484
async function resyncGithub({ chunkSource }, response) {
@@ -106,9 +106,48 @@ async function resyncGithub({ chunkSource }, response) {
106106
}
107107
}
108108

109+
110+
/**
111+
* Fetches the content of a specific DrupalWiki page via its chunkSource.
112+
* Returns the content as a text string of the page in question and only that page.
113+
* @param {object} data - metadata from document (eg: chunkSource)
114+
* @param {import("../../middleware/setDataSigner").ResponseWithSigner} response
115+
*/
116+
async function resyncDrupalWiki({ chunkSource }, response) {
117+
if (!chunkSource) throw new Error('Invalid source property provided');
118+
try {
119+
// DrupalWiki data is `payload` encrypted. So we need to expand its
120+
// encrypted payload back into query params so we can reFetch the page with same access token/params.
121+
const source = response.locals.encryptionWorker.expandPayload(chunkSource);
122+
const { loadPage } = require("../../utils/extensions/DrupalWiki");
123+
const { success, reason, content } = await loadPage({
124+
baseUrl: source.searchParams.get('baseUrl'),
125+
pageId: source.searchParams.get('pageId'),
126+
accessToken: source.searchParams.get('accessToken'),
127+
});
128+
129+
if (!success) {
130+
console.error(`Failed to sync DrupalWiki page content. ${reason}`);
131+
response.status(200).json({
132+
success: false,
133+
content: null,
134+
});
135+
} else {
136+
response.status(200).json({ success, content });
137+
}
138+
} catch (e) {
139+
console.error(e);
140+
response.status(200).json({
141+
success: false,
142+
content: null,
143+
});
144+
}
145+
}
146+
109147
module.exports = {
110148
link: resyncLink,
111149
youtube: resyncYouTube,
112150
confluence: resyncConfluence,
113151
github: resyncGithub,
114-
}
152+
drupalwiki: resyncDrupalWiki,
153+
}

collector/middleware/verifyIntegrity.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const { CommunicationKey } = require("../utils/comKey");
2+
const RuntimeSettings = require("../utils/runtimeSettings");
3+
const runtimeSettings = new RuntimeSettings();
24

35
function verifyPayloadIntegrity(request, response, next) {
46
const comKey = new CommunicationKey();
57
if (process.env.NODE_ENV === "development") {
6-
comKey.log('verifyPayloadIntegrity is skipped in development.')
8+
comKey.log('verifyPayloadIntegrity is skipped in development.');
9+
runtimeSettings.parseOptionsFromRequest(request);
710
next();
811
return;
912
}
@@ -12,7 +15,9 @@ function verifyPayloadIntegrity(request, response, next) {
1215
if (!signature) return response.status(400).json({ msg: 'Failed integrity signature check.' })
1316

1417
const validSignedPayload = comKey.verify(signature, request.body);
15-
if (!validSignedPayload) return response.status(400).json({ msg: 'Failed integrity signature check.' })
18+
if (!validSignedPayload) return response.status(400).json({ msg: 'Failed integrity signature check.' });
19+
20+
runtimeSettings.parseOptionsFromRequest(request);
1621
next();
1722
}
1823

0 commit comments

Comments
 (0)