add file chuck upload, file validation, redirect to home page incase route doesnt exist and refresh token interceptor

This commit is contained in:
Peter Maquiran
2023-11-09 11:45:04 +01:00
parent a05f85a37f
commit a16e97a59a
41 changed files with 48604 additions and 1902 deletions
+5
View File
@@ -0,0 +1,5 @@
export interface refreshToken {
Authorization: string,
refreshToken: null
}
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { MiddlewareServiceService } from './middleware-service.service';
describe('MiddlewareServiceService', () => {
let service: MiddlewareServiceService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MiddlewareServiceService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,23 @@
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { HttpServiceService } from 'src/app/services/http/http-service.service';
import { Observable } from "rxjs";
import { refreshToken } from "./interface"
@Injectable({
providedIn: 'root'
})
export class MiddlewareServiceService {
constructor(
private HttpServiceService: HttpServiceService,
) {}
refreshToken(refreshToken: string): Observable<refreshToken> {
const data = {
refreshToken: refreshToken
}
return this.HttpServiceService.put(environment.apiURL + "UserAuthentication/RefreshToken", data, {})
}
}
@@ -29,6 +29,7 @@ import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { SessionStore } from 'src/app/store/session.service';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
import { PermissionService } from 'src/app/services/permission.service';
import { FileValidatorService } from "src/app/services/file/file-validator.service"
@Component({
selector: 'app-group-messages',
@@ -105,6 +106,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
private platform: Platform,
private fileOpener: FileOpener,
public p: PermissionService,
private FileValidatorService: FileValidatorService
) {
this.ChatSystemService.getUser()
@@ -901,9 +903,11 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
const file: any = await this.fileService.getFileFromDevice(types);
const fileName = file.name
const validation = this.FileValidatorService.fileNameValidation(fileName)
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
if(validation.isOk) {
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => {
console.error(error);
@@ -946,9 +950,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
fileBase64: fileBase64,
}
})
} else {
this.toastService._badRequest("ficheiro invalido")
}
+11 -8
View File
@@ -33,6 +33,7 @@ import { Howl } from 'howler';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
import { ChatMessageDebuggingPage } from 'src/app/shared/popover/chat-message-debugging/chat-message-debugging.page';
import { PermissionService } from 'src/app/services/permission.service';
import { FileValidatorService } from "src/app/services/file/file-validator.service"
const IMAGE_DIR = 'stored-images';
@@ -100,7 +101,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
roomName: any;
isAdmin = false;
roomCountDownDate: string;
constructor(
public popoverController: PopoverController,
@@ -122,6 +123,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
private platform: Platform,
private fileOpener: FileOpener,
public p: PermissionService,
private FileValidatorService: FileValidatorService
) {
// update
this.checkAudioPermission()
@@ -172,8 +174,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.audioPermissionStatus = permissionStatus.state
permissionStatus.onchange = (data: any) => {
//
//
//
//
}
}
@@ -510,7 +512,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
getChatMembers() {
//
//
// this.showLoader = true;
// this.chatService.getMembers(this.roomId).subscribe(res => {
@@ -835,11 +837,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const roomId = this.roomId
const file: any = await this.fileService.getFileFromDevice(types);
console.log(file.type)
const fileName = file.name
const validation = this.FileValidatorService.fileNameValidation(fileName)
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
if(validation.isOk) {
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch((error) => {
console.error(error);
@@ -886,12 +889,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
fileBase64: fileBase64,
}
})
} else {
this.toastService._badRequest("ficheiro invalido")
}
}
_getBase64(file) {
@@ -59,7 +59,7 @@ export class AttendeePage implements OnInit {
this.LtaskParticipants = removeDuplicate(this.taskParticipants);
this.LtaskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
this.loggeduser = SessionStore.user;
}
ngOnChanges() {
@@ -137,7 +137,7 @@ export class AttendeePage implements OnInit {
itm.IsRequired = false;
this.LtaskParticipantsCc.push(itm);
} else {
//
//
}
// run only in gabinete digital
@@ -247,15 +247,15 @@ export class AttendeePage implements OnInit {
this.showLoader = false;
} else {
this.contacts = this.sort(result as any);
console.log('Attendes Email', this.loggeduser.Email)
// console.log('Attendes Email', this.loggeduser.Email)
let filterLoggedUserEmail = this.contacts.filter(item => item.EmailAddress.toLocaleLowerCase() != this.loggeduser.Email.toLocaleLowerCase())
if(this.taskType == 0 || this.taskType == 1){
filterLoggedUserEmail = this.contacts.filter(item => item.IsPR == false)
}
console.log('Attendes Email', filterLoggedUserEmail)
// console.log('Attendes Email', filterLoggedUserEmail)
let filterEmptyEmail = filterLoggedUserEmail.filter(item => item.EmailAddress.toLocaleLowerCase() != "")
this.contacts = filterEmptyEmail;
console.log('Attendes Email', this.contacts)
// console.log('Attendes Email', this.contacts)
this.showLoader = false;
}
@@ -271,4 +271,4 @@ export class AttendeePage implements OnInit {
}
}
}
}
@@ -10,6 +10,7 @@ import { ThemeService } from 'src/app/services/theme.service';
import { Camera, CameraResultType, CameraSource} from '@capacitor/camera';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
import { FileValidatorService } from "src/app/services/file/file-validator.service"
@Component({
selector: 'app-new-publication',
@@ -19,7 +20,7 @@ import { PublicationFolderService } from 'src/app/store/publication-folder.servi
export class NewPublicationPage implements OnInit {
showLoader: boolean;
pub: Publication = new Publication();
publicationTitle:string;
imgUrl:any;
@@ -50,11 +51,12 @@ export class NewPublicationPage implements OnInit {
private toastService: ToastService,
public ThemeService: ThemeService,
private httpErroHandle: HttpErrorHandle,
public PublicationFolderService: PublicationFolderService
public PublicationFolderService: PublicationFolderService,
private FileValidatorService: FileValidatorService
) {
this.publicationTitle = 'Nova Publicação';
}
ngOnInit() {
@@ -79,7 +81,7 @@ export class NewPublicationPage implements OnInit {
getPublicationDetail() {
if(this.publicationType != '2') {
if(this.publicationType != '2') {
this.showLoader = true;
this.publications.GetPublicationById(this.documentId).subscribe( res => {
this.publication = {
@@ -97,7 +99,7 @@ export class NewPublicationPage implements OnInit {
this.showLoader = false;
}, () => {
this.showLoader = false;
this.goBack()
this.goBack()
});
}
@@ -114,16 +116,24 @@ export class NewPublicationPage implements OnInit {
this.capturedImage = 'data:image/jpeg;base64,' +capturedImage.base64String;
this.capturedImageTitle = 'foto';
const compressedImage = await this.compressImageBase64(
this.capturedImage,
800, // maxWidth
800, // maxHeight
0.9 // quality
).then((picture) => {
console.log('taked: ', picture)
this.capturedImage = picture
});
const validation = await this.FileValidatorService.ValidateImage(this.capturedImage)
if(validation.isOk) {
const compressedImage = await this.compressImageBase64(
this.capturedImage,
800, // maxWidth
800, // maxHeight
0.9 // quality
).then((picture) => {
console.log('taked: ', picture)
this.capturedImage = picture
});
} else {
this.toastService._badRequest("imagem invalida")
}
}
async laodPicture() {
@@ -136,15 +146,24 @@ export class NewPublicationPage implements OnInit {
this.capturedImage = 'data:image/jpeg;base64,' +capturedImage.base64String;
this.capturedImageTitle = 'foto';
const compressedImage = await this.compressImageBase64(
this.capturedImage,
800, // maxWidth
800, // maxHeight
0.9 // quality
).then((picture) => {
console.log('Selected: ', picture)
this.capturedImage = picture
});
const validation = await this.FileValidatorService.ValidateImage(this.capturedImage)
if(validation.isOk) {
const compressedImage = await this.compressImageBase64(
this.capturedImage,
800, // maxWidth
800, // maxHeight
0.9 // quality
).then((picture) => {
console.log('Selected: ', picture)
this.capturedImage = picture
});
} else {
this.toastService._badRequest("imagem invalida")
}
}
@@ -176,20 +195,20 @@ export class NewPublicationPage implements OnInit {
if(this.Form.invalid) {
return false
} else {
}
if(this.publicationType == '3') {
if(!this.publication?.OriginalFileName || !this.pub.OriginalFileName) {
if(this.pub?.OriginalFileName) {
console.log('this.pub',this.pub)
}
throw('no this.publication.OriginalFileName')
}
const loader = this.toastService.loading()
if(this.capturedImage != '') {
@@ -208,7 +227,7 @@ export class NewPublicationPage implements OnInit {
}
else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) { //
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId:this.publication.DocumentId,
@@ -244,7 +263,7 @@ export class NewPublicationPage implements OnInit {
console.log({response})
this.goBack();
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
if(error.status == 404) {
@@ -255,7 +274,7 @@ export class NewPublicationPage implements OnInit {
loader.remove()
}
}
else {
@@ -275,16 +294,16 @@ export class NewPublicationPage implements OnInit {
const loader = this.toastService.loading()
try {
await this.publications.CreatePublication(this.publication.ProcessId, this.publication).toPromise()
if(this.publicationTitle == '1') {
} else if (this.publicationTitle == '2') {
this.httpErroHandle.httpsSucessMessagge('Criar publicação')
} else if (this.publicationTitle == '3') {
this.httpErroHandle.httpsSucessMessagge('Editar publicação')
}
this.goBackToViewPublications.emit();
} catch (error) {
@@ -337,32 +356,32 @@ export class NewPublicationPage implements OnInit {
return new Promise((resolve, reject) => {
const image = new (window as any).Image();
image.src = base64String;
image.onload = async () => {
const canvas = document.createElement('canvas');
let newWidth = image.width;
let newHeight = image.height;
if (newWidth > maxWidth) {
newHeight *= maxWidth / newWidth;
newWidth = maxWidth;
}
if (newHeight > maxHeight) {
newWidth *= maxHeight / newHeight;
newHeight = maxHeight;
}
canvas.width = newWidth;
canvas.height = newHeight;
const context = canvas.getContext('2d');
context?.drawImage(image, 0, 0, newWidth, newHeight);
const compressedBase64 = canvas.toDataURL('image/jpeg', quality);
resolve(compressedBase64);
};
image.onerror = (error) => {
reject(error);
};