main
js 28 lines 1.22 KB
Raw
1 "use strict";{
2 const { React } = HFS
3 const { display } = HFS.getPluginConfig()
4
5 HFS.onEvent('additionalEntryDetails', ({ entry }) =>
6 HFS.h(Uploader, entry))
7
8 function Uploader({ uri }) {
9 const { data } = HFS.useBatch(getDetails, uri, { depend: HFS.state.isAdmin })
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
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 : '') },
21 HFS.hIcon('upload'), ' ', !iconOnly && text, HFS.h('span', { 'aria-hidden': true }, ''))
22 }
23
24 function getDetails(batched) {
25 return batched.length && HFS.apiCall('get_file_details', { uris: batched }).then(x => x.details)
26 }
27
28 }