Merge branch 'feature/upload-streaming' of bitbucket.org:equilibriumito/gabinete-digital-fo into feature/upload-streaming

This commit is contained in:
Peter Maquiran
2024-01-31 17:13:40 +01:00
10 changed files with 198 additions and 178 deletions
@@ -45,7 +45,7 @@
<video *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video'" width="70" height="70"
controls="controls" preload="metadata" autoplay="autoplay" webkit-playsinline="webkit-playsinline">
<source type="video/mp4" [src]="'data:video/mp4;base64,' + seleted.FileBase64">
<source type="video/mp4" [src]="seleted.FileBase64">
</video>
@@ -252,7 +252,7 @@ export class NewPublicationPage implements OnInit {
.then(async (content) => {
this.filecontent = true;
let fileObject = {
FileBase64: 'data:video/mp4;base64,'+content.data,
FileBase64: 'data:video/mp4;base64,' + content.data,
FileExtension: 'mp4',
OriginalFileName: 'video'
}
@@ -98,6 +98,7 @@ export class PublicationsPage implements OnInit {
this.hideRefreshButton();
this.intent = window["sharedContent"]
window["refreshPublication"] = this.refreshing
}
@@ -124,7 +125,7 @@ export class PublicationsPage implements OnInit {
}
}
refreshing() {
refreshing = () => {
setTimeout(() => {
this.getActions();
}, 1500);
@@ -300,6 +301,9 @@ export class PublicationsPage implements OnInit {
const loader = this.toastService.loading();
try {
await this.publications.DeletePresidentialAction(id).toPromise();
if(window["refreshPublication"]) {
window["refreshPublication"]();
}
this.toastService._successMessage()
} catch (error) {
if(error.status == 0) {
@@ -270,6 +270,7 @@ export class ViewPublicationsPage implements OnInit {
if (!found) {
this.publicationFolderService.publicationList[folderId].push(publicationDetails)
this.publicationFolderService.revertPublicationOrder(folderId)
} else {
@@ -348,4 +349,25 @@ export class ViewPublicationsPage implements OnInit {
await modal.present();
}
getSortedPublications(): Publication[] {
const unsortedPublications = this.publicationFolderService.publicationList[this.folderId];
if (unsortedPublications) {
// Copiar a lista original para evitar alterações indesejadas
const publicationsCopy = [...unsortedPublications];
// Ordenar as publicações pelo DatePublication
publicationsCopy.sort((a, b) => {
const dateA = new Date(a.DatePublication).getTime();
const dateB = new Date(b.DatePublication).getTime();
return dateA - dateB;
});
return publicationsCopy;
} else {
return [];
}
}
}
@@ -77,7 +77,7 @@
<video *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video' && checkTableDivice() == true" width="70" height="70"
preload="metadata" webkit-playsinline="webkit-playsinline">
<source type="video/mp4" [src]="'data:video/mp4;base64,' +seleted.FileBase64">
<source type="video/mp4" [src]="seleted.FileBase64">
</video>
@@ -258,26 +258,26 @@ export class NewPublicationPage implements OnInit {
multiple: true,
});
console.log(result)
console.log(result)
result.files.forEach(async blobFile => {
console.log(blobFile)
if (this.checkFileType.checkFileType(blobFile.mimeType) == 'image' || this.checkFileType.checkFileType(blobFile.mimeType) == 'video') {
/* console.log('converte new way',this.getBase64(blobFile)) */
/* console.log('converte new way',this.getBase64(blobFile)) */
/* const blob = await fetch(
Capacitor.convertFileSrc(blobFile.path)
).then(r => r.blob()); */
/* const blob = await fetch(
Capacitor.convertFileSrc(blobFile.path)
).then(r => r.blob()); */
/* console.log(await blob.arrayBuffer());
/* console.log(await blob.arrayBuffer());
console.log("base64 :data:video/mp4;base64,",this.arrayBufferToBase64(await blob.arrayBuffer())) */
console.log("base64 :data:video/mp4;base64,",this.arrayBufferToBase64(await blob.arrayBuffer())) */
this.convertBlobToBase64(blobFile.blob).then((value) => {
console.log(value)
console.log(this.removeTextBeforeSlash(value, ','))
this.filesSizeSum = this.filesSizeSum + blobFile.size
if (this.fileSizeToMB(this.filesSizeSum) <= 20) {
@@ -288,7 +288,7 @@ export class NewPublicationPage implements OnInit {
const newAttachment = new PublicationAttachmentEntity(
{
base64: value,
base64: this.removeTextBeforeSlash(value, ','),
extension: FileExtension,
blobFile: file,
FileType: this.checkFileType.checkFileType(FileExtension)
@@ -315,7 +315,7 @@ export class NewPublicationPage implements OnInit {
});
/* this.capturedImage = 'data:image/jpeg;base64,' +capturedImage.base64String;
@@ -347,7 +347,7 @@ export class NewPublicationPage implements OnInit {
({
multiple: true,
});
console.log(result.files)
console.log(result.files)
result.files.forEach(element => {
this.filesSizeSum = this.filesSizeSum + element.size
@@ -359,15 +359,16 @@ export class NewPublicationPage implements OnInit {
.then(async (content) => {
console.log(result)
console.log('load video tablet base64',content)
console.log('load video tablet base64', content)
this.filecontent = true;
let fileObject = new PublicationAttachmentEntity ({
let fileObject = new PublicationAttachmentEntity({
base64: content.data,
extension: this.removeTextBeforeSlash(element.mimeType, '/'),
OriginalFileName: 'video',
FileType: this.checkFileType.checkFileType( this.removeTextBeforeSlash(element.mimeType, '/'))
FileType: this.checkFileType.checkFileType(this.removeTextBeforeSlash(element.mimeType, '/'))
})
this.seletedContent.push(fileObject)
console.log('Files array',this.seletedContent)
})
.catch((err) => console.error(err));
} catch (error) {
@@ -607,17 +608,59 @@ export class NewPublicationPage implements OnInit {
}
convertBlobToBase64(blob: Blob) {
console.log('Convert blob ',blob)
return new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result)
}
reader.readAsDataURL(blob)
},)
try {
return new Promise((resolve, reject) => {
const chunkSize = 5000000; // 5 MB
const fileSize = blob.size;
const chunks = Math.ceil(fileSize / chunkSize);
let currentChunk = 0;
const base64Chunks = [];
const reader = new FileReader();
reader.onload = function () {
base64Chunks.push(reader.result);
currentChunk++;
if (currentChunk < chunks) {
loadNextChunk();
} else {
const base64Data = base64Chunks.join("");
resolve(base64Data);
}
};
reader.onerror = function (error) {
reject(error);
};
function loadNextChunk() {
const start = currentChunk * chunkSize;
const end = Math.min(start + chunkSize, fileSize);
const chunk = blob.slice(start, end);
reader.readAsDataURL(chunk);
}
loadNextChunk();
});
} catch (error) {
console.log(error);
}
}
/* convertBlobToBase64(blob: Blob) {
console.log('Convert blob ',blob)
return new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result)
}
reader.readAsDataURL(blob)
},)
} */
getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
@@ -625,7 +668,7 @@ export class NewPublicationPage implements OnInit {
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
}
}
removeTextBeforeSlash(inputString, mark) {
if (inputString.includes(mark)) {
@@ -1002,7 +1045,7 @@ export class NewPublicationPage implements OnInit {
.then(async (content) => {
this.filecontent = true;
console.log('',content)
console.log('', content)
let fileObject = new PublicationAttachmentEntity({
base64: content.data,
extension: 'mp4',
@@ -1028,7 +1071,7 @@ export class NewPublicationPage implements OnInit {
}
checkTableDivice() {
if (!this.platform.is('desktop'))
if (this.platform.is('tablet'))
return true;
}
@@ -225,6 +225,7 @@ export class ViewPublicationsPage implements OnInit {
if (!found) {
this.publicationFolderService.publicationList[folderId].push(publicationDetails)
this.publicationFolderService.revertPublicationOrder(folderId)
} else {
let a: any = Object.assign({},this.publicationFolderService.publicationList[folderId][findIndex])
+47 -30
View File
@@ -10,8 +10,8 @@ import { PublicationPipe } from 'src/app/pipes/publication.pipe';
})
export class PublicationFolderService {
publicationList: {[key: string]: Publication[] } = {};
FolderDetails: {[key: string]: PublicationFolder } = {};
publicationList: { [key: string]: Publication[] } = {};
FolderDetails: { [key: string]: PublicationFolder } = {};
restoreFolder: {} = {}
@@ -25,14 +25,14 @@ export class PublicationFolderService {
constructor(
private storage: Storage,
private publications: PublicationsService,
) {}
) { }
createPublicationList(folderId) {
if(!this.publicationList[folderId]) {
if (!this.publicationList[folderId]) {
this.publicationList[folderId] = []
}
if(!this.FolderDetails[folderId]) {
if (!this.FolderDetails[folderId]) {
this.FolderDetails[folderId] = new PublicationFolder();
}
}
@@ -40,13 +40,13 @@ export class PublicationFolderService {
getFromDB(folderId: any) {
if(!this.restoreFolder[folderId]) {
if (!this.restoreFolder[folderId]) {
this.storage.get(folderId).then((viewPublications) => {
this.publicationList[folderId] = viewPublications
})
this.storage.get(folderId+"name").then((viewPublications) => {
this.storage.get(folderId + "name").then((viewPublications) => {
this.FolderDetails[folderId] = viewPublications
})
}
@@ -56,29 +56,30 @@ export class PublicationFolderService {
updateFolderDetails(folderId, res) {
this.FolderDetails[folderId] = res
this.storage.set(folderId+"name", res)
this.storage.set(folderId + "name", res)
}
save(folderId) {
this.storage.set(folderId+"name", this.FolderDetails)
this.storage.set(folderId + "name", this.FolderDetails)
this.storage.set(folderId, this.publicationList[folderId]);
}
publicationIsPresent(publicationId, folderId) {
return this.publicationList[folderId].find( e => e.DocumentId == publicationId )
return this.publicationList[folderId].find(e => e.DocumentId == publicationId)
}
publicationFind(publicationId, folderId) {
return this.publicationList[folderId].find( e => e.DocumentId == publicationId )
return this.publicationList[folderId].find(e => e.DocumentId == publicationId)
}
publicationFindIndex(publicationId, folderId) {
return this.publicationList[folderId].findIndex( e => e.DocumentId == publicationId )
return this.publicationList[folderId].findIndex(e => e.DocumentId == publicationId)
}
PublicationAddOrUpdate(folderId, publicationId, Publication: Publication) {
const findIndex = this.publicationFindIndex(publicationId, folderId)
const found = this.publicationIsPresent(publicationId, folderId)
if(!found) {
if (!found) {
this.publicationList[folderId].push(Publication)
this.revertPublicationOrder(folderId);
} else {
this.publicationList[folderId][findIndex] = Publication
}
@@ -86,9 +87,9 @@ export class PublicationFolderService {
deletePost(folderId: any, DocumentId: any) {
if(this.publicationList[folderId]) {
if (this.publicationList[folderId]) {
this.publicationList[folderId] = this.publicationList[folderId].filter( e => e.DocumentId != DocumentId)
this.publicationList[folderId] = this.publicationList[folderId].filter(e => e.DocumentId != DocumentId)
this.save(folderId)
}
@@ -99,7 +100,7 @@ export class PublicationFolderService {
this.publications.GetPresidentialAction(folderId).subscribe(res => {
this.FolderDetails[folderId] = res
this.storage.set(folderId+"name", res)
this.storage.set(folderId + "name", res)
}, (error) => {
this.showLoader = false;
// this.httpErroHandle.httpStatusHandle(error)
@@ -118,7 +119,7 @@ export class PublicationFolderService {
let loadLater = []
for (let publicationId of publicationIds) {
if(!this.publicationIsPresent(publicationId, folderId)) {
if (!this.publicationIsPresent(publicationId, folderId)) {
await this.loadPublication(publicationId, folderId)
} else {
@@ -126,7 +127,7 @@ export class PublicationFolderService {
}
}
for( let publicationId of loadLater) {
for (let publicationId of loadLater) {
await this.loadPublication(publicationId, folderId)
}
@@ -134,7 +135,7 @@ export class PublicationFolderService {
this.storage.set(folderId, this.publicationList[folderId]);
this.getpublication = this.publicationList[folderId];
} catch(error) {
} catch (error) {
this.showLoader = false;
}
@@ -147,17 +148,18 @@ export class PublicationFolderService {
const findIndex = this.publicationFindIndex(publicationId, folderId)
const found = this.publicationIsPresent(publicationId, folderId)
if(!found) {
if (!found) {
this.publicationList[folderId].push(publicationDetails)
this.revertPublicationOrder(folderId);
} else {
let a: any = Object.assign({},this.publicationList[folderId][findIndex])
let a: any = Object.assign({}, this.publicationList[folderId][findIndex])
let b: any = Object.assign({}, publicationDetails)
a.Files = a.Files.length
b.Files = b.Files.length
if(JSON.stringify(a) != JSON.stringify(b)) {
if (JSON.stringify(a) != JSON.stringify(b)) {
// console.log({a, b})
this.publicationList[folderId][findIndex] = publicationDetails
@@ -171,9 +173,10 @@ export class PublicationFolderService {
async CreatePublication(folderId, publication: Publication) {
const response = await this.publications.CreatePublication(folderId, publication).toPromise()
const response = await this.publications.CreatePublication(folderId, publication).toPromise()
let publicationDetails: Publication = this.publicationPipe.itemList(response)
this.publicationList[folderId].push(publicationDetails)
this.revertPublicationOrder(folderId)
return publicationDetails
}
@@ -182,8 +185,9 @@ export class PublicationFolderService {
const findIndex = this.publicationFindIndex(publicationId, folderId)
const found = this.publicationIsPresent(publicationId, folderId)
if(!found) {
if (!found) {
this.publicationList[folderId].push(publicationDetails)
this.revertPublicationOrder(folderId)
} else {
this.publicationList[folderId][findIndex] = publicationDetails
}
@@ -196,8 +200,10 @@ export class PublicationFolderService {
const findIndex = this.publicationFindIndex(publicationId, folderId)
const found = this.publicationIsPresent(publicationId, folderId)
if(!found) {
if (!found) {
this.publicationList[folderId].push(publicationDetails)
this.revertPublicationOrder(folderId);
} else {
return this.publicationList[folderId][findIndex]
}
@@ -205,10 +211,10 @@ export class PublicationFolderService {
}
getLocalPublication (folderId, DocumentId) {
getLocalPublication(folderId, DocumentId) {
if(this.publicationList[folderId]) {
return this.publicationList[folderId].find( e => e.DocumentId == DocumentId )
if (this.publicationList[folderId]) {
return this.publicationList[folderId].find(e => e.DocumentId == DocumentId)
} else {
}
@@ -217,11 +223,22 @@ export class PublicationFolderService {
PublicationHasImage(Publication: Publication) {
return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null"
return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null"
}
hasCapturedImage(Publication: Publication) {
return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null"
return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null"
}
revertPublicationOrder(folderId) {
//Revert order of the list
if (this.publicationList[folderId]) {
this.publicationList[folderId] = this.publicationList[folderId].sort((a, b) => {
const dateA = new Date(a.DatePublication).getTime();
const dateB = new Date(b.DatePublication).getTime();
return dateB - dateA; // Revertendo a ordem aqui
})
}
}
}