mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
packed installed
This commit is contained in:
@@ -42,9 +42,10 @@ import { FileToBase64Service } from 'src/app/services/file/file-to-base64.servic
|
||||
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
|
||||
import { Plugins, Capacitor } from '@capacitor/core';
|
||||
import { MultipleDocumentsPicker } from '@awesome-cordova-plugins/multiple-document-picker/ngx';
|
||||
import { DomSanitizer} from '@angular/platform-browser';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { StringDecoder } from 'string_decoder';
|
||||
import { File } from '@ionic-native/file/ngx';
|
||||
import { File } from '@awesome-cordova-plugins/file/ngx';
|
||||
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
|
||||
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@@ -91,8 +92,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
allowTyping = true;
|
||||
storedFileNames = [];
|
||||
lastAudioRecorded = '';
|
||||
audioRecorded:any = "";
|
||||
audioDownloaded:any = "";
|
||||
audioRecorded: any = "";
|
||||
audioDownloaded: any = "";
|
||||
durationDisplay = '';
|
||||
duration = 0;
|
||||
@ViewChild('recordbtn', { read: ElementRef }) recordBtn: ElementRef;
|
||||
@@ -103,7 +104,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
@ViewChild('filechooser') fileChooserElementRef: ElementRef;
|
||||
//items: File[] = [];
|
||||
fileSelected?: Blob;
|
||||
pdfUrl?:string;
|
||||
pdfUrl?: string;
|
||||
base64File: string;
|
||||
downloadProgess: number;
|
||||
|
||||
@@ -134,7 +135,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
private multipleDocumentsPicker: MultipleDocumentsPicker,
|
||||
private sant: DomSanitizer,
|
||||
private file: File,
|
||||
//private fileOpener: FileOpener,
|
||||
private fileOpener: FileOpener,
|
||||
private sanitiser: DomSanitizer,
|
||||
) {
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
@@ -222,16 +223,16 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
try {
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
if(recordData?.value?.recordDataBase64.includes('data:audio')){
|
||||
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
|
||||
}
|
||||
});
|
||||
} catch (error) {}
|
||||
} catch (error) { }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
startRecording() {
|
||||
@@ -242,8 +243,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
this.recording = true;
|
||||
VoiceRecorder.startRecording()
|
||||
.then((result: GenericResponse) => console.log(result.value))
|
||||
.catch(error => console.log(error));
|
||||
.then((result: GenericResponse) => console.log(result.value))
|
||||
.catch(error => console.log(error));
|
||||
this.calculateDuration();
|
||||
}
|
||||
|
||||
@@ -263,8 +264,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
//console.log(recordData);
|
||||
const fileName = new Date().getTime() + ".mp3";
|
||||
//Save file
|
||||
this.storage.set('fileName',fileName);
|
||||
this.storage.set('recordData',result).then(() => {
|
||||
this.storage.set('fileName', fileName);
|
||||
this.storage.set('recordData', result).then(() => {
|
||||
console.log('Audio recorded saved');
|
||||
})
|
||||
}
|
||||
@@ -274,7 +275,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async deleteRecording(){
|
||||
async deleteRecording() {
|
||||
this.storage.remove('fileName');
|
||||
this.storage.remove('recordData');
|
||||
|
||||
@@ -393,17 +394,17 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
var byteArrays = new Array(slicesCount);
|
||||
|
||||
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
|
||||
var begin = sliceIndex * sliceSize;
|
||||
var end = Math.min(begin + sliceSize, bytesLength);
|
||||
var begin = sliceIndex * sliceSize;
|
||||
var end = Math.min(begin + sliceSize, bytesLength);
|
||||
|
||||
var bytes = new Array(end - begin);
|
||||
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
|
||||
bytes[i] = byteCharacters[offset].charCodeAt(0);
|
||||
}
|
||||
byteArrays[sliceIndex] = new Uint8Array(bytes);
|
||||
var bytes = new Array(end - begin);
|
||||
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
|
||||
bytes[i] = byteCharacters[offset].charCodeAt(0);
|
||||
}
|
||||
byteArrays[sliceIndex] = new Uint8Array(bytes);
|
||||
}
|
||||
return new Blob(byteArrays, { type: contentType });
|
||||
}
|
||||
}
|
||||
|
||||
async sendAudio(fileName) {
|
||||
const roomId = this.roomId
|
||||
@@ -411,37 +412,37 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
|
||||
audioFile = recordData;
|
||||
if(recordData?.value?.recordDataBase64.includes('data:audio')){
|
||||
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
|
||||
this.audioRecorded = recordData?.value?.recordDataBase64;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`;
|
||||
}
|
||||
|
||||
console.log(this.audioRecorded);
|
||||
|
||||
//Converting base64 to blob
|
||||
const encodedData = btoa(this.audioRecorded);
|
||||
const blob = this.base64toBlob(encodedData, recordData.value.mimeType)
|
||||
console.log(blob)
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
//Converting base64 to blob
|
||||
const encodedData = btoa(this.audioRecorded);
|
||||
const blob = this.base64toBlob(encodedData, recordData.value.mimeType)
|
||||
console.log(blob)
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
|
||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": "application/audio",
|
||||
"msDuration":audioFile.value.msDuration,
|
||||
"mimeType":audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName ,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": "application/audio",
|
||||
"msDuration": audioFile.value.msDuration,
|
||||
"mimeType": audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
});
|
||||
});
|
||||
this.deleteRecording();
|
||||
}
|
||||
|
||||
@@ -767,63 +768,63 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
const fileReader = new FileReader();
|
||||
const zoneOriginalInstance = (fileReader as any)["__zone_symbol__originalInstance"];
|
||||
return zoneOriginalInstance || fileReader;
|
||||
}
|
||||
}
|
||||
|
||||
async addFileToChat(types: typeof FileType[]) {
|
||||
|
||||
/* this.multipleDocumentsPicker.pick(2)
|
||||
.then(async (res: any) => {
|
||||
this.files = JSON.parse(res)
|
||||
console.log('1 Add file', this.files[0].uri)
|
||||
console.log('1 Add file', JSON.stringify(this.files[0].uri))
|
||||
|
||||
|
||||
/* this.multipleDocumentsPicker.pick(2)
|
||||
.then(async (res: any) => {
|
||||
this.files = JSON.parse(res)
|
||||
console.log('1 Add file', this.files[0].uri)
|
||||
console.log('1 Add file', JSON.stringify(this.files[0].uri))
|
||||
|
||||
|
||||
|
||||
const downloadPath = (
|
||||
this.platform.is('android')
|
||||
) ? this.file.externalDataDirectory : this.file.documentsDirectory;
|
||||
const downloadPath = (
|
||||
this.platform.is('android')
|
||||
) ? this.file.externalDataDirectory : this.file.documentsDirectory;
|
||||
|
||||
this.file.writeFile(downloadPath, 'YHaaa2.pdf', 'Eudes Inácio').then((fil)=> {
|
||||
console.log('write file', fil)
|
||||
})
|
||||
|
||||
|
||||
this.fileToBase64('GS_FOLHETO_AUTOMOVEL_AC.pdf',this.files[0].uri).then(
|
||||
(data) => console.log(data)
|
||||
);
|
||||
|
||||
|
||||
const blob = new Blob([res])
|
||||
console.log('Add Blob file', blob)
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
console.log(formData)
|
||||
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).send({
|
||||
file: {
|
||||
"type": 'application/pdf',
|
||||
"guid": '',
|
||||
},
|
||||
attachments: [{
|
||||
"title": 'pdf1',
|
||||
"name": 'pdf1',
|
||||
// "text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
})
|
||||
.catch((error: any) => console.error(error)); */
|
||||
this.file.writeFile(downloadPath, 'YHaaa2.pdf', 'Eudes Inácio').then((fil)=> {
|
||||
console.log('write file', fil)
|
||||
})
|
||||
|
||||
|
||||
this.fileToBase64('GS_FOLHETO_AUTOMOVEL_AC.pdf',this.files[0].uri).then(
|
||||
(data) => console.log(data)
|
||||
);
|
||||
|
||||
|
||||
const blob = new Blob([res])
|
||||
console.log('Add Blob file', blob)
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
console.log(formData)
|
||||
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).send({
|
||||
file: {
|
||||
"type": 'application/pdf',
|
||||
"guid": '',
|
||||
},
|
||||
attachments: [{
|
||||
"title": 'pdf1',
|
||||
"name": 'pdf1',
|
||||
// "text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
})
|
||||
.catch((error: any) => console.error(error)); */
|
||||
|
||||
const roomId = this.roomId
|
||||
const roomId = this.roomId
|
||||
|
||||
const file: any = await this.fileService.getFileFromDevice(types);
|
||||
|
||||
|
||||
console.log('Add file', JSON.stringify(await this.getBase64(file)))
|
||||
|
||||
const encodedData = btoa(JSON.stringify( await this.getBase64(file)));
|
||||
const blob = this.base64toBlob(encodedData, 'application/pdf')
|
||||
const encodedData = btoa(JSON.stringify(await this.getBase64(file)));
|
||||
const blob = this.base64toBlob(encodedData, 'application/pdf')
|
||||
console.log('Add Blob file', blob)
|
||||
//console.log('Add Blob file', await this.blobToBase64(blob))
|
||||
//console.log('Add Blob file', await this.fileToByteArray(file))
|
||||
@@ -846,7 +847,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formData
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -863,26 +864,26 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
console.log('Error: ', error);
|
||||
};
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileToByteArray(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
let reader = this.getFileReader();
|
||||
//var file = new File([filepath], filename);
|
||||
reader.readAsBinaryString(file);
|
||||
reader.onloadend = (evt) => {
|
||||
console.log(evt.target.result)
|
||||
resolve(evt.target.result); // Convert data to base64
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
try {
|
||||
let reader = this.getFileReader();
|
||||
//var file = new File([filepath], filename);
|
||||
reader.readAsBinaryString(file);
|
||||
reader.onloadend = (evt) => {
|
||||
console.log(evt.target.result)
|
||||
resolve(evt.target.result); // Convert data to base64
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
blobToBase64 = blob => {
|
||||
const reader = this.getFileReader();
|
||||
@@ -1008,10 +1009,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
}
|
||||
|
||||
/* testeDownload(msg: MessageService) {
|
||||
this.downloadFile = "";
|
||||
this.AttachmentsService.downloadFileAndStore(msg.file.guid);
|
||||
} */
|
||||
/* testeDownload(msg: MessageService) {
|
||||
this.downloadFile = "";
|
||||
this.AttachmentsService.downloadFileAndStore(msg.file.guid);
|
||||
} */
|
||||
|
||||
|
||||
downloadFileMsg(msg: MessageService) {
|
||||
@@ -1062,6 +1063,46 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
return window.btoa(binary);
|
||||
}
|
||||
|
||||
b64toBlob(b64Data, contentType, sliceSize) {
|
||||
contentType = contentType || '';
|
||||
sliceSize = sliceSize || 512;
|
||||
var byteCharacters = atob(b64Data);
|
||||
var byteArrays = [];
|
||||
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
||||
var slice = byteCharacters.slice(offset, offset + sliceSize);
|
||||
var byteNumbers = new Array(slice.length);
|
||||
for (var i = 0; i < slice.length; i++) {
|
||||
byteNumbers[i] = slice.charCodeAt(i);
|
||||
}
|
||||
var byteArray = new Uint8Array(byteNumbers);
|
||||
byteArrays.push(byteArray);
|
||||
}
|
||||
var blob = new Blob(byteArrays, { type: contentType });
|
||||
return blob;
|
||||
}
|
||||
|
||||
getUserDataSheet(pdfString) {
|
||||
const blob = this.b64toBlob(pdfString, 'application/pdf', 512)
|
||||
let pathFile = ''
|
||||
const fileName = 'myPdf.pdf'
|
||||
const contentFile = blob
|
||||
if (this.platform.is('ios')) {
|
||||
pathFile = this.file.documentsDirectory
|
||||
} else {
|
||||
pathFile = this.file.externalRootDirectory
|
||||
}
|
||||
this.file
|
||||
.writeFile(pathFile, fileName, contentFile, { replace: true })
|
||||
.then(success => {
|
||||
this.fileOpener
|
||||
.open(pathFile + fileName, 'application/pdf')
|
||||
.then(() => console.log('File is opened'))
|
||||
.catch(e => console.log('Error opening file', e));
|
||||
})
|
||||
.catch(e => console.log('Error writing file', e))
|
||||
}
|
||||
|
||||
|
||||
async openPreview(msg) {
|
||||
console.log(msg);
|
||||
|
||||
@@ -1070,20 +1111,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
//this.testDownlod(msg)
|
||||
|
||||
} else {
|
||||
/* var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1)); */
|
||||
var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1));
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewMediaPage,
|
||||
cssClass: 'modal modal-desktop',
|
||||
componentProps: {
|
||||
image: msg.attachments[0].image_url,
|
||||
type: msg.file.type,
|
||||
username: msg.u.name,
|
||||
_updatedAt: msg._updatedAt
|
||||
}
|
||||
});
|
||||
modal.present();
|
||||
this.getUserDataSheet(str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1092,7 +1123,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
console.log(msg);
|
||||
if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
} else {}
|
||||
} else { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user