fix: (regression 0.50.0-alpha1) bad default mime type, causing some files to be downloaded instead of open --importing 'auth' in vfs.ts caused MIME_TYPE to be undefined in serveFile.ts
fix: (regression 0.50.0-alpha1) bad default mime type, causing some files to be downloaded instead of open --importing 'auth' in vfs.ts caused MIME_TYPE to be undefined in serveFile.ts
Massimo Melina committed
Nov 12, 2023 at 11:55 UTC
481668abfb03b45206de9fd36db557ed73f96813
7 files changed
+14
-34
src/const.ts
+1
@@ -21,6 +21,7 @@ export const IS_WINDOWS = process.platform === 'win32'
21
export const IS_MAC = process.platform === 'darwin'
22
export const IS_BINARY = !basename(process.execPath).includes('node') // this won't be node if pkg was used
23
export const APP_PATH = dirname(IS_BINARY ? process.execPath : __dirname)
24
+export const MIME_AUTO = 'auto'
25
26
// we want this to be the first stuff to be printed, then we print it in this module, that is executed at the beginning
27
if (DEV) console.clear()
src/plugins.ts
+4
-6
@@ -3,16 +3,14 @@
3
import glob from 'fast-glob'
4
import { watchLoad } from './watchLoad'
5
import _ from 'lodash'
6
-import { API_VERSION, APP_PATH, COMPATIBLE_API_VERSION, IS_WINDOWS, PLUGINS_PUB_URI } from './const'
6
+import { API_VERSION, APP_PATH, COMPATIBLE_API_VERSION, IS_WINDOWS, MIME_AUTO, PLUGINS_PUB_URI } from './const'
7
import * as Const from './const'
8
import Koa from 'koa'
9
-import {
10
- adjustStaticPathForGlob, Callback, debounceAsync, Dict, getOrSet, onlyTruthy, onProcessExit,
11
- PendingPromise, pendingPromise, same, tryJson, wait, waitFor, wantArray, watchDir
12
-} from './misc'
9
+import { adjustStaticPathForGlob, Callback, debounceAsync, Dict, getOrSet, onlyTruthy, onProcessExit,
10
+ PendingPromise, pendingPromise, same, tryJson, wait, waitFor, wantArray, watchDir } from './misc'
11
import { defineConfig, getConfig } from './config'
12
import { DirEntry } from './api.file_list'
15
-import { MIME_AUTO, VfsNode } from './vfs'
13
+import { VfsNode } from './vfs'
14
import { serveFile } from './serveFile'
15
import events from './events'
16
import { mkdir, readFile } from 'fs/promises'
src/serveFile.ts
+3
-10
@@ -2,16 +2,9 @@
2
3
import Koa from 'koa'
4
import { createReadStream, stat } from 'fs'
5
-import {
6
- HTTP_BAD_REQUEST,
7
- HTTP_FORBIDDEN,
8
- HTTP_METHOD_NOT_ALLOWED,
9
- HTTP_NO_CONTENT,
10
- HTTP_NOT_FOUND,
11
- HTTP_NOT_MODIFIED,
12
- HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_RANGE_NOT_SATISFIABLE
13
-} from './const'
14
-import { getNodeName, MIME_AUTO, VfsNode } from './vfs'
5
+import { HTTP_BAD_REQUEST, HTTP_FORBIDDEN, HTTP_METHOD_NOT_ALLOWED, HTTP_NO_CONTENT, HTTP_NOT_FOUND, HTTP_NOT_MODIFIED,
6
+ HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_RANGE_NOT_SATISFIABLE, MIME_AUTO } from './const'
7
+import { getNodeName, VfsNode } from './vfs'
8
import mimetypes from 'mime-types'
9
import { defineConfig } from './config'
10
import { matches } from './misc'
src/serveGuiFiles.ts
+2
-11
@@ -2,16 +2,8 @@
2
3
import Koa from 'koa'
4
import fs from 'fs/promises'
5
-import {
6
- API_VERSION,
7
- FRONTEND_URI,
8
- HTTP_METHOD_NOT_ALLOWED,
9
- HTTP_NO_CONTENT,
10
- HTTP_NOT_FOUND,
11
- PLUGINS_PUB_URI,
12
- VERSION,
13
- SPECIAL_URI
14
-} from './const'
5
+import { API_VERSION, MIME_AUTO, FRONTEND_URI, HTTP_METHOD_NOT_ALLOWED, HTTP_NO_CONTENT, HTTP_NOT_FOUND,
6
+ PLUGINS_PUB_URI, VERSION, SPECIAL_URI } from './const'
7
import { serveFile } from './serveFile'
8
import { getPluginConfigFields, getPluginInfo, mapPlugins, pluginsConfig } from './plugins'
9
import { refresh_session } from './api.auth'
@@ -24,7 +16,6 @@ import { customHtmlState, getSection } from './customHtml'
16
import _ from 'lodash'
17
import { defineConfig, getConfig } from './config'
18
import { getLangData } from './lang'
27
-import { MIME_AUTO } from './vfs'
19
20
const logGui = defineConfig('log_gui', false)
21
_.each(FRONTEND_OPTIONS, (v,k) => defineConfig(k, v)) // define default values
src/vfs.ts
+1
-3
@@ -9,7 +9,7 @@ import {
9
import Koa from 'koa'
10
import _ from 'lodash'
11
import { defineConfig, setConfig } from './config'
12
-import { HTTP_FOOL, HTTP_FORBIDDEN, HTTP_UNAUTHORIZED } from './const'
12
+import { HTTP_FOOL, HTTP_FORBIDDEN, HTTP_UNAUTHORIZED, MIME_AUTO } from './const'
13
import events from './events'
14
import { expandUsername } from './perm'
15
import { getCurrentUsername } from './auth'
@@ -34,8 +34,6 @@ export interface VfsNode extends VfsNodeStored { // include fields that are only
34
isFolder?: boolean
35
}
36
37
-export const MIME_AUTO = 'auto'
38
-
37
export function permsFromParent(parent: VfsNode, child: VfsNode) {
38
const ret: VfsPerms = {}
39
for (const k of PERM_KEYS) {
tests/config.yaml
+1
-3
@@ -1,7 +1,5 @@
1
allowed_referer: x.com
2
vfs:
3
- mime:
4
- "*": auto
3
masks:
4
"!tests/page/*.png":
5
mime: text/plain
@@ -128,4 +126,4 @@ accounts:
126
disabled: true
127
admins:
128
admin: true
131
-version: 0.49.4
129
+version: 0.50.0-alpha2
tests/test.ts
+2
-1
@@ -30,7 +30,7 @@ describe('basics', () => {
30
it('list', reqList('/f1/', { inList:['f2/', 'page/'] }))
31
it('search', reqList('f1', { inList:['f2/'], outList:['page'] }, { search:'2' }))
32
it('search root', reqList('/', { inList:['cantListPage/'], outList:['cantListPage/page/'] }, { search:'page' }))
33
- it('download', req('/f1/f2/alfa.txt', { re:/abcd/, mime:'text/plain' }))
33
+ it('download.mime', req('/f1/f2/alfa.txt', { re:/abcd/, mime:'text/plain' }))
34
it('download.partial', req('/f1/f2/alfa.txt', /a[^d]+$/, { // only "abc" is expected
35
headers: { Range: 'bytes=0-2' }
36
}))
@@ -165,6 +165,7 @@ function req(methodUrl: string, test:Tester, requestOptions: AxiosRequestConfig<
165
166
function process(res:any) {
167
//console.debug('sent', requestOptions, 'got', res instanceof Error ? String(res) : [res.status])
168
+ if (res.code === "ECONNREFUSED") throw res
169
if (test && test instanceof RegExp)
170
test = { re:test }
171
if (typeof test === 'number')