Skip to content

Commit

Permalink
fix: (regression 0.50.0-alpha1) bad default mime type, causing some f…
Browse files Browse the repository at this point in the history
…iles to be downloaded instead of open

--importing 'auth' in vfs.ts caused MIME_TYPE to be undefined in serveFile.ts
  • Loading branch information
rejetto committed Dec 6, 2023
1 parent 1e20113 commit 481668a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const IS_WINDOWS = process.platform === 'win32'
export const IS_MAC = process.platform === 'darwin'
export const IS_BINARY = !basename(process.execPath).includes('node') // this won't be node if pkg was used
export const APP_PATH = dirname(IS_BINARY ? process.execPath : __dirname)
export const MIME_AUTO = 'auto'

// we want this to be the first stuff to be printed, then we print it in this module, that is executed at the beginning
if (DEV) console.clear()
Expand Down
10 changes: 4 additions & 6 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import glob from 'fast-glob'
import { watchLoad } from './watchLoad'
import _ from 'lodash'
import { API_VERSION, APP_PATH, COMPATIBLE_API_VERSION, IS_WINDOWS, PLUGINS_PUB_URI } from './const'
import { API_VERSION, APP_PATH, COMPATIBLE_API_VERSION, IS_WINDOWS, MIME_AUTO, PLUGINS_PUB_URI } from './const'
import * as Const from './const'
import Koa from 'koa'
import {
adjustStaticPathForGlob, Callback, debounceAsync, Dict, getOrSet, onlyTruthy, onProcessExit,
PendingPromise, pendingPromise, same, tryJson, wait, waitFor, wantArray, watchDir
} from './misc'
import { adjustStaticPathForGlob, Callback, debounceAsync, Dict, getOrSet, onlyTruthy, onProcessExit,
PendingPromise, pendingPromise, same, tryJson, wait, waitFor, wantArray, watchDir } from './misc'
import { defineConfig, getConfig } from './config'
import { DirEntry } from './api.file_list'
import { MIME_AUTO, VfsNode } from './vfs'
import { VfsNode } from './vfs'
import { serveFile } from './serveFile'
import events from './events'
import { mkdir, readFile } from 'fs/promises'
Expand Down
13 changes: 3 additions & 10 deletions src/serveFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

import Koa from 'koa'
import { createReadStream, stat } from 'fs'
import {
HTTP_BAD_REQUEST,
HTTP_FORBIDDEN,
HTTP_METHOD_NOT_ALLOWED,
HTTP_NO_CONTENT,
HTTP_NOT_FOUND,
HTTP_NOT_MODIFIED,
HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_RANGE_NOT_SATISFIABLE
} from './const'
import { getNodeName, MIME_AUTO, VfsNode } from './vfs'
import { HTTP_BAD_REQUEST, HTTP_FORBIDDEN, HTTP_METHOD_NOT_ALLOWED, HTTP_NO_CONTENT, HTTP_NOT_FOUND, HTTP_NOT_MODIFIED,
HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_RANGE_NOT_SATISFIABLE, MIME_AUTO } from './const'
import { getNodeName, VfsNode } from './vfs'
import mimetypes from 'mime-types'
import { defineConfig } from './config'
import { matches } from './misc'
Expand Down
13 changes: 2 additions & 11 deletions src/serveGuiFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

import Koa from 'koa'
import fs from 'fs/promises'
import {
API_VERSION,
FRONTEND_URI,
HTTP_METHOD_NOT_ALLOWED,
HTTP_NO_CONTENT,
HTTP_NOT_FOUND,
PLUGINS_PUB_URI,
VERSION,
SPECIAL_URI
} from './const'
import { API_VERSION, MIME_AUTO, FRONTEND_URI, HTTP_METHOD_NOT_ALLOWED, HTTP_NO_CONTENT, HTTP_NOT_FOUND,
PLUGINS_PUB_URI, VERSION, SPECIAL_URI } from './const'
import { serveFile } from './serveFile'
import { getPluginConfigFields, getPluginInfo, mapPlugins, pluginsConfig } from './plugins'
import { refresh_session } from './api.auth'
Expand All @@ -24,7 +16,6 @@ import { customHtmlState, getSection } from './customHtml'
import _ from 'lodash'
import { defineConfig, getConfig } from './config'
import { getLangData } from './lang'
import { MIME_AUTO } from './vfs'

const logGui = defineConfig('log_gui', false)
_.each(FRONTEND_OPTIONS, (v,k) => defineConfig(k, v)) // define default values
Expand Down
4 changes: 1 addition & 3 deletions src/vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import Koa from 'koa'
import _ from 'lodash'
import { defineConfig, setConfig } from './config'
import { HTTP_FOOL, HTTP_FORBIDDEN, HTTP_UNAUTHORIZED } from './const'
import { HTTP_FOOL, HTTP_FORBIDDEN, HTTP_UNAUTHORIZED, MIME_AUTO } from './const'
import events from './events'
import { expandUsername } from './perm'
import { getCurrentUsername } from './auth'
Expand All @@ -34,8 +34,6 @@ export interface VfsNode extends VfsNodeStored { // include fields that are only
isFolder?: boolean
}

export const MIME_AUTO = 'auto'

export function permsFromParent(parent: VfsNode, child: VfsNode) {
const ret: VfsPerms = {}
for (const k of PERM_KEYS) {
Expand Down
4 changes: 1 addition & 3 deletions tests/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
allowed_referer: x.com
vfs:
mime:
"*": auto
masks:
"!tests/page/*.png":
mime: text/plain
Expand Down Expand Up @@ -128,4 +126,4 @@ accounts:
disabled: true
admins:
admin: true
version: 0.49.4
version: 0.50.0-alpha2
3 changes: 2 additions & 1 deletion tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('basics', () => {
it('list', reqList('/f1/', { inList:['f2/', 'page/'] }))
it('search', reqList('f1', { inList:['f2/'], outList:['page'] }, { search:'2' }))
it('search root', reqList('/', { inList:['cantListPage/'], outList:['cantListPage/page/'] }, { search:'page' }))
it('download', req('/f1/f2/alfa.txt', { re:/abcd/, mime:'text/plain' }))
it('download.mime', req('/f1/f2/alfa.txt', { re:/abcd/, mime:'text/plain' }))
it('download.partial', req('/f1/f2/alfa.txt', /a[^d]+$/, { // only "abc" is expected
headers: { Range: 'bytes=0-2' }
}))
Expand Down Expand Up @@ -165,6 +165,7 @@ function req(methodUrl: string, test:Tester, requestOptions: AxiosRequestConfig<

function process(res:any) {
//console.debug('sent', requestOptions, 'got', res instanceof Error ? String(res) : [res.status])
if (res.code === "ECONNREFUSED") throw res
if (test && test instanceof RegExp)
test = { re:test }
if (typeof test === 'number')
Expand Down

0 comments on commit 481668a

Please sign in to comment.