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,346 @@
1
+ /*
2
+
3
+ NodeBB Integration Layer
4
+
5
+
6
+ NodeBB Users Adapter
7
+
8
+
9
+
10
+ */
11
+
12
+
13
+
14
+
15
+ const NodeBB =
16
+ require("./index");
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ let nativeUsers = null;
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+ function loadNative() {
45
+
46
+
47
+
48
+
49
+ if(nativeUsers) {
50
+
51
+
52
+ return nativeUsers;
53
+
54
+
55
+ }
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ try {
65
+
66
+
67
+
68
+ if(
69
+
70
+ require.main &&
71
+
72
+ require.main.require
73
+
74
+ ) {
75
+
76
+
77
+
78
+ nativeUsers =
79
+
80
+ require.main.require(
81
+
82
+ "./src/user"
83
+
84
+ );
85
+
86
+
87
+ }
88
+
89
+
90
+
91
+ }
92
+
93
+
94
+ catch(error) {
95
+
96
+
97
+ nativeUsers = null;
98
+
99
+
100
+ }
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+ return nativeUsers;
109
+
110
+
111
+
112
+
113
+ }
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ async function getUser(uid) {
128
+
129
+
130
+
131
+
132
+ const users =
133
+
134
+ loadNative();
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+ /*
144
+ * Native NodeBB mode
145
+ */
146
+
147
+
148
+ if(
149
+
150
+ users &&
151
+
152
+ typeof users.getUserFields === "function"
153
+
154
+ ) {
155
+
156
+
157
+
158
+ return await users.getUserFields(
159
+
160
+ uid,
161
+
162
+ [
163
+
164
+ "uid",
165
+
166
+ "username",
167
+
168
+ "userslug",
169
+
170
+ "email",
171
+
172
+ "picture"
173
+
174
+ ]
175
+
176
+ );
177
+
178
+
179
+ }
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+ /*
189
+ * Standalone mode
190
+ */
191
+
192
+
193
+ return {
194
+
195
+
196
+ uid,
197
+
198
+
199
+ username:
200
+
201
+ "NodeBB unavailable",
202
+
203
+
204
+
205
+ userslug:
206
+
207
+ null,
208
+
209
+
210
+
211
+ email:
212
+
213
+ null,
214
+
215
+
216
+
217
+ picture:
218
+
219
+ null
220
+
221
+
222
+
223
+ };
224
+
225
+
226
+
227
+
228
+ }
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+ async function getUsers(uids = []) {
243
+
244
+
245
+
246
+
247
+ const result = [];
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+ for(const uid of uids) {
257
+
258
+
259
+
260
+ result.push(
261
+
262
+ await getUser(uid)
263
+
264
+ );
265
+
266
+
267
+ }
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+ return result;
276
+
277
+
278
+
279
+
280
+ }
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+ function info() {
295
+
296
+
297
+
298
+
299
+ return {
300
+
301
+
302
+ nodebb:
303
+
304
+ NodeBB.info(),
305
+
306
+
307
+
308
+ adapter:
309
+
310
+ "users"
311
+
312
+
313
+
314
+ };
315
+
316
+
317
+
318
+
319
+ }
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+ module.exports = {
334
+
335
+ getUser,
336
+
337
+
338
+ getUsers,
339
+
340
+
341
+ info
342
+
343
+
344
+
345
+
346
+ };
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+
3
+ /*
4
+
5
+ NodeBB Integration Layer
6
+
7
+
8
+ HTTP API routes
9
+
10
+
11
+
12
+ */
13
+
14
+
15
+
16
+
17
+ const Meta =
18
+ require("../nodebb/meta");
19
+
20
+ const Search =
21
+ require("../ai/search");
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ function init(router) {
36
+
37
+
38
+
39
+
40
+ if(!router) {
41
+
42
+
43
+ return false;
44
+
45
+
46
+ }
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+ router.get(
56
+
57
+ "/api/v3/integration/info",
58
+
59
+ async function(
60
+
61
+ req,
62
+
63
+ res
64
+
65
+ ) {
66
+
67
+
68
+
69
+ try {
70
+
71
+
72
+
73
+ const info =
74
+
75
+ await Meta.getInfo();
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+ res.json(info);
84
+
85
+
86
+
87
+ }
88
+
89
+
90
+ catch(error) {
91
+
92
+
93
+
94
+ res.status(500)
95
+
96
+ .json({
97
+
98
+ error:
99
+
100
+ error.message
101
+
102
+ });
103
+
104
+
105
+
106
+ }
107
+
108
+
109
+
110
+ }
111
+
112
+ );
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+ router.post(
123
+
124
+ "/api/v3/integration/search",
125
+
126
+ async function(
127
+
128
+ req,
129
+
130
+ res
131
+
132
+ ) {
133
+
134
+
135
+
136
+ try {
137
+
138
+
139
+
140
+ const query =
141
+
142
+ req.body.query;
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+ const limit =
151
+
152
+ req.body.limit || 5;
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+ const result =
161
+
162
+ await Search.searchText(
163
+
164
+ query,
165
+
166
+ limit
167
+
168
+ );
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+ res.json(result);
177
+
178
+
179
+
180
+ }
181
+
182
+
183
+ catch(error) {
184
+
185
+
186
+
187
+ res.status(500)
188
+
189
+ .json({
190
+
191
+ error:
192
+
193
+ error.message
194
+
195
+ });
196
+
197
+
198
+
199
+ }
200
+
201
+
202
+
203
+ }
204
+
205
+ );
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+ return true;
215
+
216
+
217
+
218
+
219
+ }
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+ module.exports = {
234
+
235
+ init
236
+
237
+
238
+
239
+
240
+ };
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ /*
4
+
5
+ NodeBB Integration Layer
6
+
7
+
8
+ Routes loader
9
+
10
+
11
+
12
+ */
13
+
14
+
15
+
16
+
17
+ const API =
18
+ require("./api");
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ function init(router) {
33
+
34
+
35
+
36
+
37
+ if(!router) {
38
+
39
+
40
+ console.log(
41
+
42
+ "[Routes] router unavailable"
43
+
44
+ );
45
+
46
+
47
+ return false;
48
+
49
+
50
+ }
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+ API.init(
60
+
61
+ router
62
+
63
+ );
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+ console.log(
73
+
74
+ "[Routes] initialized"
75
+
76
+ );
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+ return true;
85
+
86
+
87
+
88
+
89
+ }
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ module.exports = {
104
+
105
+ init
106
+
107
+
108
+
109
+
110
+ };