-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.js
More file actions
66 lines (58 loc) · 2.02 KB
/
library.js
File metadata and controls
66 lines (58 loc) · 2.02 KB
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
56
57
58
59
60
61
62
63
64
65
66
const winston = require.main.require('winston');
const meta = require.main.require('./src/meta');
const db = require.main.require('./src/database');
const categories = require.main.require('./src/categories');
const routeHelpers = require.main.require('./src/routes/helpers');
const ModderSupportPlugin = {
supportCategoryId: 0,
async init(params) {
const { router } = params;
// Admin panel
routeHelpers.setupAdminPageRoute(router, '/admin/plugins/mff-modder-support', renderAdmin);
try {
const options = await meta.settings.get('mff-modder-support');
if (options.hasOwnProperty('supportCategoryId')) {
ModderSupportPlugin.supportCategoryId = parseInt(options['supportCategoryId'], 10);
}
}
catch (err) {
winston.warn(`[plugin/mff-modder-support] Unable to retrieve settings, will keep defaults: ${err.message}`);
}
},
async topicPost(data) {
if (isSupportSection(data.cid)) {
checkModderHelpRequest(data.tags);
}
return data;
},
async topicEdit(data) {
if (isSupportSection(data.topic.cid)) {
checkModderHelpRequest(data.data.tags);
}
return data;
},
async addToAdminNav(header) {
header.plugins.push({
route: '/plugins/mff-modder-support',
name: 'MFF Modder Support',
});
return header;
}
};
function checkModderHelpRequest(tags) {
if (!tags || tags.length < 1) {
throw new Error('[[modder-support:no-version]]');
}
}
function isSupportSection(cid) {
return cid === ModderSupportPlugin.supportCategoryId;
}
async function renderAdmin(req, res) {
const cids = await db.getSortedSetRange('categories:cid', 0, -1);
const data = await categories.getCategoriesFields(cids, ['cid', 'name']);
res.render('admin/plugins/mff-modder-support', {
title: 'MFF modder support',
categories: data,
});
}
module.exports = ModderSupportPlugin;