diff --git a/projects/ucap-webmessenger-api-common/src/lib/models/file-upload-item.ts b/projects/ucap-webmessenger-api-common/src/lib/models/file-upload-item.ts new file mode 100644 index 00000000..25fbbf69 --- /dev/null +++ b/projects/ucap-webmessenger-api-common/src/lib/models/file-upload-item.ts @@ -0,0 +1,38 @@ +import { Observable, Subject } from 'rxjs'; +import { share } from 'rxjs/operators'; + +export class FileUploadItem { + file: File; + uploadTime: number; + uploadingProgress$: Observable; + + private uploadingProgress: Subject; + private uploadStartTime: number; + + private constructor(file: File) { + this.file = file; + } + + static fromFiles(files: File[]): FileUploadItem[] { + const fileItems: FileUploadItem[] = []; + for (const file of files) { + fileItems.push(new FileUploadItem(file)); + } + return fileItems; + } + + uploadStart(): Subject { + this.uploadStartTime = new Date().getTime(); + this.uploadingProgress = new Subject(); + this.uploadingProgress$ = this.uploadingProgress + .asObservable() + .pipe(share()); + return this.uploadingProgress; + } + + uploadComplete() { + const endTime = new Date().getTime(); + this.uploadTime = endTime - this.uploadStartTime; + this.uploadingProgress.complete(); + } +} diff --git a/projects/ucap-webmessenger-api-common/src/public-api.ts b/projects/ucap-webmessenger-api-common/src/public-api.ts index e94b036b..351d4812 100644 --- a/projects/ucap-webmessenger-api-common/src/public-api.ts +++ b/projects/ucap-webmessenger-api-common/src/public-api.ts @@ -15,6 +15,8 @@ export * from './lib/apis/trans-mass-talk-save'; export * from './lib/apis/translation-req'; export * from './lib/apis/translation-save'; +export * from './lib/models/file-upload-item'; + export * from './lib/services/common-api.service'; export * from './lib/ucap-common-api.module';