This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
forked from dmpasilva/nodebb-plugin-anon-category
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.js
executable file
·108 lines (75 loc) · 2.46 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"use strict";
var path = require('path');
var nconf = require('nconf');
var topics = require(path.join(nconf.get('base_dir'), 'src/topics'));
var controllers = require('./lib/controllers');
var AnonCategory = nconf.get('anoncat:category');
var AnonPosterID = nconf.get('anoncat:posterId'),
plugin = {};
plugin.init = function(params, callback) {
var router = params.router,
hostMiddleware = params.middleware,
hostControllers = params.controllers;
// We create two routes for every view. One API call, and the actual route itself.
// Just add the buildHeader middleware to your route and NodeBB will take care of everything for you.
router.get('/admin/plugins/anoncat', hostMiddleware.admin.buildHeader, controllers.renderAdminPage);
router.get('/api/admin/plugins/anoncat', controllers.renderAdminPage);
callback();
};
plugin.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/plugins/anoncat',
icon: 'fa-tint',
name: 'Anon Category'
});
callback(null, header);
};
plugin.anonTopic = function(params, callback) {
console.log("Called anonTopic");
console.log(params);
if(params.topic.cid == AnonCategory) {
params.topic.uid = AnonPosterID;
params.data.uid = AnonPosterID;
// we need this to stay as is due to forum modaration concerns
//params.data.req.uid = 0;
console.log(params);
}
callback(null, params);
}
plugin.createAnonPost = function(params, callback) {
console.log("-------------------");
console.log("called createAnonPost");
console.log(params);
console.log(callback);
console.log("trying to change author");
if(params.post.hasOwnProperty("cid")) {
let cid = params.post.cid;
if(cid == AnonCategory) {
params.post.uid = AnonPosterID;
params.data.uid = AnonPosterID;
// we need this to stay as is due to forum modaration concerns
//params.data.req.uid = 0;
}
console.log(params);
callback(null, params);
}
else {
topics.getTopicField(params.post.tid, 'cid', function(err, category) {
if (err) {
console.log("There was an error in anonymizer");
callback(null, params);
}
console.log("post belongs to category ");
console.log(category);
if(category == AnonCategory) {
params.post.uid = AnonPosterID;
params.data.uid = AnonPosterID;
// we need this to stay as is due to forum modaration concerns
//params.data.req.uid = 0;
}
console.log(params);
callback(null, params);
});
}
};
module.exports = plugin;