nodebb-plugin-niki-loyalty 1.2.2 → 1.2.3
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 +48 -54
- package/package.json +1 -1
- package/plugin.json +8 -28
package/library.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const db = require.main.require('./src/database');
|
|
4
2
|
const user = require.main.require('./src/user');
|
|
5
3
|
const posts = require.main.require('./src/posts');
|
|
6
4
|
const routeHelpers = require.main.require('./src/controllers/helpers');
|
|
7
5
|
const nconf = require.main.require('nconf');
|
|
8
6
|
const socketHelpers = require.main.require('./src/socket.io/index');
|
|
7
|
+
const SocketPlugins = require.main.require('./src/socket.io/plugins');
|
|
9
8
|
const Plugin = {};
|
|
10
9
|
|
|
11
10
|
// =========================
|
|
@@ -17,12 +16,12 @@ const SETTINGS = {
|
|
|
17
16
|
|
|
18
17
|
// Puan Tablosu ve Limitleri
|
|
19
18
|
const ACTIONS = {
|
|
20
|
-
login: { points:
|
|
21
|
-
new_topic: { points:
|
|
22
|
-
reply: { points: 3, limit: 2, name: 'Yorum Yazma 💬' },
|
|
23
|
-
read: { points: 1, limit: 8, name: 'Konu Okuma 👀' },
|
|
24
|
-
like_given: { points: 4, limit: 2, name: 'Beğeni Atma ❤️' },
|
|
25
|
-
like_taken: { points: 5, limit: 2, name: 'Beğeni Alma 🌟' }
|
|
19
|
+
login: { points: 2, limit: 1, name: 'Günlük Giriş 👋' },
|
|
20
|
+
new_topic: { points: 7, limit: 1, name: 'Yeni Konu 📝' },
|
|
21
|
+
reply: { points: 3.5, limit: 2, name: 'Yorum Yazma 💬' },
|
|
22
|
+
read: { points: 1, limit: 8, name: 'Konu Okuma 👀' }, // Heartbeat ile çalışır
|
|
23
|
+
like_given: { points: 4, limit: 2, name: 'Beğeni Atma ❤️' }, // 4 puan x 2 = max 8
|
|
24
|
+
like_taken: { points: 5, limit: 2, name: 'Beğeni Alma 🌟' } // 5 puan x 2 = max 10
|
|
26
25
|
};
|
|
27
26
|
|
|
28
27
|
// Ödüller
|
|
@@ -356,51 +355,6 @@ Plugin.init = async function (params) {
|
|
|
356
355
|
if (!isStaff) return res.render('403', {});
|
|
357
356
|
return res.render('niki-kasa', { title: 'Niki Kasa' });
|
|
358
357
|
});
|
|
359
|
-
|
|
360
|
-
// 7) (niki-admin artık Custom Page ile yönetiliyor, route kaldırıldı)
|
|
361
|
-
|
|
362
|
-
// 8) ADMIN API - TÜM KULLANICILARIN PUANLARI
|
|
363
|
-
router.get('/api/niki-loyalty/admin/users', middleware.ensureLoggedIn, async (req, res) => {
|
|
364
|
-
try {
|
|
365
|
-
console.log('[Niki-Loyalty] Admin API called, uid:', req.uid);
|
|
366
|
-
|
|
367
|
-
const isAdmin = await user.isAdministrator(req.uid);
|
|
368
|
-
const isMod = await user.isGlobalModerator(req.uid);
|
|
369
|
-
|
|
370
|
-
console.log('[Niki-Loyalty] isAdmin:', isAdmin, 'isMod:', isMod);
|
|
371
|
-
|
|
372
|
-
if (!isAdmin && !isMod) {
|
|
373
|
-
console.log('[Niki-Loyalty] Access denied for uid:', req.uid);
|
|
374
|
-
return res.status(403).json({ error: 'Yetkisiz' });
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// Tüm kullanıcıları al (limit 500)
|
|
378
|
-
const uids = await db.getSortedSetRange('users:joindate', 0, 499);
|
|
379
|
-
if (!uids || uids.length === 0) return res.json([]);
|
|
380
|
-
|
|
381
|
-
// Kullanıcı bilgilerini al
|
|
382
|
-
const usersData = await user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture', 'niki_points', 'icon:bgColor']);
|
|
383
|
-
|
|
384
|
-
// Puanları olan kullanıcıları filtrele ve sırala
|
|
385
|
-
const result = usersData
|
|
386
|
-
.map(u => ({
|
|
387
|
-
uid: u.uid,
|
|
388
|
-
username: u.username,
|
|
389
|
-
userslug: u.userslug,
|
|
390
|
-
picture: u.picture || '',
|
|
391
|
-
iconBg: u['icon:bgColor'] || '#4b5563',
|
|
392
|
-
points: parseFloat(u.niki_points || 0)
|
|
393
|
-
}))
|
|
394
|
-
.filter(u => u.points > 0) // Sadece puanı olanlar
|
|
395
|
-
.sort((a, b) => b.points - a.points); // Yüksekten düşüğe sırala
|
|
396
|
-
|
|
397
|
-
console.log('[Niki-Loyalty] Returning', result.length, 'users');
|
|
398
|
-
return res.json(result);
|
|
399
|
-
} catch (err) {
|
|
400
|
-
console.error('[Niki-Loyalty] Admin users error:', err);
|
|
401
|
-
return res.status(500).json({ error: 'Sunucu hatası' });
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
358
|
};
|
|
405
359
|
|
|
406
360
|
Plugin.addScripts = async function (scripts) {
|
|
@@ -419,5 +373,45 @@ Plugin.addNavigation = async function (nav) {
|
|
|
419
373
|
return nav;
|
|
420
374
|
};
|
|
421
375
|
|
|
422
|
-
//
|
|
376
|
+
// =========================
|
|
377
|
+
// 🔌 SOCKET IO FONKSİYONLARI
|
|
378
|
+
// =========================
|
|
379
|
+
Plugin.adminGetUsers = async function (socket, data) {
|
|
380
|
+
// Yetki Kontrolü
|
|
381
|
+
const uid = socket.uid;
|
|
382
|
+
if (!uid) throw new Error('Giriş yapmalısınız.');
|
|
383
|
+
|
|
384
|
+
const isAdmin = await user.isAdministrator(uid);
|
|
385
|
+
const isMod = await user.isGlobalModerator(uid);
|
|
386
|
+
|
|
387
|
+
if (!isAdmin && !isMod) throw new Error('Yetkisiz Erişim');
|
|
388
|
+
|
|
389
|
+
// Tüm kullanıcıları al (limit 500)
|
|
390
|
+
const uids = await db.getSortedSetRange('users:joindate', 0, 499);
|
|
391
|
+
if (!uids || uids.length === 0) return [];
|
|
392
|
+
|
|
393
|
+
// Kullanıcı bilgilerini al
|
|
394
|
+
const usersData = await user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture', 'niki_points', 'icon:bgColor']);
|
|
395
|
+
|
|
396
|
+
// Puanları olan kullanıcıları filtrele ve sırala
|
|
397
|
+
const result = usersData
|
|
398
|
+
.map(u => ({
|
|
399
|
+
uid: u.uid,
|
|
400
|
+
username: u.username,
|
|
401
|
+
userslug: u.userslug,
|
|
402
|
+
picture: u.picture || '',
|
|
403
|
+
iconBg: u['icon:bgColor'] || '#4b5563',
|
|
404
|
+
points: parseFloat(u.niki_points || 0)
|
|
405
|
+
}))
|
|
406
|
+
.filter(u => u.points > 0) // Sadece puanı olanlar
|
|
407
|
+
.sort((a, b) => b.points - a.points); // Yüksekten düşüğe sırala
|
|
408
|
+
|
|
409
|
+
return result;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// Soket'e kaydet (Client: socket.emit('plugins.niki.getUsers', ...))
|
|
413
|
+
SocketPlugins.niki = {
|
|
414
|
+
getUsers: Plugin.adminGetUsers
|
|
415
|
+
};
|
|
416
|
+
|
|
423
417
|
module.exports = Plugin;
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -5,34 +5,14 @@
|
|
|
5
5
|
"url": "https://forum.ieu.app",
|
|
6
6
|
"library": "./library.js",
|
|
7
7
|
"hooks": [
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
{
|
|
17
|
-
"hook": "filter:scripts.get",
|
|
18
|
-
"method": "addScripts"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"hook": "action:user.loggedIn",
|
|
22
|
-
"method": "onLogin"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"hook": "action:topic.save",
|
|
26
|
-
"method": "onTopicCreate"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"hook": "action:post.save",
|
|
30
|
-
"method": "onPostCreate"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"hook": "action:post.upvote",
|
|
34
|
-
"method": "onUpvote"
|
|
35
|
-
}
|
|
8
|
+
{ "hook": "static:app.load", "method": "init" },
|
|
9
|
+
{ "hook": "filter:navigation.available", "method": "addNavigation" },
|
|
10
|
+
{ "hook": "filter:scripts.get", "method": "addScripts" },
|
|
11
|
+
|
|
12
|
+
{ "hook": "action:user.loggedIn", "method": "onLogin" },
|
|
13
|
+
{ "hook": "action:topic.save", "method": "onTopicCreate" },
|
|
14
|
+
{ "hook": "action:post.save", "method": "onPostCreate" },
|
|
15
|
+
{ "hook": "action:post.upvote", "method": "onUpvote" }
|
|
36
16
|
],
|
|
37
17
|
"staticDirs": {
|
|
38
18
|
"static": "./static"
|