nodebb-plugin-pdf-secure2 1.3.4 → 1.3.5
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/lib/controllers.js +7 -0
- package/library.js +10 -1
- package/package.json +1 -1
package/lib/controllers.js
CHANGED
|
@@ -42,13 +42,17 @@ Controllers.renderAdminPage = function (req, res) {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
Controllers.servePdfBinary = async function (req, res) {
|
|
45
|
+
console.log('[PDF-Secure] servePdfBinary called - uid:', req.uid, 'nonce:', req.query.nonce ? 'present' : 'missing');
|
|
46
|
+
|
|
45
47
|
// Authentication gate - require logged-in user
|
|
46
48
|
if (!req.uid) {
|
|
49
|
+
console.log('[PDF-Secure] servePdfBinary - REJECTED: no uid');
|
|
47
50
|
return res.status(401).json({ error: 'Authentication required' });
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
const { nonce } = req.query;
|
|
51
54
|
if (!nonce) {
|
|
55
|
+
console.log('[PDF-Secure] servePdfBinary - REJECTED: no nonce');
|
|
52
56
|
return res.status(400).json({ error: 'Missing nonce' });
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -56,9 +60,12 @@ Controllers.servePdfBinary = async function (req, res) {
|
|
|
56
60
|
|
|
57
61
|
const data = nonceStore.validate(nonce, uid);
|
|
58
62
|
if (!data) {
|
|
63
|
+
console.log('[PDF-Secure] servePdfBinary - REJECTED: invalid/expired nonce for uid:', uid);
|
|
59
64
|
return res.status(403).json({ error: 'Invalid or expired nonce' });
|
|
60
65
|
}
|
|
61
66
|
|
|
67
|
+
console.log('[PDF-Secure] servePdfBinary - OK: file:', data.file, 'isPremium:', data.isPremium);
|
|
68
|
+
|
|
62
69
|
try {
|
|
63
70
|
// Server-side premium gate: non-premium users only get first page
|
|
64
71
|
const pdfBuffer = data.isPremium
|
package/library.js
CHANGED
|
@@ -101,6 +101,7 @@ plugin.init = async (params) => {
|
|
|
101
101
|
// Check if user is Premium or Lite (admins/global mods always premium)
|
|
102
102
|
let isPremium = false;
|
|
103
103
|
let isLite = false;
|
|
104
|
+
let isVip = false;
|
|
104
105
|
if (req.uid) {
|
|
105
106
|
const [isAdmin, isGlobalMod, isPremiumMember, isVipMember, isLiteMember] = await Promise.all([
|
|
106
107
|
groups.isMember(req.uid, 'administrators'),
|
|
@@ -110,10 +111,11 @@ plugin.init = async (params) => {
|
|
|
110
111
|
groups.isMember(req.uid, 'Lite'),
|
|
111
112
|
]);
|
|
112
113
|
isPremium = isAdmin || isGlobalMod || isPremiumMember || isVipMember;
|
|
113
|
-
|
|
114
|
+
isVip = isVipMember || isAdmin;
|
|
114
115
|
// Lite: full PDF access but restricted UI (no annotations, sidebar, etc.)
|
|
115
116
|
isLite = !isPremium && isLiteMember;
|
|
116
117
|
}
|
|
118
|
+
console.log('[PDF-Secure] Viewer request - uid:', req.uid, 'file:', safeName, 'isPremium:', isPremium, 'isVip:', isVip, 'isLite:', isLite);
|
|
117
119
|
|
|
118
120
|
// Lite users get full PDF like premium (for nonce/server-side PDF data)
|
|
119
121
|
const hasFullAccess = isPremium || isLite;
|
|
@@ -231,6 +233,7 @@ plugin.filterMetaTags = async (hookData) => {
|
|
|
231
233
|
|
|
232
234
|
// Inject plugin config into client-side
|
|
233
235
|
plugin.filterConfig = async function (data) {
|
|
236
|
+
console.log('[PDF-Secure] filterConfig called - data exists:', !!data, 'config exists:', !!(data && data.config));
|
|
234
237
|
return data;
|
|
235
238
|
};
|
|
236
239
|
|
|
@@ -238,13 +241,19 @@ plugin.filterConfig = async function (data) {
|
|
|
238
241
|
// This hides PDF URLs from: page source, API, RSS, ActivityPub
|
|
239
242
|
plugin.transformPdfLinks = async (data) => {
|
|
240
243
|
if (!data || !data.postData || !data.postData.content) {
|
|
244
|
+
console.log('[PDF-Secure] transformPdfLinks - no data/postData/content, skipping');
|
|
241
245
|
return data;
|
|
242
246
|
}
|
|
243
247
|
|
|
248
|
+
console.log('[PDF-Secure] transformPdfLinks - processing post tid:', data.postData.tid, 'pid:', data.postData.pid);
|
|
249
|
+
|
|
244
250
|
// Regex to match PDF links: <a href="...xxx.pdf">text</a>
|
|
245
251
|
// Captures: full URL path, filename, link text
|
|
246
252
|
const pdfLinkRegex = /<a\s+[^>]*href=["']([^"']*\/([^"'\/]+\.pdf))["'][^>]*>([^<]*)<\/a>/gi;
|
|
247
253
|
|
|
254
|
+
const matchCount = (data.postData.content.match(pdfLinkRegex) || []).length;
|
|
255
|
+
console.log('[PDF-Secure] transformPdfLinks - found', matchCount, 'PDF links in post');
|
|
256
|
+
|
|
248
257
|
data.postData.content = data.postData.content.replace(pdfLinkRegex, (match, fullPath, filename, linkText) => {
|
|
249
258
|
// Decode filename to prevent double encoding (URL may already be encoded)
|
|
250
259
|
let decodedFilename;
|
package/package.json
CHANGED