new way to invoke merge

This commit is contained in:
Peter Maquiran
2024-02-09 11:26:33 +01:00
parent c21802f30b
commit 8dd02b391f
2 changed files with 19 additions and 16 deletions
@@ -5,7 +5,7 @@ import { v4 as uuidv4 } from 'uuid'
import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http'; import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http';
import { CMAPIService } from '../shared/repository/CMAPI/cmapi.service'; import { CMAPIService } from '../shared/repository/CMAPI/cmapi.service';
import { HubConnectionBuilder } from '@microsoft/signalr'; import { HubConnectionBuilder } from '@microsoft/signalr';
import { ok, err, Result } from 'neverthrow';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@@ -125,8 +125,16 @@ class ReconnectingWebSocketSignalR {
}); });
} }
commit(path) { commit(path): Promise<Result<true, false>> {
this.connection.invoke("CommitUpload", path).catch(err => console.error(err.toString())); 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() { disconnect() {
@@ -214,22 +214,11 @@ export class PublicationFormMV {
if(!PublicationAttachmentEntity.hasChunkManger) { if(!PublicationAttachmentEntity.hasChunkManger) {
const fileBlob = PublicationAttachmentEntity.blobFile; const fileBlob = PublicationAttachmentEntity.blobFile;
const fileChunks = new Chunks({chunkSize: 1024 }) const fileChunks = new Chunks({chunkSize: 40 })
fileChunks.setFile(fileBlob) fileChunks.setFile(fileBlob)
PublicationAttachmentEntity.setChunkManger(fileChunks) 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) { } else if(PublicationAttachmentEntity.chucksManager.doneUpload) {
return resolve(true) return resolve(true)
} }
@@ -250,11 +239,17 @@ export class PublicationFormMV {
} while (attemp<3 && result.isErr() && result?.error == 'slow') } while (attemp<3 && result.isErr() && result?.error == 'slow')
PublicationAttachmentEntity.chucksManager.setManualRetry() PublicationAttachmentEntity.chucksManager.setManualRetry()
PublicationAttachmentEntity.chucksManager.doneChunkUpload()
if(result.isErr()) { if(result.isErr()) {
resolve(false) resolve(false)
} else { } 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) resolve(true)
} }