@@ -2,7 +2,7 @@ const { getLinkText } = require("../../processLink");
2
2
3
3
/**
4
4
* 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)
6
6
* @param {import("../../middleware/setDataSigner").ResponseWithSigner } response
7
7
*/
8
8
async function resyncLink ( { link } , response ) {
@@ -24,7 +24,7 @@ async function resyncLink({ link }, response) {
24
24
* Fetches the content of a YouTube link. Returns the content as a text string of the video in question.
25
25
* We offer this as there may be some videos where a transcription could be manually edited after initial scraping
26
26
* 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)
28
28
* @param {import("../../middleware/setDataSigner").ResponseWithSigner } response
29
29
*/
30
30
async function resyncYouTube ( { link } , response ) {
@@ -44,9 +44,9 @@ async function resyncYouTube({ link }, response) {
44
44
}
45
45
46
46
/**
47
- * Fetches the content of a specific confluence page via its chunkSource.
47
+ * Fetches the content of a specific confluence page via its chunkSource.
48
48
* 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)
50
50
* @param {import("../../middleware/setDataSigner").ResponseWithSigner } response
51
51
*/
52
52
async function resyncConfluence ( { chunkSource } , response ) {
@@ -76,9 +76,9 @@ async function resyncConfluence({ chunkSource }, response) {
76
76
}
77
77
78
78
/**
79
- * Fetches the content of a specific confluence page via its chunkSource.
79
+ * Fetches the content of a specific confluence page via its chunkSource.
80
80
* 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)
82
82
* @param {import("../../middleware/setDataSigner").ResponseWithSigner } response
83
83
*/
84
84
async function resyncGithub ( { chunkSource } , response ) {
@@ -106,9 +106,48 @@ async function resyncGithub({ chunkSource }, response) {
106
106
}
107
107
}
108
108
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
+
109
147
module . exports = {
110
148
link : resyncLink ,
111
149
youtube : resyncYouTube ,
112
150
confluence : resyncConfluence ,
113
151
github : resyncGithub ,
114
- }
152
+ drupalwiki : resyncDrupalWiki ,
153
+ }
0 commit comments