@samitouri / QOSami-HFS / commits / 729cb509

log: option "log interface" will account for images you may use in the page, and other files included by plugins #565

Massimo Melina committed May 29, 2024 at 00:13 UTC 729cb5095d1eaa9c4bf719e0e530f0942701f1eb
2 files changed +7 -2
src/plugins.ts
+4 -1
@@ -139,8 +139,11 @@ export const pluginsMiddleware: Koa.Middleware = async (ctx, next) => {
139 if (path.startsWith(PLUGINS_PUB_URI)) {
140 const a = path.substring(PLUGINS_PUB_URI.length).split('/')
141 const name = a.shift()!
142 - if (plugins.hasOwnProperty(name)) // do it only if the plugin is loaded
142 + if (plugins.hasOwnProperty(name)) { // do it only if the plugin is loaded
143 + if (ctx.get('referer')?.endsWith('/'))
144 + ctx.state.considerAsGui = true
145 await serveFile(ctx, plugins[name]!.folder + '/public/' + a.join('/'), MIME_AUTO)
146 + }
147 return
148 }
149 if (ctx.body === undefined && ctx.status === HTTP_NOT_FOUND) // no response was provided by plugins, so we'll do
src/serveFile.ts
+3 -1
@@ -7,7 +7,7 @@ import { HTTP_BAD_REQUEST, HTTP_FORBIDDEN, HTTP_METHOD_NOT_ALLOWED, HTTP_NO_CONT
7 import { getNodeName, VfsNode } from './vfs'
8 import mimetypes from 'mime-types'
9 import { defineConfig } from './config'
10 -import { CFG, Dict, makeMatcher, matches } from './misc'
10 +import { CFG, Dict, makeMatcher, matches, with_ } from './misc'
11 import _ from 'lodash'
12 import { basename } from 'path'
13 import { promisify } from 'util'
@@ -37,6 +37,8 @@ export async function serveFileNode(ctx: Koa.Context, node: VfsNode) {
37 ctx.state.vfsNode = node // useful to tell service files from files shared by the user
38 if ('dl' in ctx.query) // please, download
39 ctx.attachment(name)
40 + else if (ctx.get('referer')?.endsWith('/') && with_(ctx.get('accept'), x => x && !x.includes('text')))
41 + ctx.state.considerAsGui = true
42 await serveFile(ctx, source||'', mimeString)
43
44 if (await limitDownloadsPerAccount(ctx) === undefined) // returning false will not execute other limits