This repository has been archived by the owner on May 28, 2024. It is now read-only.
forked from oplik0/nodebb-plugin-category-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.js
55 lines (45 loc) · 1.53 KB
/
library.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const categories = require.main.require('./src/categories');
const db = require.main.require('./src/database');
const meta = require.main.require('./src/meta');
const routesHelpers = require.main.require('./src/routes/helpers');
const CategoryQueuePlugin = {
settings: {},
};
/**
* Called on `static:app.load`
*/
CategoryQueuePlugin.init = async function init(data) {
const { middleware, router } = data;
async function renderAdmin(req, res) {
const cids = await db.getSortedSetRange('categories:cid', 0, -1);
const categoriesData = await categories.getCategoriesData(cids);
const categoriesTree = categories.getTree(categoriesData);
res.render('admin/plugins/category-queue', { categories: categoriesTree || [] });
}
routesHelpers.setupAdminPageRoute(router, `/admin/plugins/category-queue`, middleware, [], renderAdmin);
CategoryQueuePlugin.settings = await meta.settings.get('category-queue');
};
/**
* Called on `filter:admin.header.build`
*/
CategoryQueuePlugin.addAdminNavigation = async function (header) {
header.plugins.push({
route: '/plugins/category-queue',
icon: 'fa-tint',
name: 'Category Queue',
});
return header;
};
/**
* Called on `filter:post.shouldQueue`
*/
CategoryQueuePlugin.postQueue = async function (postData) {
const targetCid = Number(postData.data.cid);
const cids = Object.values(CategoryQueuePlugin.settings).map(Number).filter(Boolean);
if (targetCid && cids.includes(targetCid)) {
postData.shouldQueue = true;
}
return postData;
};
module.exports = CategoryQueuePlugin;