@samitouri / QOSami-HFS / commits / c8a2bdb7
Fork 0

QOSami-HFS is a web file server for your computer. Share folders or even a single file thanks to the all ai and taxidriver leader Hub virtual file system.

don't show uploader's ip if you are not admin

Massimo Melina committed Aug 24, 2024 at 17:40 UTC c8a2bdb7ab983b67c9039fa71cffd2cef909a100
3 files changed +19 -5
frontend/src/fileMenu.ts
+8 -1
@@ -99,7 +99,8 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMe
99 const {t} = useI18N()
100 const details = useApi('get_file_details', { uris: [entry.uri] }).data?.details?.[0]
101 const showProps = [ ...props,
102 - with_(details?.upload, x => x && { id: 'uploader', label: t`Uploader`, value: x.ip + prefix(' (', x.username, ')') })
102 + with_(renderUploaderFromDetails(details), value =>
103 + value && { id: 'uploader', label: t`Uploader`, value })
104 ]
105 return h(Fragment, {},
106 h('dl', { className: 'file-dialog-properties' },
@@ -200,4 +201,10 @@ export function makeOnClickOpen(entry: DirEntry) {
201 return setTimeout(() => getHFS().navigate(entry.uri)) // couldn't find the reason why navigating sync is reverted back
202 location.href = entry.uri
203 }
204 +}
205 +
206 +function renderUploaderFromDetails(details: any) {
207 + if (!details) return
208 + const { upload: u } = details
209 + return u && `${u.username||''}${prefix('@', u.ip)}`
210 }
\ No newline at end of file
plugins/list-uploader/public/main.js
+3 -2
@@ -10,10 +10,11 @@
10 const text = React.useMemo(() => {
11 if (!data || data === true) return ''
12 const { upload: x } = data
13 + const shouldShowIpWithUser = display === 'ip+user' && x.ip || display === 'tooltip' && HFS.state.adminUrl
14 return !x ? ''
15 : display === 'user' ? x.username
15 - : display === 'ip' || !x.username ? x.ip
16 - : x.ip + ' (' + x.username + ')'
16 + : display === 'ip' || !x.username && shouldShowIpWithUser ? x.ip
17 + : shouldShowIpWithUser ? x.ip + ' (' + x.username + ')' : x.username
18 }, [data])
19 const iconOnly = display === 'tooltip'
20 return text && HFS.h('span', { className: 'uploader', title: HFS.t`Uploader` + (iconOnly ? ' ' + text : '') },
src/frontEndApis.ts
+8 -2
@@ -15,6 +15,8 @@ import { getUploadMeta } from './upload'
15 import { apiAssertTypes, deleteNode } from './misc'
16 import { getCommentFor, setCommentFor } from './comments'
17 import { SendListReadable } from './SendList'
18 +import { ctxAdminAccess } from './adminApis'
19 +import _ from 'lodash'
20
21 export const frontEndApis: ApiHandlers = {
22 get_file_list,
@@ -34,6 +36,7 @@ export const frontEndApis: ApiHandlers = {
36 async get_file_details({ uris }, ctx) {
37 if (typeof uris?.[0] !== 'string')
38 return new ApiError(HTTP_BAD_REQUEST, 'bad uris')
39 + const isAdmin = ctxAdminAccess(ctx)
40 return {
41 details: await Promise.all(uris.map(async (uri: any) => {
42 if (typeof uri !== 'string')
@@ -41,8 +44,11 @@ export const frontEndApis: ApiHandlers = {
44 const node = await urlToNode(uri, ctx)
45 if (!node)
46 return false
44 - const upload = node.source && await getUploadMeta(node.source).catch(() => undefined)
45 - return upload && { upload }
47 + let upload = node.source && await getUploadMeta(node.source).catch(() => undefined)
48 + if (!upload) return
49 + if (!isAdmin)
50 + upload = _.omit(upload, 'ip')
51 + return { upload }
52 }))
53 }
54 },