nodebb-plugin-niki-loyalty 1.0.1 → 1.0.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 +12 -28
- package/package.json +1 -1
- package/templates/admin/plugins/quickstart/partials/sorted-list/form.tpl +0 -10
- package/templates/admin/plugins/quickstart/partials/sorted-list/item.tpl +0 -12
- package/templates/admin/plugins/quickstart.tpl +0 -68
- package/templates/quickstart.tpl +0 -7
package/library.js
CHANGED
|
@@ -2,75 +2,58 @@
|
|
|
2
2
|
|
|
3
3
|
const db = require.main.require('./src/database');
|
|
4
4
|
const user = require.main.require('./src/user');
|
|
5
|
-
const routeHelpers = require.main.require('./src/controllers/helpers');
|
|
6
5
|
|
|
7
6
|
const Plugin = {};
|
|
8
7
|
|
|
9
8
|
// --- AYARLAR ---
|
|
10
9
|
const SETTINGS = {
|
|
11
|
-
pointsPerHeartbeat: 5,
|
|
12
|
-
|
|
13
|
-
dailyCap: 250 // Günlük maksimum puan (Örn: 50dk aktiflik)
|
|
10
|
+
pointsPerHeartbeat: 5,
|
|
11
|
+
dailyCap: 250
|
|
14
12
|
};
|
|
15
13
|
|
|
16
14
|
Plugin.init = async function (params) {
|
|
17
15
|
const router = params.router;
|
|
18
16
|
const middleware = params.middleware;
|
|
19
17
|
|
|
20
|
-
// API: Kalp Atışı (Puan Kazanma)
|
|
18
|
+
// 1. API: Kalp Atışı (Puan Kazanma - Client.js burayı kullanır)
|
|
21
19
|
router.post('/api/niki-loyalty/heartbeat', middleware.ensureLoggedIn, async (req, res) => {
|
|
22
20
|
const uid = req.uid;
|
|
23
|
-
const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
|
24
|
-
|
|
25
|
-
// 1. Günlük Limiti Kontrol Et
|
|
21
|
+
const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
|
26
22
|
const dailyKey = `niki:daily:${uid}:${today}`;
|
|
23
|
+
|
|
27
24
|
const currentDailyScore = await db.getObjectField(dailyKey, 'score') || 0;
|
|
28
25
|
|
|
29
26
|
if (parseInt(currentDailyScore) >= SETTINGS.dailyCap) {
|
|
30
27
|
return res.json({ earned: false, reason: 'daily_cap' });
|
|
31
28
|
}
|
|
32
29
|
|
|
33
|
-
// 2. Puan Ver
|
|
34
30
|
await user.incrementUserFieldBy(uid, 'niki_points', SETTINGS.pointsPerHeartbeat);
|
|
35
31
|
await db.incrObjectFieldBy(dailyKey, 'score', SETTINGS.pointsPerHeartbeat);
|
|
36
32
|
|
|
37
|
-
// 3. Güncel Bakiyeyi Dön
|
|
38
33
|
const newBalance = await user.getUserField(uid, 'niki_points');
|
|
39
|
-
return res.json({
|
|
40
|
-
earned: true,
|
|
41
|
-
points: SETTINGS.pointsPerHeartbeat,
|
|
42
|
-
total: newBalance,
|
|
43
|
-
daily: parseInt(currentDailyScore) + SETTINGS.pointsPerHeartbeat
|
|
44
|
-
});
|
|
34
|
+
return res.json({ earned: true, points: SETTINGS.pointsPerHeartbeat, total: newBalance });
|
|
45
35
|
});
|
|
46
36
|
|
|
47
|
-
//
|
|
48
|
-
|
|
37
|
+
// 2. YENİ API: Cüzdan Verisi Çekme (Custom Page burayı kullanacak)
|
|
38
|
+
router.get('/api/niki-loyalty/wallet-data', middleware.ensureLoggedIn, async (req, res) => {
|
|
49
39
|
const uid = req.uid;
|
|
50
|
-
if (!uid) return res.redirect('/login');
|
|
51
|
-
|
|
52
40
|
const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
|
53
41
|
|
|
54
|
-
// Verileri Çek
|
|
55
42
|
const [userData, dailyData] = await Promise.all([
|
|
56
|
-
user.getUserFields(uid, ['
|
|
43
|
+
user.getUserFields(uid, ['niki_points']),
|
|
57
44
|
db.getObject(`niki:daily:${uid}:${today}`)
|
|
58
45
|
]);
|
|
59
46
|
|
|
60
47
|
const currentPoints = parseInt(userData.niki_points) || 0;
|
|
61
48
|
const dailyScore = parseInt(dailyData ? dailyData.score : 0) || 0;
|
|
62
|
-
|
|
63
|
-
// Yüzdelik Hesapla (Bar için)
|
|
64
49
|
let dailyPercent = (dailyScore / SETTINGS.dailyCap) * 100;
|
|
65
50
|
if (dailyPercent > 100) dailyPercent = 100;
|
|
66
51
|
|
|
67
|
-
res.
|
|
68
|
-
title: 'Niki Cüzdan',
|
|
52
|
+
res.json({
|
|
69
53
|
points: currentPoints,
|
|
70
54
|
dailyScore: dailyScore,
|
|
71
55
|
dailyCap: SETTINGS.dailyCap,
|
|
72
|
-
dailyPercent: dailyPercent
|
|
73
|
-
user: userData
|
|
56
|
+
dailyPercent: dailyPercent
|
|
74
57
|
});
|
|
75
58
|
});
|
|
76
59
|
};
|
|
@@ -80,6 +63,7 @@ Plugin.addScripts = async function (scripts) {
|
|
|
80
63
|
return scripts;
|
|
81
64
|
};
|
|
82
65
|
|
|
66
|
+
// Menüye eklemeye devam edelim, Custom Page ile aynı linki vereceğiz
|
|
83
67
|
Plugin.addNavigation = async function (nav) {
|
|
84
68
|
nav.push({
|
|
85
69
|
"route": "/niki-wallet",
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
<form>
|
|
2
|
-
<div class="mb-3">
|
|
3
|
-
<label class="form-label" for="name">Name</label>
|
|
4
|
-
<input type="text" id="name" name="name" class="form-control" placeholder="Name" />
|
|
5
|
-
</div>
|
|
6
|
-
<div class="mb-3">
|
|
7
|
-
<label class="form-label" for="description">Description</label>
|
|
8
|
-
<input type="text" id="description" name="description" class="form-control" placeholder="Description" />
|
|
9
|
-
</div>
|
|
10
|
-
</form>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<li data-type="item" class="list-group-item">
|
|
2
|
-
<div class="d-flex gap-2 justify-content-between align-items-start">
|
|
3
|
-
<div class="flex-grow-1">
|
|
4
|
-
<strong>{name}</strong><br />
|
|
5
|
-
<small>{description}</small>
|
|
6
|
-
</div>
|
|
7
|
-
<div class="d-flex gap-1 flex-nowrap">
|
|
8
|
-
<button type="button" data-type="edit" class="btn btn-sm btn-info">Edit</button>
|
|
9
|
-
<button type="button" data-type="remove" class="btn btn-sm btn-danger">Delete</button>
|
|
10
|
-
</div>
|
|
11
|
-
</div>
|
|
12
|
-
</li>
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
<div class="acp-page-container">
|
|
2
|
-
<!-- IMPORT admin/partials/settings/header.tpl -->
|
|
3
|
-
|
|
4
|
-
<div class="row m-0">
|
|
5
|
-
<div id="spy-container" class="col-12 col-md-8 px-0 mb-4" tabindex="0">
|
|
6
|
-
<form role="form" class="quickstart-settings">
|
|
7
|
-
<div class="mb-4">
|
|
8
|
-
<h5 class="fw-bold tracking-tight settings-header">General</h5>
|
|
9
|
-
|
|
10
|
-
<p class="lead">
|
|
11
|
-
Adjust these settings. You can then retrieve these settings in code via:
|
|
12
|
-
<br/><code>await meta.settings.get('quickstart');</code>
|
|
13
|
-
</p>
|
|
14
|
-
<div class="mb-3">
|
|
15
|
-
<label class="form-label" for="setting-1">Setting 1</label>
|
|
16
|
-
<input type="text" id="setting-1" name="setting-1" title="Setting 1" class="form-control" placeholder="Setting 1">
|
|
17
|
-
</div>
|
|
18
|
-
<div class="mb-3">
|
|
19
|
-
<label class="form-label" for="setting-2">Setting 2</label>
|
|
20
|
-
<input type="text" id="setting-2" name="setting-2" title="Setting 2" class="form-control" placeholder="Setting 2">
|
|
21
|
-
</div>
|
|
22
|
-
|
|
23
|
-
<div class="form-check form-switch">
|
|
24
|
-
<input type="checkbox" class="form-check-input" id="setting-3" name="setting-3">
|
|
25
|
-
<label for="setting-3" class="form-check-label">Setting 3</label>
|
|
26
|
-
</div>
|
|
27
|
-
</div>
|
|
28
|
-
|
|
29
|
-
<div class="mb-4">
|
|
30
|
-
<h5 class="fw-bold tracking-tight settings-header">Colors</h5>
|
|
31
|
-
|
|
32
|
-
<p class="alert" id="preview">
|
|
33
|
-
Here is some preview text. Use the inputs below to modify this alert's appearance.
|
|
34
|
-
</p>
|
|
35
|
-
<div class="mb-3 d-flex gap-2">
|
|
36
|
-
<label class="form-label" for="color">Foreground</label>
|
|
37
|
-
<input data-settings="colorpicker" type="color" id="color" name="color" title="Background Color" class="form-control p-1" placeholder="#ffffff" value="#ffffff" style="width: 64px;"/>
|
|
38
|
-
</div>
|
|
39
|
-
<div class="mb-3 d-flex gap-2">
|
|
40
|
-
<label class="form-label" for="bgColor">Background</label>
|
|
41
|
-
<input data-settings="colorpicker" type="color" id="bgColor" name="bgColor" title="Background Color" class="form-control p-1" placeholder="#000000" value="#000000" style="width: 64px;" />
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
|
|
45
|
-
<div class="mb-4">
|
|
46
|
-
<h5 class="fw-bold tracking-tight settings-header">Sorted List</h5>
|
|
47
|
-
|
|
48
|
-
<div class="mb-3" data-type="sorted-list" data-sorted-list="sample-list" data-item-template="admin/plugins/quickstart/partials/sorted-list/item" data-form-template="admin/plugins/quickstart/partials/sorted-list/form">
|
|
49
|
-
<ul data-type="list" class="list-group mb-2"></ul>
|
|
50
|
-
<button type="button" data-type="add" class="btn btn-info">Add Item</button>
|
|
51
|
-
</div>
|
|
52
|
-
</div>
|
|
53
|
-
|
|
54
|
-
<div>
|
|
55
|
-
<h5 class="fw-bold tracking-tight settings-header">Uploads</h5>
|
|
56
|
-
|
|
57
|
-
<label class="form-label" for="uploadedImage">Upload Image</label>
|
|
58
|
-
<div class="d-flex gap-1">
|
|
59
|
-
<input id="uploadedImage" name="uploadedImage" type="text" class="form-control" />
|
|
60
|
-
<input value="Upload" data-action="upload" data-target="uploadedImage" type="button" class="btn btn-light" />
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
</form>
|
|
64
|
-
</div>
|
|
65
|
-
|
|
66
|
-
<!-- IMPORT admin/partials/settings/toc.tpl -->
|
|
67
|
-
</div>
|
|
68
|
-
</div>
|