nodebb-plugin-integration 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,348 @@
1
+ "use strict";
2
+
3
+ /*
4
+
5
+ NodeBB Integration Layer
6
+
7
+
8
+ NodeBB Posts Adapter
9
+
10
+
11
+
12
+ */
13
+
14
+
15
+
16
+
17
+ const NodeBB =
18
+ require("./index");
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ let nativePosts = null;
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ function loadNative() {
47
+
48
+
49
+
50
+
51
+ if(nativePosts) {
52
+
53
+
54
+ return nativePosts;
55
+
56
+
57
+ }
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+ try {
67
+
68
+
69
+
70
+ if(
71
+
72
+ require.main &&
73
+
74
+ require.main.require
75
+
76
+ ) {
77
+
78
+
79
+
80
+ nativePosts =
81
+
82
+ require.main.require(
83
+
84
+ "./src/posts"
85
+
86
+ );
87
+
88
+
89
+ }
90
+
91
+
92
+
93
+ }
94
+
95
+
96
+ catch(error) {
97
+
98
+
99
+ nativePosts = null;
100
+
101
+
102
+ }
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ return nativePosts;
111
+
112
+
113
+
114
+
115
+ }
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+ async function getPost(pid) {
130
+
131
+
132
+
133
+
134
+ const posts =
135
+
136
+ loadNative();
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ /*
146
+ * Native NodeBB mode
147
+ */
148
+
149
+
150
+ if(
151
+
152
+ posts &&
153
+
154
+ typeof posts.getPostFields === "function"
155
+
156
+ ) {
157
+
158
+
159
+
160
+ return await posts.getPostFields(
161
+
162
+ pid,
163
+
164
+ [
165
+
166
+ "pid",
167
+
168
+ "tid",
169
+
170
+ "uid",
171
+
172
+ "content",
173
+
174
+ "timestamp"
175
+
176
+ ]
177
+
178
+ );
179
+
180
+
181
+ }
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+ /*
191
+ * Standalone mode
192
+ */
193
+
194
+
195
+ return {
196
+
197
+
198
+ pid,
199
+
200
+
201
+ tid:
202
+
203
+ null,
204
+
205
+
206
+
207
+ uid:
208
+
209
+ null,
210
+
211
+
212
+
213
+ content:
214
+
215
+ "NodeBB unavailable",
216
+
217
+
218
+
219
+ timestamp:
220
+
221
+ Date.now()
222
+
223
+
224
+
225
+ };
226
+
227
+
228
+
229
+
230
+ }
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+ async function getPosts(pids = []) {
245
+
246
+
247
+
248
+
249
+ const result = [];
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+ for(const pid of pids) {
259
+
260
+
261
+
262
+ result.push(
263
+
264
+ await getPost(pid)
265
+
266
+ );
267
+
268
+
269
+ }
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+ return result;
278
+
279
+
280
+
281
+
282
+ }
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+ function info() {
297
+
298
+
299
+
300
+
301
+ return {
302
+
303
+
304
+ nodebb:
305
+
306
+ NodeBB.info(),
307
+
308
+
309
+
310
+ adapter:
311
+
312
+ "posts"
313
+
314
+
315
+
316
+ };
317
+
318
+
319
+
320
+
321
+ }
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+ module.exports = {
336
+
337
+ getPost,
338
+
339
+
340
+ getPosts,
341
+
342
+
343
+ info
344
+
345
+
346
+
347
+
348
+ };
@@ -0,0 +1,356 @@
1
+ "use strict";
2
+
3
+ /*
4
+
5
+ NodeBB Integration Layer
6
+
7
+
8
+ NodeBB Topics Adapter
9
+
10
+
11
+
12
+ */
13
+
14
+
15
+
16
+
17
+ const NodeBB =
18
+ require("./index");
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ let nativeTopics = null;
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ function loadNative() {
47
+
48
+
49
+
50
+
51
+ if(nativeTopics) {
52
+
53
+
54
+ return nativeTopics;
55
+
56
+
57
+ }
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+ try {
67
+
68
+
69
+
70
+ if(
71
+
72
+ require.main &&
73
+
74
+ require.main.require
75
+
76
+ ) {
77
+
78
+
79
+
80
+ nativeTopics =
81
+
82
+ require.main.require(
83
+
84
+ "./src/topics"
85
+
86
+ );
87
+
88
+
89
+ }
90
+
91
+
92
+
93
+ }
94
+
95
+
96
+ catch(error) {
97
+
98
+
99
+ nativeTopics = null;
100
+
101
+
102
+ }
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ return nativeTopics;
111
+
112
+
113
+
114
+
115
+ }
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+ async function getTopic(tid) {
130
+
131
+
132
+
133
+
134
+ const topics =
135
+
136
+ loadNative();
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ /*
146
+ * Native NodeBB mode
147
+ */
148
+
149
+
150
+ if(
151
+
152
+ topics &&
153
+
154
+ typeof topics.getTopicFields === "function"
155
+
156
+ ) {
157
+
158
+
159
+
160
+ return await topics.getTopicFields(
161
+
162
+ tid,
163
+
164
+ [
165
+
166
+ "tid",
167
+
168
+ "uid",
169
+
170
+ "title",
171
+
172
+ "cid",
173
+
174
+ "timestamp",
175
+
176
+ "mainPid"
177
+
178
+ ]
179
+
180
+ );
181
+
182
+
183
+ }
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+ /*
193
+ * Standalone mode
194
+ */
195
+
196
+
197
+ return {
198
+
199
+
200
+ tid,
201
+
202
+
203
+ uid:
204
+
205
+ null,
206
+
207
+
208
+
209
+ title:
210
+
211
+ "NodeBB unavailable",
212
+
213
+
214
+
215
+ cid:
216
+
217
+ null,
218
+
219
+
220
+
221
+ timestamp:
222
+
223
+ Date.now(),
224
+
225
+
226
+
227
+ mainPid:
228
+
229
+ null
230
+
231
+
232
+
233
+ };
234
+
235
+
236
+
237
+
238
+ }
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+ async function getTopics(tids = []) {
253
+
254
+
255
+
256
+
257
+ const result = [];
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+ for(const tid of tids) {
267
+
268
+
269
+
270
+ result.push(
271
+
272
+ await getTopic(tid)
273
+
274
+ );
275
+
276
+
277
+ }
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+ return result;
286
+
287
+
288
+
289
+
290
+ }
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+ function info() {
305
+
306
+
307
+
308
+
309
+ return {
310
+
311
+
312
+ nodebb:
313
+
314
+ NodeBB.info(),
315
+
316
+
317
+
318
+ adapter:
319
+
320
+ "topics"
321
+
322
+
323
+
324
+ };
325
+
326
+
327
+
328
+
329
+ }
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+ module.exports = {
344
+
345
+ getTopic,
346
+
347
+
348
+ getTopics,
349
+
350
+
351
+ info
352
+
353
+
354
+
355
+
356
+ };