@nextcloud/files 3.0.0-beta.4 → 3.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/files/file.d.ts +26 -0
- package/dist/files/fileType.d.ts +25 -0
- package/dist/files/folder.d.ts +30 -0
- package/dist/files/node.d.ts +69 -0
- package/dist/files/nodeData.d.ts +51 -0
- package/dist/humanfilesize.d.ts +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +359 -14
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +426 -13
- package/dist/index.js.map +1 -1
- package/dist/permissions.d.ts +35 -0
- package/dist/utils/logger.d.ts +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
3
|
+
*
|
|
4
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
5
|
+
*
|
|
6
|
+
* @license AGPL-3.0-or-later
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Affero General Public License as
|
|
10
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
11
|
+
* License, or (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Affero General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
import { FileType } from './fileType';
|
|
23
|
+
import Node from './node';
|
|
24
|
+
export declare class File extends Node {
|
|
25
|
+
get type(): FileType;
|
|
26
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
3
|
+
*
|
|
4
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
5
|
+
*
|
|
6
|
+
* @license AGPL-3.0-or-later
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Affero General Public License as
|
|
10
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
11
|
+
* License, or (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Affero General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare enum FileType {
|
|
23
|
+
Folder = "folder",
|
|
24
|
+
File = "file"
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
3
|
+
*
|
|
4
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
5
|
+
*
|
|
6
|
+
* @license AGPL-3.0-or-later
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Affero General Public License as
|
|
10
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
11
|
+
* License, or (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Affero General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
import { FileType } from './fileType';
|
|
23
|
+
import Node from './node';
|
|
24
|
+
import NodeData from './nodeData';
|
|
25
|
+
export declare class Folder extends Node {
|
|
26
|
+
constructor(data: NodeData);
|
|
27
|
+
get type(): FileType;
|
|
28
|
+
get extension(): string | null;
|
|
29
|
+
get mime(): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Permission } from '../permissions';
|
|
2
|
+
import { FileType } from './fileType';
|
|
3
|
+
import NodeData, { Attribute } from './nodeData';
|
|
4
|
+
export default abstract class Node {
|
|
5
|
+
private _data;
|
|
6
|
+
private _attributes;
|
|
7
|
+
private _knownDavService;
|
|
8
|
+
constructor(data: NodeData, davService?: RegExp);
|
|
9
|
+
/**
|
|
10
|
+
* Get the source url to this object
|
|
11
|
+
*/
|
|
12
|
+
get source(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Get this object name
|
|
15
|
+
*/
|
|
16
|
+
get basename(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Get this object's extension
|
|
19
|
+
*/
|
|
20
|
+
get extension(): string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Get the directory path leading to this object
|
|
23
|
+
*/
|
|
24
|
+
get dirname(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Is it a file or a folder ?
|
|
27
|
+
*/
|
|
28
|
+
abstract get type(): FileType;
|
|
29
|
+
/**
|
|
30
|
+
* Get the file mime
|
|
31
|
+
*/
|
|
32
|
+
get mime(): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Get the file size
|
|
35
|
+
*/
|
|
36
|
+
get size(): number | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Get the file attribute
|
|
39
|
+
*/
|
|
40
|
+
get attributes(): Attribute;
|
|
41
|
+
/**
|
|
42
|
+
* Get the file permissions
|
|
43
|
+
*/
|
|
44
|
+
get permissions(): Permission;
|
|
45
|
+
/**
|
|
46
|
+
* Get the file owner
|
|
47
|
+
*/
|
|
48
|
+
get owner(): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Is this a dav-related ressource ?
|
|
51
|
+
*/
|
|
52
|
+
get isDavRessource(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Get the dav root of this object
|
|
55
|
+
*/
|
|
56
|
+
get root(): string | null;
|
|
57
|
+
/**
|
|
58
|
+
* Move the node to a new destination
|
|
59
|
+
*
|
|
60
|
+
* @param {string} destination the new source.
|
|
61
|
+
* e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
|
|
62
|
+
*/
|
|
63
|
+
move(destination: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Rename the node
|
|
66
|
+
* This aliases the move method for easier usage
|
|
67
|
+
*/
|
|
68
|
+
rename(basename: any): void;
|
|
69
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
3
|
+
*
|
|
4
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
5
|
+
*
|
|
6
|
+
* @license AGPL-3.0-or-later
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Affero General Public License as
|
|
10
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
11
|
+
* License, or (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Affero General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
import { Permission } from "../permissions";
|
|
23
|
+
export interface Attribute {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
export default interface NodeData {
|
|
27
|
+
/** Unique ID */
|
|
28
|
+
id?: number;
|
|
29
|
+
/** URL to the ressource
|
|
30
|
+
* e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
|
|
31
|
+
* or https://domain.com/Photos/picture.jpg
|
|
32
|
+
*/
|
|
33
|
+
source: string;
|
|
34
|
+
/** Last modified time */
|
|
35
|
+
mtime?: Date;
|
|
36
|
+
/** Creation time */
|
|
37
|
+
crtime?: Date;
|
|
38
|
+
/** The mime type */
|
|
39
|
+
mime?: string;
|
|
40
|
+
/** The node size type */
|
|
41
|
+
size?: number;
|
|
42
|
+
/** The node permissions */
|
|
43
|
+
permissions?: Permission;
|
|
44
|
+
/** The owner UID of this node */
|
|
45
|
+
owner: string | null;
|
|
46
|
+
attributes?: Attribute;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validate Node construct data
|
|
50
|
+
*/
|
|
51
|
+
export declare const validateData: (data: NodeData) => void;
|
package/dist/humanfilesize.d.ts
CHANGED
|
@@ -26,4 +26,4 @@
|
|
|
26
26
|
* @param size in bytes
|
|
27
27
|
* @param skipSmallSizes avoid rendering tiny sizes and return '< 1 KB' instead
|
|
28
28
|
*/
|
|
29
|
-
export declare function formatFileSize(size: number | string, skipSmallSizes?: boolean): string;
|
|
29
|
+
export declare function formatFileSize(size: number | string, skipSmallSizes?: boolean, binaryPrefixes?: boolean): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
export { formatFileSize } from './humanfilesize';
|
|
24
24
|
export { type Entry } from './newFileMenu';
|
|
25
25
|
import { type Entry, NewFileMenu } from './newFileMenu';
|
|
26
|
+
export { FileType } from './files/fileType';
|
|
27
|
+
export { File } from './files/file';
|
|
28
|
+
export { Folder } from './files/folder';
|
|
29
|
+
export { Permission, parseWebdavPermissions } from './permissions';
|
|
26
30
|
declare global {
|
|
27
31
|
interface Window {
|
|
28
32
|
OC: any;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getCanonicalLocale } from '@nextcloud/l10n';
|
|
2
2
|
import { getCurrentUser } from '@nextcloud/auth';
|
|
3
3
|
import { getLoggerBuilder } from '@nextcloud/logger';
|
|
4
|
+
import { basename, extname, dirname } from 'path';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
@@ -24,30 +25,32 @@ import { getLoggerBuilder } from '@nextcloud/logger';
|
|
|
24
25
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
25
26
|
*
|
|
26
27
|
*/
|
|
27
|
-
const humanList = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
28
|
+
const humanList = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
29
|
+
const humanListBinary = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
|
|
28
30
|
/**
|
|
29
31
|
* Format a file size in a human-like format. e.g. 42GB
|
|
30
32
|
*
|
|
31
33
|
* @param size in bytes
|
|
32
34
|
* @param skipSmallSizes avoid rendering tiny sizes and return '< 1 KB' instead
|
|
33
35
|
*/
|
|
34
|
-
function formatFileSize(size, skipSmallSizes = false) {
|
|
36
|
+
function formatFileSize(size, skipSmallSizes = false, binaryPrefixes = false) {
|
|
35
37
|
if (typeof size === 'string') {
|
|
36
38
|
size = Number(size);
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
/*
|
|
41
|
+
* @note This block previously used Log base 1024, per IEC 80000-13;
|
|
42
|
+
* however, the wrong prefix was used. Now we use decimal calculation
|
|
43
|
+
* with base 1000 per the SI. Base 1024 calculation with binary
|
|
44
|
+
* prefixes is optional, but has yet to be added to the UI.
|
|
45
|
+
*/
|
|
46
|
+
// Calculate Log with base 1024 or 1000: size = base ** order
|
|
47
|
+
let order = size > 0 ? Math.floor(Math.log(size) / Math.log(binaryPrefixes ? 1024 : 1000)) : 0;
|
|
40
48
|
// Stay in range of the byte sizes that are defined
|
|
41
|
-
order = Math.min(humanList.length - 1, order);
|
|
42
|
-
const readableFormat = humanList[order];
|
|
43
|
-
let relativeSize = (size / Math.pow(1024, order)).toFixed(1);
|
|
49
|
+
order = Math.min((binaryPrefixes ? humanListBinary.length : humanList.length) - 1, order);
|
|
50
|
+
const readableFormat = binaryPrefixes ? humanListBinary[order] : humanList[order];
|
|
51
|
+
let relativeSize = (size / Math.pow(binaryPrefixes ? 1024 : 1000, order)).toFixed(1);
|
|
44
52
|
if (skipSmallSizes === true && order === 0) {
|
|
45
|
-
|
|
46
|
-
return '< 1 KB';
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
return '0 KB';
|
|
50
|
-
}
|
|
53
|
+
return (relativeSize !== '0.0' ? '< 1 ' : '0 ') + (binaryPrefixes ? humanListBinary[1] : humanList[1]);
|
|
51
54
|
}
|
|
52
55
|
if (order < 2) {
|
|
53
56
|
relativeSize = parseFloat(relativeSize).toFixed(0);
|
|
@@ -181,6 +184,348 @@ const getNewFileMenu = function () {
|
|
|
181
184
|
return window._nc_newfilemenu;
|
|
182
185
|
};
|
|
183
186
|
|
|
187
|
+
/**
|
|
188
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
189
|
+
*
|
|
190
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
191
|
+
*
|
|
192
|
+
* @license AGPL-3.0-or-later
|
|
193
|
+
*
|
|
194
|
+
* This program is free software: you can redistribute it and/or modify
|
|
195
|
+
* it under the terms of the GNU Affero General Public License as
|
|
196
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
197
|
+
* License, or (at your option) any later version.
|
|
198
|
+
*
|
|
199
|
+
* This program is distributed in the hope that it will be useful,
|
|
200
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
201
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
202
|
+
* GNU Affero General Public License for more details.
|
|
203
|
+
*
|
|
204
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
205
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
206
|
+
*
|
|
207
|
+
*/
|
|
208
|
+
var FileType;
|
|
209
|
+
(function (FileType) {
|
|
210
|
+
FileType["Folder"] = "folder";
|
|
211
|
+
FileType["File"] = "file";
|
|
212
|
+
})(FileType || (FileType = {}));
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
216
|
+
*
|
|
217
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
218
|
+
*
|
|
219
|
+
* @license AGPL-3.0-or-later
|
|
220
|
+
*
|
|
221
|
+
* This program is free software: you can redistribute it and/or modify
|
|
222
|
+
* it under the terms of the GNU Affero General Public License as
|
|
223
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
224
|
+
* License, or (at your option) any later version.
|
|
225
|
+
*
|
|
226
|
+
* This program is distributed in the hope that it will be useful,
|
|
227
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
228
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
229
|
+
* GNU Affero General Public License for more details.
|
|
230
|
+
*
|
|
231
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
232
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
233
|
+
*
|
|
234
|
+
*/
|
|
235
|
+
var Permission;
|
|
236
|
+
(function (Permission) {
|
|
237
|
+
Permission[Permission["NONE"] = 0] = "NONE";
|
|
238
|
+
Permission[Permission["CREATE"] = 4] = "CREATE";
|
|
239
|
+
Permission[Permission["READ"] = 1] = "READ";
|
|
240
|
+
Permission[Permission["UPDATE"] = 2] = "UPDATE";
|
|
241
|
+
Permission[Permission["DELETE"] = 8] = "DELETE";
|
|
242
|
+
Permission[Permission["SHARE"] = 16] = "SHARE";
|
|
243
|
+
Permission[Permission["ALL"] = 31] = "ALL";
|
|
244
|
+
})(Permission || (Permission = {}));
|
|
245
|
+
/**
|
|
246
|
+
* Parse the webdav permission string to a permission enum
|
|
247
|
+
* @see https://github.com/nextcloud/server/blob/71f698649f578db19a22457cb9d420fb62c10382/lib/public/Files/DavUtil.php#L58-L88
|
|
248
|
+
*/
|
|
249
|
+
const parseWebdavPermissions = function (permString = '') {
|
|
250
|
+
let permissions = Permission.NONE;
|
|
251
|
+
if (!permString)
|
|
252
|
+
return permissions;
|
|
253
|
+
if (permString.includes('C') || permString.includes('K'))
|
|
254
|
+
permissions |= Permission.CREATE;
|
|
255
|
+
if (permString.includes('G'))
|
|
256
|
+
permissions |= Permission.READ;
|
|
257
|
+
if (permString.includes('W') || permString.includes('N') || permString.includes('V'))
|
|
258
|
+
permissions |= Permission.UPDATE;
|
|
259
|
+
if (permString.includes('D'))
|
|
260
|
+
permissions |= Permission.DELETE;
|
|
261
|
+
if (permString.includes('R'))
|
|
262
|
+
permissions |= Permission.SHARE;
|
|
263
|
+
return permissions;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
268
|
+
*
|
|
269
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
270
|
+
*
|
|
271
|
+
* @license AGPL-3.0-or-later
|
|
272
|
+
*
|
|
273
|
+
* This program is free software: you can redistribute it and/or modify
|
|
274
|
+
* it under the terms of the GNU Affero General Public License as
|
|
275
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
276
|
+
* License, or (at your option) any later version.
|
|
277
|
+
*
|
|
278
|
+
* This program is distributed in the hope that it will be useful,
|
|
279
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
280
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
281
|
+
* GNU Affero General Public License for more details.
|
|
282
|
+
*
|
|
283
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
284
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
285
|
+
*
|
|
286
|
+
*/
|
|
287
|
+
/**
|
|
288
|
+
* Validate Node construct data
|
|
289
|
+
*/
|
|
290
|
+
const validateData = (data) => {
|
|
291
|
+
if ('id' in data && (typeof data.id !== 'number' || data.id < 0)) {
|
|
292
|
+
throw new Error('Invalid id type of value');
|
|
293
|
+
}
|
|
294
|
+
if (!data.source) {
|
|
295
|
+
throw new Error('Missing mandatory source');
|
|
296
|
+
}
|
|
297
|
+
if (!data.source.startsWith('http')) {
|
|
298
|
+
throw new Error('Invalid source format');
|
|
299
|
+
}
|
|
300
|
+
if ('mtime' in data && !(data.mtime instanceof Date)) {
|
|
301
|
+
throw new Error('Invalid mtime type');
|
|
302
|
+
}
|
|
303
|
+
if ('crtime' in data && !(data.crtime instanceof Date)) {
|
|
304
|
+
throw new Error('Invalid crtime type');
|
|
305
|
+
}
|
|
306
|
+
if (!data.mime || typeof data.mime !== 'string'
|
|
307
|
+
|| !data.mime.match(/^[-\w.]+\/[-+\w.]+$/gi)) {
|
|
308
|
+
throw new Error('Missing or invalid mandatory mime');
|
|
309
|
+
}
|
|
310
|
+
if ('size' in data && typeof data.size !== 'number') {
|
|
311
|
+
throw new Error('Invalid size type');
|
|
312
|
+
}
|
|
313
|
+
if ('permissions' in data && !(typeof data.permissions === 'number'
|
|
314
|
+
&& data.permissions >= Permission.NONE
|
|
315
|
+
&& data.permissions <= Permission.ALL)) {
|
|
316
|
+
throw new Error('Invalid permissions');
|
|
317
|
+
}
|
|
318
|
+
if ('owner' in data
|
|
319
|
+
&& data.owner !== null
|
|
320
|
+
&& typeof data.owner !== 'string') {
|
|
321
|
+
throw new Error('Invalid owner type');
|
|
322
|
+
}
|
|
323
|
+
if ('attributes' in data && typeof data.attributes !== 'object') {
|
|
324
|
+
throw new Error('Invalid attributes format');
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
330
|
+
*
|
|
331
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
332
|
+
*
|
|
333
|
+
* @license AGPL-3.0-or-later
|
|
334
|
+
*
|
|
335
|
+
* This program is free software: you can redistribute it and/or modify
|
|
336
|
+
* it under the terms of the GNU Affero General Public License as
|
|
337
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
338
|
+
* License, or (at your option) any later version.
|
|
339
|
+
*
|
|
340
|
+
* This program is distributed in the hope that it will be useful,
|
|
341
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
342
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
343
|
+
* GNU Affero General Public License for more details.
|
|
344
|
+
*
|
|
345
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
346
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
347
|
+
*
|
|
348
|
+
*/
|
|
349
|
+
class Node {
|
|
350
|
+
_data;
|
|
351
|
+
_attributes;
|
|
352
|
+
_knownDavService = /(remote|public)\.php\/(web)?dav/i;
|
|
353
|
+
constructor(data, davService) {
|
|
354
|
+
// Validate data
|
|
355
|
+
validateData(data);
|
|
356
|
+
this._data = data;
|
|
357
|
+
this._attributes = data.attributes || {};
|
|
358
|
+
delete this._data.attributes;
|
|
359
|
+
if (davService) {
|
|
360
|
+
this._knownDavService = davService;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Get the source url to this object
|
|
365
|
+
*/
|
|
366
|
+
get source() {
|
|
367
|
+
// strip any ending slash
|
|
368
|
+
return this._data.source.replace(/\/$/i, '');
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Get this object name
|
|
372
|
+
*/
|
|
373
|
+
get basename() {
|
|
374
|
+
return basename(this.source);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Get this object's extension
|
|
378
|
+
*/
|
|
379
|
+
get extension() {
|
|
380
|
+
return extname(this.source);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get the directory path leading to this object
|
|
384
|
+
*/
|
|
385
|
+
get dirname() {
|
|
386
|
+
return dirname(this.source);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Get the file mime
|
|
390
|
+
*/
|
|
391
|
+
get mime() {
|
|
392
|
+
return this._data.mime;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Get the file size
|
|
396
|
+
*/
|
|
397
|
+
get size() {
|
|
398
|
+
return this._data.size;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get the file attribute
|
|
402
|
+
*/
|
|
403
|
+
get attributes() {
|
|
404
|
+
return this._attributes;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Get the file permissions
|
|
408
|
+
*/
|
|
409
|
+
get permissions() {
|
|
410
|
+
// If this is not a dav ressource, we can only read it
|
|
411
|
+
if (this.owner === null && !this.isDavRessource) {
|
|
412
|
+
return Permission.READ;
|
|
413
|
+
}
|
|
414
|
+
return this._data.permissions || Permission.READ;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Get the file owner
|
|
418
|
+
*/
|
|
419
|
+
get owner() {
|
|
420
|
+
// Remote ressources have no owner
|
|
421
|
+
if (!this.isDavRessource) {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
return this._data.owner;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Is this a dav-related ressource ?
|
|
428
|
+
*/
|
|
429
|
+
get isDavRessource() {
|
|
430
|
+
return this.source.match(this._knownDavService) !== null;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Get the dav root of this object
|
|
434
|
+
*/
|
|
435
|
+
get root() {
|
|
436
|
+
if (this.isDavRessource) {
|
|
437
|
+
return this.dirname.split(this._knownDavService).pop() || null;
|
|
438
|
+
}
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Move the node to a new destination
|
|
443
|
+
*
|
|
444
|
+
* @param {string} destination the new source.
|
|
445
|
+
* e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
|
|
446
|
+
*/
|
|
447
|
+
move(destination) {
|
|
448
|
+
this._data.source = destination;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Rename the node
|
|
452
|
+
* This aliases the move method for easier usage
|
|
453
|
+
*/
|
|
454
|
+
rename(basename) {
|
|
455
|
+
if (basename.includes('/')) {
|
|
456
|
+
throw new Error('Invalid basename');
|
|
457
|
+
}
|
|
458
|
+
this.move(this.dirname + '/' + basename);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
464
|
+
*
|
|
465
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
466
|
+
*
|
|
467
|
+
* @license AGPL-3.0-or-later
|
|
468
|
+
*
|
|
469
|
+
* This program is free software: you can redistribute it and/or modify
|
|
470
|
+
* it under the terms of the GNU Affero General Public License as
|
|
471
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
472
|
+
* License, or (at your option) any later version.
|
|
473
|
+
*
|
|
474
|
+
* This program is distributed in the hope that it will be useful,
|
|
475
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
476
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
477
|
+
* GNU Affero General Public License for more details.
|
|
478
|
+
*
|
|
479
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
480
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
481
|
+
*
|
|
482
|
+
*/
|
|
483
|
+
class File extends Node {
|
|
484
|
+
get type() {
|
|
485
|
+
return FileType.File;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
|
|
491
|
+
*
|
|
492
|
+
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
493
|
+
*
|
|
494
|
+
* @license AGPL-3.0-or-later
|
|
495
|
+
*
|
|
496
|
+
* This program is free software: you can redistribute it and/or modify
|
|
497
|
+
* it under the terms of the GNU Affero General Public License as
|
|
498
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
499
|
+
* License, or (at your option) any later version.
|
|
500
|
+
*
|
|
501
|
+
* This program is distributed in the hope that it will be useful,
|
|
502
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
503
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
504
|
+
* GNU Affero General Public License for more details.
|
|
505
|
+
*
|
|
506
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
507
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
508
|
+
*
|
|
509
|
+
*/
|
|
510
|
+
class Folder extends Node {
|
|
511
|
+
constructor(data) {
|
|
512
|
+
// enforcing mimes
|
|
513
|
+
super({
|
|
514
|
+
...data,
|
|
515
|
+
mime: 'httpd/unix-directory'
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
get type() {
|
|
519
|
+
return FileType.Folder;
|
|
520
|
+
}
|
|
521
|
+
get extension() {
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
get mime() {
|
|
525
|
+
return 'httpd/unix-directory';
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
184
529
|
/**
|
|
185
530
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
186
531
|
*
|
|
@@ -227,5 +572,5 @@ const getNewFileMenuEntries = function (context) {
|
|
|
227
572
|
return newFileMenu.getEntries(context);
|
|
228
573
|
};
|
|
229
574
|
|
|
230
|
-
export { addNewFileMenuEntry, formatFileSize, getNewFileMenuEntries, removeNewFileMenuEntry };
|
|
575
|
+
export { File, FileType, Folder, Permission, addNewFileMenuEntry, formatFileSize, getNewFileMenuEntries, parseWebdavPermissions, removeNewFileMenuEntry };
|
|
231
576
|
//# sourceMappingURL=index.esm.js.map
|