fix: missing content-length on plugin/public

Massimo Melina committed Jan 15, 2022 at 10:36 UTC 9935594eb85cb28edcf62a6798562faec849fa1a
2 files changed +11 -10
src/plugins.ts
+10 -10
@@ -1,15 +1,15 @@
1 -import { createReadStream, watch } from 'fs'
1 +import { watch } from 'fs'
2 import glob from 'fast-glob'
3 import { watchLoad } from './watchLoad'
4 import _ from 'lodash'
5 import { resolve } from 'path'
6 import { PLUGINS_PUB_URI } from './const'
7 -import mime from 'mime-types'
7 import Koa from 'koa'
8 import { getOrSet, onProcessExit, wantArray } from './misc'
9 import { getConfig, subscribeConfig } from './config'
10 import { DirEntry } from './api.file_list'
11 import { VfsNode } from './vfs'
12 +import { serveFile } from './serveFile'
13
14 const PATH = 'plugins'
15
@@ -43,16 +43,16 @@ export function pluginsMiddleware(): Koa.Middleware {
43 }
44 // expose public plugins' files
45 const { path } = ctx
46 - if (!ctx.pluginStopped && path.startsWith(PLUGINS_PUB_URI)) {
47 - const a = path.substring(PLUGINS_PUB_URI.length).split('/')
48 - if (plugins.hasOwnProperty(a[0])) { // do it only if the plugin is loaded
49 - a.splice(1,0,'public')
50 - ctx.type = mime.lookup(path) || ''
51 - ctx.body = createReadStream(resolve(PATH, a.join('/')))
46 + if (!ctx.pluginStopped) {
47 + if (path.startsWith(PLUGINS_PUB_URI)) {
48 + const a = path.substring(PLUGINS_PUB_URI.length).split('/')
49 + if (plugins.hasOwnProperty(a[0])) { // do it only if the plugin is loaded
50 + a.splice(1, 0, 'public')
51 + await serveFile(PATH + '/' + a.join('/'), 'auto')(ctx, next)
52 + }
53 }
53 - }
54 - if (!ctx.pluginStopped)
54 await next()
55 + }
56 for (const f of after)
57 await f()
58 }
todo.md
+1
@@ -1,4 +1,5 @@
1 # To do
2 +- inject extras directly into <head> ? easier for makers and faster to load
3 - confirm archive
4 - automatic theme based on system preferences
5 - archive button as a link that can be copied