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
@@ -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);
};