aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/services/FileInfo.ts
blob: 18629845cca41a04484418ed52d1f4f71eb19d4e (plain)
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
/**
 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

/* eslint-disable jsdoc/require-jsdoc */

import type { Node } from '@nextcloud/files'

export default function(node: Node) {
	const fileInfo = new OC.Files.FileInfo({
		id: node.fileid,
		path: node.dirname,
		name: node.basename,
		mtime: node.mtime?.getTime(),
		etag: node.attributes.etag,
		size: node.size,
		hasPreview: node.attributes.hasPreview,
		isEncrypted: node.attributes.isEncrypted === 1,
		isFavourited: node.attributes.favorite === 1,
		mimetype: node.mime,
		permissions: node.permissions,
		mountType: node.attributes['mount-type'],
		sharePermissions: node.attributes['share-permissions'],
		shareAttributes: JSON.parse(node.attributes['share-attributes'] || '[]'),
		type: node.type === 'file' ? 'file' : 'dir',
	})

	// TODO remove when no more legacy backbone is used
	fileInfo.get = (key) => fileInfo[key]
	fileInfo.isDirectory = () => fileInfo.mimetype === 'httpd/unix-directory'
	fileInfo.canEdit = () => Boolean(fileInfo.permissions & OC.PERMISSION_UPDATE)

	return fileInfo
}