mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
file upload
This commit is contained in:
@@ -458,7 +458,8 @@ export class NewPublicationPage implements OnInit {
|
||||
if(upload) {
|
||||
this.publication.Files = this.publication.Files.map((e:PublicationAttachmentEntity)=> {
|
||||
if(e.FileType == 'video') {
|
||||
e.FileBase64 = environment.apiURL + "/ObjectServer/StreamFiles?path="+ e.chucksManager.path
|
||||
e.OriginalFileName = e.chucksManager.path
|
||||
e.FileExtension = "mp4"
|
||||
}
|
||||
|
||||
return e
|
||||
@@ -520,7 +521,8 @@ export class NewPublicationPage implements OnInit {
|
||||
if(upload) {
|
||||
this.publication.Files = this.publication.Files.map((e:PublicationAttachmentEntity)=> {
|
||||
if(e.FileType == 'video') {
|
||||
e.FileBase64 = environment.apiURL + "/ObjectServer/StreamFiles?path="+ e.chucksManager.path
|
||||
e.OriginalFileName = e.chucksManager.path
|
||||
e.FileExtension = "mp4"
|
||||
}
|
||||
|
||||
return e
|
||||
@@ -1076,6 +1078,7 @@ class UploadFileUseCase {
|
||||
async execute(PublicationAttachmentEntity: PublicationAttachmentEntity): Promise<Result<PublicationAttachmentEntity, PublicationAttachmentEntity>> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
PublicationAttachmentEntity.chucksManager.clearManualRetry()
|
||||
|
||||
let path: string;
|
||||
const length = PublicationAttachmentEntity.chucksManager.chunks.totalChunks.toString()
|
||||
@@ -1086,7 +1089,7 @@ class UploadFileUseCase {
|
||||
const blob = new Blob([chunk]);
|
||||
const blobFile = new File([blob], "test.mp4", { type: blob.type });
|
||||
|
||||
return await this.CMAPIService.FileContent({length, path: PublicationAttachmentEntity.chucksManager.path, index, blobFile})
|
||||
return this.CMAPIService.FileContent({length, path: PublicationAttachmentEntity.chucksManager.path, index, blobFile})
|
||||
}
|
||||
|
||||
if(!PublicationAttachmentEntity.chucksManager.hasPath()) {
|
||||
@@ -1101,13 +1104,15 @@ class UploadFileUseCase {
|
||||
PublicationAttachmentEntity.chucksManager.setPath(path)
|
||||
PublicationAttachmentEntity.chucksManager.setResponse(initIndex, uploadRequest)
|
||||
} else {
|
||||
reject(err(PublicationAttachmentEntity))
|
||||
PublicationAttachmentEntity.chucksManager.setManualRetry()
|
||||
return reject(err(PublicationAttachmentEntity))
|
||||
}
|
||||
}
|
||||
|
||||
const allRequest: Promise<any>[] = []
|
||||
let connection = true
|
||||
|
||||
for (let index = 2; index <= PublicationAttachmentEntity.chucksManager.chunks.totalChunks -1; index++) {
|
||||
for (let index = 2; ( (index <= PublicationAttachmentEntity.chucksManager.chunks.totalChunks -1) && connection ); index++) {
|
||||
const needUpload = PublicationAttachmentEntity.chucksManager.needToUploadChunkIndex(index)
|
||||
|
||||
if(needUpload) {
|
||||
@@ -1116,7 +1121,9 @@ class UploadFileUseCase {
|
||||
if(uploadRequest.isErr()) {
|
||||
const pingRequest = await this.CMAPIService.ping()
|
||||
if( pingRequest.isErr()) {
|
||||
reject(err(PublicationAttachmentEntity))
|
||||
connection = false
|
||||
PublicationAttachmentEntity.chucksManager.setManualRetry()
|
||||
return reject(err(PublicationAttachmentEntity))
|
||||
}
|
||||
} else {
|
||||
PublicationAttachmentEntity.chucksManager.setResponse(index, uploadRequest)
|
||||
@@ -1139,20 +1146,28 @@ class UploadFileUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(allRequest)
|
||||
|
||||
const uploadRequest = await readAndUploadChunk(PublicationAttachmentEntity.chucksManager.chunks.totalChunks)
|
||||
if(uploadRequest.isErr()) {
|
||||
const pingRequest = await this.CMAPIService.ping()
|
||||
if( pingRequest.isErr()) {
|
||||
reject(err(PublicationAttachmentEntity))
|
||||
}
|
||||
if(!connection) {
|
||||
PublicationAttachmentEntity.chucksManager.setManualRetry()
|
||||
return reject(err(PublicationAttachmentEntity))
|
||||
} else {
|
||||
PublicationAttachmentEntity.chucksManager.setResponse(PublicationAttachmentEntity.chucksManager.chunks.totalChunks, uploadRequest)
|
||||
await Promise.all(allRequest)
|
||||
|
||||
const uploadRequest = await readAndUploadChunk(PublicationAttachmentEntity.chucksManager.chunks.totalChunks)
|
||||
if(uploadRequest.isErr()) {
|
||||
const pingRequest = await this.CMAPIService.ping()
|
||||
if( pingRequest.isErr()) {
|
||||
PublicationAttachmentEntity.chucksManager.setManualRetry()
|
||||
return reject(err(PublicationAttachmentEntity))
|
||||
}
|
||||
} else {
|
||||
PublicationAttachmentEntity.chucksManager.setResponse(PublicationAttachmentEntity.chucksManager.chunks.totalChunks, uploadRequest)
|
||||
}
|
||||
|
||||
PublicationAttachmentEntity.chucksManager.doneChunkUpload()
|
||||
resolve(ok(PublicationAttachmentEntity))
|
||||
}
|
||||
|
||||
PublicationAttachmentEntity.chucksManager.doneChunkUpload()
|
||||
resolve(ok(PublicationAttachmentEntity))
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1386,6 +1401,7 @@ class ChucksManager {
|
||||
onSetPath: Function[] = []
|
||||
onSetLastChunk: Function[] = []
|
||||
contentReady = false
|
||||
manualRetry = false
|
||||
|
||||
getUploadPercentage() {
|
||||
return this.uploadPercentage
|
||||
@@ -1428,6 +1444,14 @@ class ChucksManager {
|
||||
return percentage;
|
||||
}
|
||||
|
||||
setManualRetry() {
|
||||
this.manualRetry = true
|
||||
}
|
||||
|
||||
clearManualRetry() {
|
||||
this.manualRetry = false
|
||||
}
|
||||
|
||||
setPercentage() {
|
||||
const percentage: number = this.calculatePercentage()
|
||||
console.log({percentage})
|
||||
|
||||
Reference in New Issue
Block a user