nodebb-plugin-pdf-secure 1.2.9 → 1.2.11

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 CHANGED
@@ -36,8 +36,19 @@ plugin.init = async (params) => {
36
36
 
37
37
  // PDF direct access blocker middleware
38
38
  // Intercepts requests to uploaded PDF files and returns 403
39
- router.get('/assets/uploads/files/:filename', (req, res, next) => {
39
+ // Admin and Global Moderators can bypass this restriction
40
+ router.get('/assets/uploads/files/:filename', async (req, res, next) => {
40
41
  if (req.params.filename && req.params.filename.toLowerCase().endsWith('.pdf')) {
42
+ // Admin ve Global Mod'lar direkt erişebilsin
43
+ if (req.uid) {
44
+ const [isAdmin, isGlobalMod] = await Promise.all([
45
+ groups.isMember(req.uid, 'administrators'),
46
+ groups.isMember(req.uid, 'Global Moderators'),
47
+ ]);
48
+ if (isAdmin || isGlobalMod) {
49
+ return next();
50
+ }
51
+ }
41
52
  return res.status(403).json({ error: 'Direct PDF access is not allowed. Use the secure viewer.' });
42
53
  }
43
54
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-pdf-secure",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "Secure PDF viewer plugin for NodeBB - prevents downloading, enables canvas-only rendering with Premium group support",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -215,6 +215,8 @@
215
215
  targetElement.replaceWith(container);
216
216
 
217
217
  // LAZY LOADING with Intersection Observer + Queue
218
+ // Smart loading: only loads PDFs that are actually visible
219
+ var queueEntry = null; // Track if this PDF is in queue
218
220
  var observer = new IntersectionObserver(function (entries) {
219
221
  entries.forEach(function (entry) {
220
222
  if (entry.isIntersecting) {
@@ -229,13 +231,36 @@
229
231
  svgEl.innerHTML = '<path d="M12 4V2A10 10 0 0 0 2 12h2a8 8 0 0 1 8-8z"/>';
230
232
  }
231
233
 
232
- // Add to queue
233
- queuePdfLoad(iframeWrapper, filename, loadingPlaceholder);
234
- observer.disconnect();
234
+ // Add to queue (if not already)
235
+ if (!queueEntry) {
236
+ queueEntry = { wrapper: iframeWrapper, filename, placeholder: loadingPlaceholder };
237
+ loadQueue.push(queueEntry);
238
+ processQueue();
239
+ }
240
+ } else {
241
+ // LEFT viewport - remove from queue if waiting
242
+ if (queueEntry && loadQueue.includes(queueEntry)) {
243
+ var idx = loadQueue.indexOf(queueEntry);
244
+ if (idx > -1) {
245
+ loadQueue.splice(idx, 1);
246
+ console.log('[PDF-Secure] Queue: Removed (left viewport) -', filename);
247
+
248
+ // Reset placeholder to waiting state
249
+ var textEl = loadingPlaceholder.querySelector('.pdf-loading-text');
250
+ if (textEl) textEl.textContent = 'Sırada bekliyor...';
251
+ var svgEl = loadingPlaceholder.querySelector('svg');
252
+ if (svgEl) {
253
+ svgEl.style.fill = '#555';
254
+ svgEl.style.animation = 'none';
255
+ svgEl.innerHTML = '<path d="M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm4 18H6V4h7v5h5v11z"/>';
256
+ }
257
+ }
258
+ queueEntry = null;
259
+ }
235
260
  }
236
261
  });
237
262
  }, {
238
- rootMargin: '200px',
263
+ rootMargin: '0px', // Only trigger when actually visible
239
264
  threshold: 0
240
265
  });
241
266