From 8dd02b391fbc263524504494e447aeda058c3e5b Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 9 Feb 2024 11:26:33 +0100 Subject: [PATCH] new way to invoke merge --- .../services/socket-connection-mcr.service.ts | 14 ++++++++++--- .../upload/upload-streaming.service.ts | 21 +++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/app/services/socket-connection-mcr.service.ts b/src/app/services/socket-connection-mcr.service.ts index 79487258a..4dbd9ac16 100644 --- a/src/app/services/socket-connection-mcr.service.ts +++ b/src/app/services/socket-connection-mcr.service.ts @@ -5,7 +5,7 @@ import { v4 as uuidv4 } from 'uuid' import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http'; import { CMAPIService } from '../shared/repository/CMAPI/cmapi.service'; import { HubConnectionBuilder } from '@microsoft/signalr'; - +import { ok, err, Result } from 'neverthrow'; @Injectable({ providedIn: 'root' }) @@ -125,8 +125,16 @@ class ReconnectingWebSocketSignalR { }); } - commit(path) { - this.connection.invoke("CommitUpload", path).catch(err => console.error(err.toString())); + commit(path): Promise> { + return new Promise((resolve, reject) => { + this.connection.invoke("CommitUpload", path).then((e) => { + console.log("commit message", e) + resolve(ok(true)) + }).catch(err => { + resolve(err(false)) + console.error(err.toString()) + }); + }) } disconnect() { diff --git a/src/app/shared/publication/upload/upload-streaming.service.ts b/src/app/shared/publication/upload/upload-streaming.service.ts index 571dfb6b3..352e92c30 100644 --- a/src/app/shared/publication/upload/upload-streaming.service.ts +++ b/src/app/shared/publication/upload/upload-streaming.service.ts @@ -214,22 +214,11 @@ export class PublicationFormMV { if(!PublicationAttachmentEntity.hasChunkManger) { const fileBlob = PublicationAttachmentEntity.blobFile; - const fileChunks = new Chunks({chunkSize: 1024 }) + const fileChunks = new Chunks({chunkSize: 40 }) fileChunks.setFile(fileBlob) PublicationAttachmentEntity.setChunkManger(fileChunks) - PublicationAttachmentEntity.chucksManager.registerOnLastChunk(() => { - this.ObjectMergeNotification.socket.commit(PublicationAttachmentEntity.chucksManager.path) - - const guid = PublicationAttachmentEntity.chucksManager.path - - this.ObjectMergeNotification.subscribe(guid, (data) => { - PublicationAttachmentEntity - resolve(true) - }) - }) - } else if(PublicationAttachmentEntity.chucksManager.doneUpload) { return resolve(true) } @@ -250,11 +239,17 @@ export class PublicationFormMV { } while (attemp<3 && result.isErr() && result?.error == 'slow') PublicationAttachmentEntity.chucksManager.setManualRetry() - PublicationAttachmentEntity.chucksManager.doneChunkUpload() if(result.isErr()) { resolve(false) } else { + const guid = PublicationAttachmentEntity.chucksManager.path + this.ObjectMergeNotification.subscribe(guid, (data) => { + PublicationAttachmentEntity + resolve(true) + }) + PublicationAttachmentEntity.chucksManager.doneChunkUpload() + this.ObjectMergeNotification.socket.commit(PublicationAttachmentEntity.chucksManager.path) resolve(true) }