|
@@ -1,6 +1,7 @@
|
|
import joinPath, { pathAndName, trailingSlash } from './joinPath';
|
|
import joinPath, { pathAndName, trailingSlash } from './joinPath';
|
|
import Collection from './Collection';
|
|
import Collection from './Collection';
|
|
import EventEmitter from '@dom111/typed-event-emitter/EventEmitter';
|
|
import EventEmitter from '@dom111/typed-event-emitter/EventEmitter';
|
|
|
|
+import { t } from 'i18next';
|
|
|
|
|
|
type EntryArgs = {
|
|
type EntryArgs = {
|
|
copy?: boolean;
|
|
copy?: boolean;
|
|
@@ -14,6 +15,7 @@ type EntryArgs = {
|
|
del?: boolean;
|
|
del?: boolean;
|
|
rename?: boolean;
|
|
rename?: boolean;
|
|
placeholder?: boolean;
|
|
placeholder?: boolean;
|
|
|
|
+ uploaded?: number;
|
|
collection?: Collection | null;
|
|
collection?: Collection | null;
|
|
};
|
|
};
|
|
|
|
|
|
@@ -21,6 +23,23 @@ type EntryEvents = {
|
|
updated: [];
|
|
updated: [];
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+function sizeToDisplaySize(size: number): string {
|
|
|
|
+ return ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'].reduce(
|
|
|
|
+ (size: string | number, label) => {
|
|
|
|
+ if (typeof size === 'string') {
|
|
|
|
+ return size;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (size < 1024) {
|
|
|
|
+ return `${size.toFixed(2 * (label === 'bytes' ? 0 : 1))} ${label}`;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return size / 1024;
|
|
|
|
+ },
|
|
|
|
+ size
|
|
|
|
+ ) as string;
|
|
|
|
+}
|
|
|
|
+
|
|
export default class Entry extends EventEmitter<EntryEvents> {
|
|
export default class Entry extends EventEmitter<EntryEvents> {
|
|
#copy: boolean;
|
|
#copy: boolean;
|
|
#del: boolean;
|
|
#del: boolean;
|
|
@@ -34,6 +53,7 @@ export default class Entry extends EventEmitter<EntryEvents> {
|
|
#name: string;
|
|
#name: string;
|
|
#path: string;
|
|
#path: string;
|
|
#placeholder: boolean;
|
|
#placeholder: boolean;
|
|
|
|
+ #uploaded: number;
|
|
#rename: boolean;
|
|
#rename: boolean;
|
|
#size: number;
|
|
#size: number;
|
|
#title: string;
|
|
#title: string;
|
|
@@ -51,6 +71,7 @@ export default class Entry extends EventEmitter<EntryEvents> {
|
|
modified,
|
|
modified,
|
|
move = true,
|
|
move = true,
|
|
placeholder = false,
|
|
placeholder = false,
|
|
|
|
+ uploaded = 0,
|
|
rename = true,
|
|
rename = true,
|
|
size = 0,
|
|
size = 0,
|
|
title = '',
|
|
title = '',
|
|
@@ -75,6 +96,7 @@ export default class Entry extends EventEmitter<EntryEvents> {
|
|
this.#del = del;
|
|
this.#del = del;
|
|
this.#rename = rename;
|
|
this.#rename = rename;
|
|
this.#placeholder = placeholder;
|
|
this.#placeholder = placeholder;
|
|
|
|
+ this.#uploaded = uploaded;
|
|
this.collection = collection;
|
|
this.collection = collection;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -131,20 +153,17 @@ export default class Entry extends EventEmitter<EntryEvents> {
|
|
}
|
|
}
|
|
|
|
|
|
if (!this.#displaySize) {
|
|
if (!this.#displaySize) {
|
|
- this.#displaySize = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'].reduce(
|
|
|
|
- (size: string | number, label) => {
|
|
|
|
- if (typeof size === 'string') {
|
|
|
|
- return size;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (size < 1024) {
|
|
|
|
- return `${size.toFixed(2 * (label === 'bytes' ? 0 : 1))} ${label}`;
|
|
|
|
- }
|
|
|
|
|
|
+ this.#displaySize = sizeToDisplaySize(this.#size);
|
|
|
|
+ }
|
|
|
|
|
|
- return size / 1024;
|
|
|
|
|
|
+ if (this.placeholder) {
|
|
|
|
+ return t('uploadProgress', {
|
|
|
|
+ interpolation: {
|
|
|
|
+ escapeValue: false,
|
|
},
|
|
},
|
|
- this.#size
|
|
|
|
- ) as string;
|
|
|
|
|
|
+ uploaded: sizeToDisplaySize(this.#uploaded),
|
|
|
|
+ total: this.#displaySize,
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
return this.#displaySize;
|
|
return this.#displaySize;
|
|
@@ -211,6 +230,14 @@ export default class Entry extends EventEmitter<EntryEvents> {
|
|
this.#placeholder = value;
|
|
this.#placeholder = value;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ get uploaded(): number {
|
|
|
|
+ return this.#uploaded;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ set uploaded(value: number) {
|
|
|
|
+ this.#uploaded = value;
|
|
|
|
+ }
|
|
|
|
+
|
|
get rename(): boolean {
|
|
get rename(): boolean {
|
|
return this.#rename;
|
|
return this.#rename;
|
|
}
|
|
}
|