fix: was displaying "comment" tools even with descript_ion disabled
Massimo Melina committed
Oct 21, 2023 at 02:39 UTC
7f395040aceb16c9428f460cee41b403e70d4f10
5 files changed
+14
-7
frontend/src/fileMenu.ts
+1
-1
@@ -26,7 +26,7 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMe
26
const cantDownload = entry.cantOpen || isFolder && entry.p?.includes('r') // folders needs both list and read
27
const menu = [
28
!cantDownload && { id: 'download', label: t`Download`, href: uri + (isFolder ? '?get=zip' : '?dl'), icon: 'download' },
29
- state.props?.can_upload && { id: 'comment', label: t`Comment`, icon: 'comment', onClick: () => editComment(entry) },
29
+ state.props?.can_comment && { id: 'comment', label: t`Comment`, icon: 'comment', onClick: () => editComment(entry) },
30
...addToMenu.map(x => {
31
if (x === 'open') {
32
if (entry.cantOpen) return
frontend/src/state.ts
+1
@@ -32,6 +32,7 @@ export const state = proxy<{
32
accept?: string
33
can_delete?: boolean
34
can_archive?: boolean
35
+ can_comment?: boolean
36
}
37
tilesSize: number
38
}>({
frontend/src/upload.ts
+5
-4
@@ -138,8 +138,9 @@ export function showUpload() {
138
entries: adding,
139
actions: {
140
delete: rec => _.remove(uploadState.adding, { file: rec.file }),
141
- comment: rec => inputComment(basename(rec.file.name), rec.comment)
142
- .then(s => _.find(uploadState.adding, { file: rec.file })!.comment = s || undefined),
141
+ comment: !props?.can_comment ? null
142
+ : (rec => inputComment(basename(rec.file.name), rec.comment)
143
+ .then(s => _.find(uploadState.adding, { file: rec.file })!.comment = s || undefined)),
144
},
145
}),
146
h(UploadStatus, { margin: '.5em 0' }),
@@ -191,7 +192,7 @@ function path(f: File, pre='') {
192
return (prefix('', pre, '/') + (f.webkitRelativePath || f.name)).replaceAll('//','/')
193
}
194
194
-function FilesList({ entries, actions }: { entries: Readonly<ToUpload[]>, actions: { [icon:string]: (rec :ToUpload) => any } }) {
195
+function FilesList({ entries, actions }: { entries: Readonly<ToUpload[]>, actions: { [icon:string]: null | ((rec :ToUpload) => any) } }) {
196
const { uploading, progress } = useSnapshot(uploadState)
197
return !entries.length ? null : h('table', { className: 'upload-list', width: '100%' },
198
h('tbody', {},
@@ -199,7 +200,7 @@ function FilesList({ entries, actions }: { entries: Readonly<ToUpload[]>, action
200
const working = e === uploading
201
return h(Fragment, { key: i },
202
h('tr', {},
202
- h('td', { className: 'nowrap '}, ..._.map(actions, (cb, icon) => iconBtn(icon, () => cb(e))) ),
203
+ h('td', { className: 'nowrap '}, ..._.map(actions, (cb, icon) => cb && iconBtn(icon, () => cb(e))) ),
204
h('td', {}, formatBytes(e.file.size)),
205
h('td', { className: working ? 'ani-working' : undefined },
206
path(e.file),
src/api.file_list.ts
+3
-2
@@ -8,7 +8,7 @@ import { mapPlugins } from './plugins'
8
import { asyncGeneratorToArray, dirTraversal, pattern2filter, WHO_NO_ONE } from './misc'
9
import { HTTP_FOOL, HTTP_METHOD_NOT_ALLOWED, HTTP_NOT_FOUND } from './const'
10
import Koa from 'koa'
11
-import { descriptIon, DESCRIPT_ION, getCommentFor } from './comments'
11
+import { descriptIon, DESCRIPT_ION, getCommentFor, areCommentsEnabled } from './comments'
12
import { basename } from 'path'
13
14
export interface DirEntry { n:string, s?:number, m?:Date, c?:Date, p?: string, comment?: string, web?: boolean }
@@ -33,7 +33,8 @@ export const get_file_list: ApiHandler = async ({ uri, offset, limit, search, c
33
const fakeChild = applyParentToChild({}, node) // we want to know if we want to delete children
34
const can_delete = hasPermission(fakeChild, 'can_delete', ctx)
35
const can_archive = hasPermission(fakeChild, 'can_archive', ctx)
36
- const props = { can_archive, can_upload, can_delete, accept: node.accept }
36
+ const can_comment = can_upload && areCommentsEnabled()
37
+ const props = { can_archive, can_upload, can_delete, accept: node.accept, can_comment }
38
if (!list)
39
return { ...props, list: await asyncGeneratorToArray(produceEntries()) }
40
setTimeout(async () => {
src/comments.ts
+4
@@ -33,6 +33,10 @@ export const setCommentFor = singleFromBatch(async (jobs: [path: string, comment
33
}))
34
})
35
36
+export function areCommentsEnabled() {
37
+ return descriptIon.get()
38
+}
39
+
40
const MULTILINE_SUFFIX = '\x04\xc2'
41
function readDescription(path: string) {
42
return parseFile(join(path, DESCRIPT_ION), txt => new Map(txt.split('\n').map(line => {