Skip to content

Commit 4bf0659

Browse files
committed
fix(node): cloning
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 7c64dd5 commit 4bf0659

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

lib/node/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class File extends Node {
1515
* Returns a clone of the file
1616
*/
1717
clone(): File {
18-
return new File(this.data)
18+
return new File(this._data, this._knownDavService)
1919
}
2020

2121
}

lib/node/folder.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import type { NodeData } from './nodeData'
65
import { FileType } from './fileType'
76
import { Node } from './node'
87

98
export class Folder extends Node {
109

11-
constructor(data: NodeData) {
10+
constructor(...[data, davService]: ConstructorParameters<typeof Node>) {
1211
// enforcing mimes
1312
super({
1413
...data,
1514
mime: 'httpd/unix-directory',
16-
})
15+
}, davService)
1716
}
1817

1918
get type(): FileType.Folder {
@@ -32,7 +31,7 @@ export class Folder extends Node {
3231
* Returns a clone of the folder
3332
*/
3433
clone(): Folder {
35-
return new Folder(this.data)
34+
return new Folder(this._data, this._knownDavService)
3635
}
3736

3837
}

lib/node/node.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ export enum NodeStatus {
2121
LOCKED = 'locked',
2222
}
2323

24+
type NodeConstructorData = [NodeData, RegExp?]
25+
2426
export abstract class Node {
2527

26-
private _data: NodeData
2728
private _attributes: Attribute
28-
private _knownDavService = /(remote|public)\.php\/(web)?dav/i
29+
30+
protected _data: NodeData
31+
protected _knownDavService = /(remote|public)\.php\/(web)?dav/i
2932

3033
private readonlyAttributes = Object.entries(Object.getOwnPropertyDescriptors(Node.prototype))
3134
.filter(e => typeof e[1].get === 'function' && e[0] !== '__proto__')
@@ -58,7 +61,7 @@ export abstract class Node {
5861
},
5962
} as ProxyHandler<Attribute>
6063

61-
constructor(data: NodeData, davService?: RegExp) {
64+
constructor(...[data, davService]: NodeConstructorData) {
6265
if (!data.mime) {
6366
data.mime = 'application/octet-stream'
6467
}
@@ -346,13 +349,6 @@ export abstract class Node {
346349
this._data.status = status
347350
}
348351

349-
/**
350-
* Get the node data
351-
*/
352-
get data(): NodeData {
353-
return structuredClone(this._data)
354-
}
355-
356352
/**
357353
* Move the node to a new destination
358354
*

0 commit comments

Comments
 (0)