nodebb-plugin-ezoic-infinite 1.5.18 → 1.5.21
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.
- package/library.js +23 -5
- package/package.json +1 -1
- package/public/client.js +706 -682
- package/public/style.css +21 -3
package/library.js
CHANGED
|
@@ -9,7 +9,11 @@ const plugin = {};
|
|
|
9
9
|
|
|
10
10
|
function normalizeExcludedGroups(value) {
|
|
11
11
|
if (!value) return [];
|
|
12
|
-
|
|
12
|
+
// NodeBB settings may return arrays, strings, or objects like {0:'a',1:'b'}
|
|
13
|
+
if (Array.isArray(value)) return value.map(String).map(s => s.trim()).filter(Boolean);
|
|
14
|
+
if (typeof value === 'object') {
|
|
15
|
+
return Object.values(value).map(String).map(s => s.trim()).filter(Boolean);
|
|
16
|
+
}
|
|
13
17
|
return String(value).split(',').map(s => s.trim()).filter(Boolean);
|
|
14
18
|
}
|
|
15
19
|
|
|
@@ -66,9 +70,19 @@ async function getSettings() {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
async function isUserExcluded(uid, excludedGroups) {
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
73
|
+
const list = (excludedGroups || []).map(g => String(g).toLowerCase());
|
|
74
|
+
const id = Number(uid) || 0;
|
|
75
|
+
|
|
76
|
+
if (!list.length) return false;
|
|
77
|
+
|
|
78
|
+
// Guests (uid=0) are not in groups.getUserGroups; treat explicitly if configured
|
|
79
|
+
if (id === 0) {
|
|
80
|
+
return list.includes('guests') || list.includes('guest');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const userGroups = await groups.getUserGroups([id]);
|
|
84
|
+
const names = (userGroups[0] || []).map(g => (g && g.name) ? g.name : String(g));
|
|
85
|
+
return names.some(name => list.includes(String(name).toLowerCase()));
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
plugin.onSettingsSet = function (data) {
|
|
@@ -107,7 +121,11 @@ plugin.init = async ({ router, middleware }) => {
|
|
|
107
121
|
|
|
108
122
|
router.get('/api/plugins/ezoic-infinite/config', async (req, res) => {
|
|
109
123
|
const settings = await getSettings();
|
|
110
|
-
const
|
|
124
|
+
const uid = (typeof req.uid !== 'undefined' && req.uid !== null) ? req.uid
|
|
125
|
+
: (req.user && req.user.uid) ? req.user.uid
|
|
126
|
+
: (res.locals && res.locals.uid) ? res.locals.uid
|
|
127
|
+
: 0;
|
|
128
|
+
const excluded = await isUserExcluded(uid, settings.excludedGroups);
|
|
111
129
|
|
|
112
130
|
res.json({
|
|
113
131
|
excluded,
|