mime types (and other file masks) will now be case insensitive #375

Massimo Melina committed Oct 12, 2023 at 10:10 UTC 2de67e6268bef6f156861a39128f8533ca403994
4 files changed +6 -5
src/misc.ts
+1 -1
@@ -94,7 +94,7 @@ function parseAddress(s: string) {
94 }
95
96 export function makeMatcher(mask: string, emptyMaskReturns=false) {
97 - return mask ? matcher(mask.replace(/^(!)?/, '$1(') + ')') // adding () will allow us to use the pipe at root level
97 + return mask ? matcher(mask.replace(/^(!)?/, '$1(') + ')', { nocase: true}) // adding () will allow us to use the pipe at root level
98 : () => emptyMaskReturns
99 }
100
src/plugins.ts
+2 -2
@@ -12,7 +12,7 @@ import {
12 } from './misc'
13 import { defineConfig, getConfig } from './config'
14 import { DirEntry } from './api.file_list'
15 -import { VfsNode } from './vfs'
15 +import { MIME_AUTO, VfsNode } from './vfs'
16 import { serveFile } from './serveFile'
17 import events from './events'
18 import { mkdir, readFile } from 'fs/promises'
@@ -132,7 +132,7 @@ export const pluginsMiddleware: Koa.Middleware = async (ctx, next) => {
132 const a = path.substring(PLUGINS_PUB_URI.length).split('/')
133 const name = a.shift()!
134 if (plugins.hasOwnProperty(name)) // do it only if the plugin is loaded
135 - await serveFile(ctx, plugins[name]!.folder + '/public/' + a.join('/'), 'auto')
135 + await serveFile(ctx, plugins[name]!.folder + '/public/' + a.join('/'), MIME_AUTO)
136 return
137 }
138 await next()
src/serveFile.ts
+1 -1
@@ -45,7 +45,7 @@ export function serveFileNode(ctx: Koa.Context, node: VfsNode) {
45 }
46 }
47
48 -const mimeCfg = defineConfig<Record<string,string>>('mime', { '*': 'auto' })
48 +const mimeCfg = defineConfig<Record<string,string>>('mime', { '*': MIME_AUTO })
49
50 export async function serveFile(ctx: Koa.Context, source:string, mime?:string, content?: string | Buffer) {
51 if (!source)
src/serveGuiFiles.ts
+2 -1
@@ -24,6 +24,7 @@ import { customHtmlState, getSection } from './customHtml'
24 import _ from 'lodash'
25 import { defineConfig } from './config'
26 import { getLangData } from './lang'
27 +import { MIME_AUTO } from './vfs'
28
29 const logGui = defineConfig('log_gui', false)
30
@@ -54,7 +55,7 @@ function serveStatic(uri: string): Koa.Middleware {
55 if (content === null)
56 return ctx.status = HTTP_NOT_FOUND
57 if (!serveApp)
57 - return serveFile(ctx, fullPath, 'auto', content)
58 + return serveFile(ctx, fullPath, MIME_AUTO, content)
59 // we don't cache the index as it's small and may prevent plugins change to apply
60 ctx.body = await treatIndex(ctx, uri, String(content))
61 }