mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
add file chuck upload, file validation, redirect to home page incase route doesnt exist and refresh token interceptor
This commit is contained in:
@@ -32,6 +32,10 @@ import { SessionStore } from 'src/app/store/session.service';
|
||||
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
|
||||
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
|
||||
import { RouteService } from 'src/app/services/route.service';
|
||||
import { FileValidatorService } from "src/app/services/file/file-validator.service"
|
||||
import { sanitize } from "sanitize-filename-ts";
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-group-messages',
|
||||
templateUrl: './group-messages.page.html',
|
||||
@@ -104,6 +108,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
private file: File,
|
||||
private fileOpener: FileOpener,
|
||||
public RouteService: RouteService,
|
||||
private FileValidatorService: FileValidatorService
|
||||
) {
|
||||
this.ChatSystemService.getUser()
|
||||
|
||||
@@ -507,7 +512,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
"mimeType": audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName,
|
||||
"title": sanitize(fileName),
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
@@ -828,37 +833,45 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
const file: any = await this.fileService.getFileFromDevice(types);
|
||||
|
||||
|
||||
const fileName = file.name
|
||||
|
||||
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
|
||||
const validation = this.FileValidatorService.fileNameValidation(fileName)
|
||||
|
||||
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch((error) => {
|
||||
console.error(error);
|
||||
})));
|
||||
const blob = this.fileService.base64toBlob(encodedData, file.type)
|
||||
if(validation.isOk) {
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('blobFile', blob);
|
||||
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).catch((error) => {
|
||||
console.error(error);
|
||||
})));
|
||||
const blob = this.fileService.base64toBlob(encodedData, file.type)
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('blobFile', blob);
|
||||
|
||||
|
||||
this.ChatSystemService.getGroupRoom(roomId).send({
|
||||
file: {
|
||||
"type": file.type,
|
||||
"guid": '',
|
||||
},
|
||||
attachments: [{
|
||||
"title": file.name,
|
||||
"name": file.name,
|
||||
// "text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formData,
|
||||
attachmentsModelData: {
|
||||
fileBase64: encodedData
|
||||
}
|
||||
});
|
||||
this.ChatSystemService.getGroupRoom(roomId).send({
|
||||
file: {
|
||||
"type": file.type,
|
||||
"guid": '',
|
||||
},
|
||||
attachments: [{
|
||||
"title": sanitize(fileName),
|
||||
"name": sanitize(fileName),
|
||||
// "text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formData,
|
||||
attachmentsModelData: {
|
||||
fileBase64: encodedData
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
this.toastService._badRequest("ficheiro invalido")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user