Bug not fix

This commit is contained in:
Eudes Inácio
2022-03-31 11:56:49 +01:00
parent f8215163fa
commit 498f6ce5ac
72 changed files with 1663 additions and 125 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ import { CookieService } from 'ngx-cookie-service';
import { ImagePicker } from '@ionic-native/image-picker/ngx';
import { MediaCapture } from '@ionic-native/media-capture/ngx';
import { Media } from '@ionic-native/media/ngx';
import { File } from '@ionic-native/file/ngx';
import { File } from '@ionic-native/file/ngx';
import { StreamingMedia } from '@ionic-native/streaming-media/ngx';
import { PhotoViewer } from '@ionic-native/photo-viewer/ngx';
@@ -8,6 +8,7 @@ import { ViewMediaPageRoutingModule } from './view-media-routing.module';
import { ViewMediaPage } from './view-media.page';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { PdfViewerModule } from 'ng2-pdf-viewer';
@NgModule({
imports: [
@@ -16,6 +17,7 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
IonicModule,
FontAwesomeModule,
ViewMediaPageRoutingModule,
PdfViewerModule
],
declarations: [ViewMediaPage]
})
@@ -24,6 +24,11 @@
<img src="{{image}}">
</div>
<div *ngIf="type == 'application/pdf'">
<pdf-viewer [src]="image"
[render-text]="true"
[original-size]="false"
style="width: 400px; height: 500px"
></pdf-viewer>
</div>
</div>
</ion-slide>
@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';
import { DomSanitizer} from '@angular/platform-browser';
@Component({
selector: 'app-view-media',
@@ -18,9 +19,12 @@ export class ViewMediaPage implements OnInit {
maxRation: 2
};
base64Sanitize:any = "";
constructor(
private modalController: ModalController,
private navParams:NavParams,
public sanitizer: DomSanitizer,
) {
this.image = this.navParams.get('image')
this.type = this.navParams.get('type')
@@ -29,8 +33,18 @@ export class ViewMediaPage implements OnInit {
}
ngOnInit() {
console.log(this.image)
this.base64Sanitize = this.sanitizer.bypassSecurityTrustResourceUrl(eval(this.image));
console.log(this.base64Sanitize)
}
sanitizeBase64() {
return this.sanitizer.bypassSecurityTrustResourceUrl(this.image);
}
close(){
this.modalController.dismiss()
}
@@ -80,7 +80,7 @@
</div>
<div *ngIf="msg.file.type != 'application/img'">
<div class="file add-attachment-bg-color" *ngIf="msg.file.type != 'application/audio'">
<div (click)="docIndex(i); viewDocument(msg, file.title_link)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<div (click)="docIndex(i); openPreview(msg)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<span *ngIf="msg.file.type">
<fa-icon *ngIf="msg.file.type == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon>
<fa-icon *ngIf="msg.file.type == 'application/word'" icon="file-word" class="word-icon"></fa-icon>
+10 -18
View File
@@ -44,7 +44,7 @@ import { Plugins, Capacitor } from '@capacitor/core';
import { MultipleDocumentsPicker } from '@awesome-cordova-plugins/multiple-document-picker/ngx';
import { DomSanitizer} from '@angular/platform-browser';
import { StringDecoder } from 'string_decoder';
//import { File } from 'node_modules_/@ionic-native/file/ngx';
import { File } from '@ionic-native/file/ngx';
const IMAGE_DIR = 'stored-images';
@@ -133,7 +133,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
private fileToBase64Service: FileToBase64Service,
private multipleDocumentsPicker: MultipleDocumentsPicker,
private sant: DomSanitizer,
//private file: File
private file: File,
//private fileOpener: FileOpener,
private sanitiser: DomSanitizer,
) {
this.loggedUser = authService.ValidatedUserChat['data'];
@@ -740,17 +741,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
return zoneOriginalInstance || fileReader;
}
fileToBase64 = (blob,filename) => {
return new Promise(resolve => {
var file = new File([blob], filename);
var reader = this.getFileReader(); // Read file content on file loaded event
reader.onloadend = (evt) => {
console.log(evt.target.result)
resolve(evt.target.result); }; // Convert data to base64
reader.readAsDataURL(file);
} )
};
async addFileToChat(types: typeof FileType[]) {
/* this.multipleDocumentsPicker.pick(2)
@@ -1032,12 +1022,11 @@ fileToBase64 = (blob,filename) => {
} else if (event.type === HttpEventType.Response) {
if (msg.file.type == "application/img") {
this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
} else {
} else if (msg.file.type == "application/pdf") {
//console.log('TRY THIS LIBRARY ',fromByteArray(event.body));
this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '');
this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '');
//this.downloadFile = event.body
console.log(event.body)
console.log(this._arrayBufferToBase64(event.body))
console.log(this.downloadFile)
}
msg.attachments[0] = {
@@ -1070,10 +1059,13 @@ fileToBase64 = (blob,filename) => {
console.log(msg);
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
this.downloadFile(msg)
this.downloadFileMsg(msg)
//this.testDownlod(msg)
} else {
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',
+55 -44
View File
@@ -86,8 +86,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
allowTyping = true;
storedFileNames = [];
lastAudioRecorded = '';
audioRecorded:any = "";
audioDownloaded:any = "";
audioRecorded: any = "";
audioDownloaded: any = "";
durationDisplay = '';
duration = 0;
@@ -239,7 +239,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}, 1000)
}
async getFile(fileName?:any){
async getFile(fileName?: any) {
const audioFile = await Filesystem.readFile({
path: fileName,
directory: Directory.Data
@@ -257,10 +257,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
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}`);
}
});
@@ -293,8 +293,8 @@ export class MessagesPage implements OnInit, OnChanges, 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');
})
}
@@ -304,7 +304,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}, 1000);
}
async deleteRecording(){
async deleteRecording() {
this.storage.remove('fileName');
this.storage.remove('recordData');
@@ -361,17 +361,17 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.storage.get('recordData').then((recordData) => {
console.log(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}`;
}
});
//Converting base64 to blob
const base64Response = await fetch(this.audioRecorded);
const blob = await base64Response.blob();
const blob = await base64Response.blob();
const formData = new FormData();
formData.append("blobFile", blob);
@@ -380,11 +380,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
file: {
"type": "application/audio",
/* "guid": '', */
"msDuration":audioFile.value.msDuration,
"mimeType":audioFile.value.mimeType,
"msDuration": audioFile.value.msDuration,
"mimeType": audioFile.value.mimeType,
},
attachments: [{
"title": fileName ,
"title": fileName,
"title_link": this.audioRecorded,
"title_link_download": true,
"type": "audio"
@@ -395,10 +395,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
deleteMessage(msgId: string, msg:MessageService) {
deleteMessage(msgId: string, msg: MessageService) {
/* msg.delateStatusFalse()
this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId) */
/* msg.delateStatusFalse()
this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId) */
}
@@ -417,8 +417,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
else {
console.log('PDF CLICK', msg)
var str = msg.attachments[0].image_url;
str = str.substring(1,((str.length)-1));
str = str.substring(1, ((str.length) - 1));
const encodedData = btoa(str);
/* let fullUrl;
fullUrl = "https://gabinetedigitalchat.dyndns.info" + url;
@@ -443,17 +443,17 @@ export class MessagesPage implements OnInit, OnChanges, 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 openViewDocumentModal(file: any) {
@@ -772,7 +772,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const roomId = this.roomId
const file: any = await this.fileService.getFileFromDevice(types);
console.log('Add file', file)
/* const imageData = await this.fileToBase64Service.convert(file).then((filee) => {
console.log('Add file', filee)
@@ -922,7 +922,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
if (msg.file.type == "application/img") {
this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
} else if (msg.file.type === 'application/pdf') {
this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '');
//console.log(this._arrayBufferToBase64(event.body))
console.log(eval(this.downloadFile))
@@ -939,7 +939,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
// save the changes to the storage
//msg.save()
}
});
@@ -948,16 +948,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
_arrayBufferToBase64( buffer ) {
var binary = '';
var bytes = new Uint8Array( buffer );
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
}
return window.btoa( binary );
}
pdfPreview() {
const options: DocumentViewerOptions = {
title: 'My App'
@@ -970,12 +960,33 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
this.downloadFileMsg(msg)
} else if (msg.file.type === "application/pdf") {
this.viewDocument(msg, msg.attachments.image_url)
/* } else if (msg.file.type === "application/pdf") {
console.log(str);
const win = window.open("", "_blank");
let html = '';
html += '<html>';
html += '<body style="margin:0!important">';
html += '<iframe width="100%" height="100%" src="' + str + '" type="application/pdf" />';
html += '</body>';
html += '</html>';
setTimeout(() => {
win.document.write(html);
}, 0); */
//this.viewDocument(msg, msg.attachments.image_url)
} else {
var str = msg.attachments[0].image_url;
str = str.substring(1, ((str.length) - 1));
/* if(msg.file.type === "application/pdf") {
this.viewDocument(msg, msg.attachments.image_url)
} else { */
@@ -983,7 +994,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
image: msg.attachments[0].image_url,
image: str,
type: msg.file.type,
username: msg.u.name,
_updatedAt: msg._updatedAt
@@ -40,7 +40,8 @@
</ion-refresher>
<div class="main-container px-20">
<ion-content>
<ion-card *ngFor="let publication of publicationList let i = index">
<ion-card *ngFor="let publication of publicationList let i = index"
(click)="viewPublicationDetail(publication.DocumentId)">
<ion-card-content>
<div class="post-img">
<img [lazyLoad]="publication.FileBase64">