Skip to content

Commit 9e0f249

Browse files
committed
feat(upload): allow to track children of an upload
This allow to better visualize ongoing uploads in an UI Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 1c8e5ab commit 9e0f249

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

lib/upload/uploader/Upload.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ export interface IUpload extends TypedEventTarget<UploadEvents> {
6262
*/
6363
readonly signal: AbortSignal
6464

65+
/**
66+
* The children of this upload.
67+
* - For a file upload, this will be an empty array.
68+
* - For a folder upload, this will be the uploads of the children files and folders.
69+
*/
70+
readonly children: IUpload[]
71+
6572
/**
6673
* Cancels the upload
6774
*/
@@ -82,6 +89,14 @@ export abstract class Upload extends TypedEventTarget<UploadEvents> implements P
8289
this.#abortController.abort()
8390
}
8491

92+
/**
93+
* Get the children of this upload.
94+
* For a file upload, this will be an empty array, for a folder upload, this will be the uploads of the children files and folders.
95+
*/
96+
public get children(): IUpload[] {
97+
return []
98+
}
99+
85100
/**
86101
* Start the upload
87102
*

lib/upload/uploader/UploadFileTree.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@ export class UploadFileTree extends Upload implements IUpload {
8989
return false
9090
}
9191

92+
get children(): IUpload[] {
93+
return [...this.#children]
94+
}
95+
9296
/**
9397
* Set up all child uploads for this upload tree.
9498
*/
9599
initialize(): (Upload & IUpload)[] {
100+
const grandchildren: (Upload & IUpload)[] = []
96101
for (const child of this.#directory.children) {
97102
if (child instanceof FileTree) {
98103
const upload = new UploadFileTree(
@@ -104,7 +109,8 @@ export class UploadFileTree extends Upload implements IUpload {
104109
noChunking: this.#noChunking,
105110
},
106111
)
107-
this.#children.push(upload, ...upload.initialize())
112+
this.#children.push(upload)
113+
grandchildren.push(...upload.initialize())
108114
} else {
109115
const upload = new UploadFile(
110116
join(this.source, child.name),
@@ -114,7 +120,7 @@ export class UploadFileTree extends Upload implements IUpload {
114120
this.#children.push(upload)
115121
}
116122
}
117-
return this.#children
123+
return [...this.#children, ...grandchildren]
118124
}
119125

120126
async start(queue: PQueue): Promise<void> {

0 commit comments

Comments
 (0)