better code: omit=c is the new default

Massimo Melina committed Jun 29, 2023 at 12:23 UTC 6a00c25a34a906865c77fc2443fd6133d24b7edd
3 files changed +6 -8
frontend/src/useFetchList.ts
-1
@@ -42,7 +42,6 @@ export default function useFetchList() {
42 uri: desiredPath,
43 search,
44 sse: true,
45 - omit: 'c',
45 [RELOADER_PROP]: snap.listReloader, // symbol, so it won't be serialized, but will force reloading
46 }
47 if (_.isEqual(baseParams, lastReq.current)) return
src/adminApis.ts
+1 -1
@@ -175,7 +175,7 @@ export const favicon = defineConfig('favicon', '')
175 export const title = defineConfig('title', "File server")
176
177 export function ctxAdminAccess(ctx: Koa.Context) {
178 - return !ctx.ips.length // we consider localhost_admin only if no proxy is being usedø
178 + return !ctx.ips.length // we consider localhost_admin only if no proxy is being used
179 && localhostAdmin.get() && isLocalHost(ctx)
180 || getFromAccount(ctx.state.account, a => a.admin)
181 }
src/api.file_list.ts
+5 -6
@@ -16,10 +16,10 @@ import { stat } from 'fs/promises'
16 import { mapPlugins } from './plugins'
17 import { asyncGeneratorToArray, dirTraversal, pattern2filter } from './misc'
18 import _ from 'lodash'
19 -import { HTTP_BAD_REQUEST, HTTP_FOOL, HTTP_METHOD_NOT_ALLOWED, HTTP_NOT_FOUND } from './const'
19 +import { HTTP_FOOL, HTTP_METHOD_NOT_ALLOWED, HTTP_NOT_FOUND } from './const'
20 import Koa from 'koa'
21
22 -export const file_list: ApiHandler = async ({ uri, offset, limit, search, omit, sse }, ctx) => {
22 +export const file_list: ApiHandler = async ({ uri, offset, limit, search, c, sse }, ctx) => {
23 const node = await urlToNode( uri || '/', ctx)
24 const list = new SendListReadable()
25 if (!node)
@@ -80,12 +80,11 @@ export const file_list: ApiHandler = async ({ uri, offset, limit, search, omit,
80 --offset
81 continue
82 }
83 - if (omit) {
84 - if (omit !== 'c')
85 - ctx.throw(HTTP_BAD_REQUEST, 'omit')
83 + if (!c) { // include c field?
84 if (!entry.m)
85 entry.m = entry.c
88 - delete entry.c
86 + if (entry.c)
87 + entry.c = undefined
88 }
89 yield entry
90 if (limit && !--limit)