plugin/list-uploader
Massimo Melina committed
Jun 27, 2023 at 16:27 UTC
45a347c4577f6c2b79ba8a5546ecf0f12d84fdc5
2 files changed
+48
plugins/list-uploader/plugin.js
new
+21
@@ -0,0 +1,21 @@
1
+exports.version = 1.0
2
+exports.description = "Show uploader info in list"
3
+exports.apiRequired = 8.23
4
+exports.frontend_js = "main.js"
5
+
6
+exports.configDialog = {
7
+ sx: { maxWidth: '15em' },
8
+}
9
+
10
+exports.config = {
11
+ display: {
12
+ type: 'select',
13
+ options: {
14
+ "IP only": 'ip',
15
+ "Username only": 'user',
16
+ "IP + username": 'ip+user',
17
+ },
18
+ defaultValue: 'ip+user',
19
+ frontend: true,
20
+ }
21
+}
\ No newline at end of file
plugins/list-uploader/public/main.js
new
+27
@@ -0,0 +1,27 @@
1
+{
2
+ const { display } = HFS.getPluginConfig()
3
+
4
+ HFS.onEvent('additionalEntryDetails', ({ entry }) =>
5
+ !entry.isFolder && HFS.h(Uploader, entry))
6
+
7
+ const cache = {}
8
+
9
+ function Uploader({ uri }) {
10
+ const fullUri = location.pathname + uri
11
+ const cachedData = cache[fullUri]
12
+ const [freshData, error] = HFS.useApi(!cachedData && 'get_file_details', { uri: fullUri })
13
+ if (!cachedData)
14
+ cache[fullUri] = freshData || Boolean(error)
15
+ const data = freshData || cachedData
16
+ const text = HFS.React.useMemo(() => {
17
+ if (!data || data === true) return ''
18
+ const { upload: x } = data
19
+ return !x ? ''
20
+ : display === 'user' ? x.username
21
+ : display === 'ip' || !x.username ? x.ip
22
+ : x.ip + ' (' + x.username + ')'
23
+ })
24
+ return text && HFS.h('span', { className: 'uploader', title: HFS.t`Uploader` },
25
+ HFS.hIcon('upload'), ' ', text, ' – ')
26
+ }
27
+}