1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { FileStat, ResponseDataDetailed } from 'webdav'
import { Folder, Permission, View, davGetDefaultPropfind, davRemoteURL, davResultToNode, davRootPath, getNavigation } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { CancelablePromise } from 'cancelable-promise'
import LinkSvg from '@mdi/svg/svg/link.svg?raw'
import { client } from '../../../files/src/services/WebdavClient'
import logger from '../services/logger'
export default () => {
const view = new View({
id: 'public-file-share',
name: t('files_sharing', 'Public file share'),
caption: t('files_sharing', 'Publicly shared file.'),
emptyTitle: t('files_sharing', 'No file'),
emptyCaption: t('files_sharing', 'The file shared with you will show up here'),
icon: LinkSvg,
order: 1,
getContents: () => {
return new CancelablePromise(async (resolve, reject, onCancel) => {
const abort = new AbortController()
onCancel(() => abort.abort())
try {
const node = await client.stat(
davRootPath,
{
data: davGetDefaultPropfind(),
details: true,
signal: abort.signal,
},
) as ResponseDataDetailed<FileStat>
resolve({
// We only have one file as the content
contents: [davResultToNode(node.data)],
// Fake a readonly folder as root
folder: new Folder({
id: 0,
source: `${davRemoteURL}${davRootPath}`,
root: davRootPath,
owner: null,
permissions: Permission.READ,
attributes: {
// Ensure the share note is set on the root
note: node.data.props?.note,
},
}),
})
} catch (e) {
logger.error(e as Error)
reject(e as Error)
}
})
},
})
const Navigation = getNavigation()
Navigation.register(view)
}
|