mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
send every type of file its possible now
This commit is contained in:
@@ -677,6 +677,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
"DocId": res.data.selected.Id,
|
||||
"Assunto": res.data.selected.Assunto,
|
||||
},
|
||||
temporaryData: res,
|
||||
attachments: [{
|
||||
"title": res.data.selected.Assunto,
|
||||
"description": res.data.selected.DocTypeDesc,
|
||||
@@ -704,10 +705,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
console.log('Add file', JSON.stringify(await this.getBase64(file)))
|
||||
|
||||
if (file.type == "application/pdf") {
|
||||
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
|
||||
|
||||
const encodedData = btoa(JSON.stringify(await this.getBase64(file)));
|
||||
const blob = this.base64toBlob(encodedData, 'application/pdf')
|
||||
const blob = this.base64toBlob(encodedData, file.type)
|
||||
console.log('Add Blob file', blob)
|
||||
const formData = new FormData();
|
||||
formData.append('blobFile', blob);
|
||||
@@ -1060,32 +1061,45 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
msg.downloadFileMsg()
|
||||
}
|
||||
|
||||
downloadFileFromBrowser(fileName: string, data: any): void {
|
||||
const linkSource = data;
|
||||
const downloadLink = document.createElement("a");
|
||||
downloadLink.href = linkSource;
|
||||
downloadLink.download = fileName;
|
||||
downloadLink.click();
|
||||
}
|
||||
|
||||
async openPreview(msg: MessageService) {
|
||||
|
||||
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
|
||||
if(msg.file.type === "application/webtrix") {
|
||||
this.viewDocument(msg.file, msg.attachments.image_url)
|
||||
} else {
|
||||
|
||||
var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1));
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewMediaPage,
|
||||
cssClass: 'modal modal-desktop',
|
||||
componentProps: {
|
||||
image: str,
|
||||
type: msg.file.type,
|
||||
username: msg.u.name,
|
||||
_updatedAt: msg._updatedAt
|
||||
}
|
||||
});
|
||||
modal.present();
|
||||
|
||||
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
|
||||
} else {
|
||||
this.openFile(str, msg.attachments[0].name);
|
||||
|
||||
var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1));
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
|
||||
this.downloadFileFromBrowser(msg.attachments[0].name, str)
|
||||
/* const modal = await this.modalController.create({
|
||||
component: ViewMediaPage,
|
||||
cssClass: 'modal modal-desktop',
|
||||
componentProps: {
|
||||
image: str,
|
||||
type: msg.file.type,
|
||||
username: msg.u.name,
|
||||
_updatedAt: msg._updatedAt
|
||||
}
|
||||
});
|
||||
modal.present(); */
|
||||
|
||||
} else {
|
||||
this.openFile(str, msg.attachments[0].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -448,42 +448,14 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.deleteRecording();
|
||||
}
|
||||
|
||||
|
||||
viewDocument(msg: any, url?: string) {
|
||||
console.log(msg)
|
||||
if (msg.attachments.type == "application/webtrix") {
|
||||
//this.openViewDocumentModal(file);
|
||||
viewDocument(file: any, url?: string) {
|
||||
console.log()
|
||||
if (file.type == "application/webtrix") {
|
||||
this.openViewDocumentModal(file);
|
||||
}
|
||||
|
||||
if (msg.attachments.type == "application/pdf") {
|
||||
|
||||
try {
|
||||
const writeSecretFile = async () => {
|
||||
await Filesystem.writeFile({
|
||||
path: msg.attachments.name,
|
||||
data: msg.attachments.image_url,
|
||||
directory: Directory.Documents,
|
||||
encoding: Encoding.UTF8,
|
||||
});
|
||||
};
|
||||
|
||||
console.log('WRITE', writeSecretFile);
|
||||
|
||||
const readSecretFile = async () => {
|
||||
const contents = await Filesystem.readFile({
|
||||
path: msg.attachments.name,
|
||||
directory: Directory.Documents,
|
||||
encoding: Encoding.UTF8,
|
||||
});
|
||||
|
||||
console.log('secrets:', contents);
|
||||
};
|
||||
|
||||
console.log('READ', readSecretFile);
|
||||
|
||||
} catch (e) {
|
||||
console.error("Unable to write file", e);
|
||||
}
|
||||
else {
|
||||
let fullUrl = "https://www.tabularium.pt" + url;
|
||||
this.fileService.viewDocumentByUrl(fullUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -716,6 +688,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
"DocId": res.data.selected.Id,
|
||||
"Assunto": res.data.selected.Assunto,
|
||||
},
|
||||
temporaryData: res,
|
||||
attachments: [{
|
||||
"title": res.data.selected.Assunto,
|
||||
"description": res.data.selected.DocTypeDesc,
|
||||
@@ -780,7 +753,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
console.log('Add file', JSON.stringify(await this.getBase64(file)))
|
||||
|
||||
//if (file.type == "application/pdf") {
|
||||
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
|
||||
|
||||
const encodedData = btoa(JSON.stringify(await this.getBase64(file)));
|
||||
const blob = this.base64toBlob(encodedData, file.type)
|
||||
@@ -803,9 +776,9 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}],
|
||||
temporaryData: formData
|
||||
});
|
||||
/* } else {
|
||||
} else {
|
||||
console.log('File type invalid')
|
||||
} */
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -998,36 +971,50 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
.catch(e => console.log('Error writing file', e))
|
||||
}
|
||||
|
||||
downloadFileFromBrowser(fileName: string, data: any): void {
|
||||
const linkSource = data;
|
||||
const downloadLink = document.createElement("a");
|
||||
downloadLink.href = linkSource;
|
||||
downloadLink.download = fileName;
|
||||
downloadLink.click();
|
||||
}
|
||||
|
||||
|
||||
async openPreview(msg) {
|
||||
console.log(msg);
|
||||
|
||||
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
//this.testDownlod(msg)
|
||||
|
||||
if(msg.file.type === "application/webtrix") {
|
||||
this.viewDocument(msg.file, msg.attachments.image_url)
|
||||
} else {
|
||||
var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1));
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewMediaPage,
|
||||
cssClass: 'modal modal-desktop',
|
||||
componentProps: {
|
||||
image: str,
|
||||
type: msg.file.type,
|
||||
username: msg.u.name,
|
||||
_updatedAt: msg._updatedAt
|
||||
}
|
||||
});
|
||||
modal.present();
|
||||
|
||||
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
//this.testDownlod(msg)
|
||||
|
||||
} else {
|
||||
this.openFile(str, msg.attachments[0].name, msg.file.type);
|
||||
var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1));
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
|
||||
this.downloadFileFromBrowser(msg.attachments[0].name, str)
|
||||
/* const modal = await this.modalController.create({
|
||||
component: ViewMediaPage,
|
||||
cssClass: 'modal modal-desktop',
|
||||
componentProps: {
|
||||
image: str,
|
||||
type: msg.file.type,
|
||||
username: msg.u.name,
|
||||
_updatedAt: msg._updatedAt
|
||||
}
|
||||
});
|
||||
modal.present(); */
|
||||
|
||||
} else {
|
||||
this.openFile(str, msg.attachments[0].name, msg.file.type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user