download-counter: ignore special files

Massimo Melina committed Feb 8, 2022 at 18:24 UTC 80f108edbb36cfb0baf6f4326db136b54449dee7
3 files changed +6 -2
plugins/download-counter/plugin.js
+1 -1
@@ -23,7 +23,7 @@ exports.init = api => {
23 unload: () => save.flush(), // we may have pending savings
24 middleware: (ctx) =>
25 () => { // execute after other middlewares are done
26 - if (ctx.status >= 300 || !ctx.fileSource) return
26 + if (ctx.status >= 300 || !ctx.vfsNode) return
27 const { path } = ctx
28 counters[path] = counters[path] + 1 || 1
29 save()
src/serveFile.ts
+4 -1
@@ -11,7 +11,10 @@ import path from 'path'
11
12 export function serveFileNode(node: VfsNode) : Koa.Middleware {
13 const { source, mime } = node
14 - return serveFile(source||'', mime)
14 + return (ctx, next) => {
15 + ctx.vfsNode = node // useful to tell service files from files shared by the user
16 + return serveFile(source||'', mime)(ctx, next)
17 + }
18 }
19
20 export function serveFile(source:string, mime?:string, modifier?:(s:string)=>string) : Koa.Middleware {
todo.md
+1
@@ -1,6 +1,7 @@
1 # To do
2 - allowed referer
3 - admin/plugins
4 +- download-counter: expose results on admin
5 - log rotation
6 - log filter option
7 - log filter plugin