Skip to content
Snippets Groups Projects
Commit f7f254ef authored by OZGCloud's avatar OZGCloud
Browse files

OZG-3262 OZG-3379 sanitize filename; tiny cleanup

parent 15d9a490
No related branches found
No related tags found
No related merge requests found
......@@ -23,11 +23,10 @@
*/
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { createEmptyStateResource, createErrorStateResource, createStateResource, EMPTY_STRING, getMessageCode, getMessageForIssue, isNotNil, isUnprocessableEntity, StateResource } from '@goofy-client/tech-shared';
import { createEmptyStateResource, createErrorStateResource, createStateResource, EMPTY_STRING, getMessageForIssue, isNotNil, isUnprocessableEntity, isValidationFieldFileSizeExceedError, sanitizeFileName, StateResource } from '@goofy-client/tech-shared';
import { SnackBarService } from '@goofy-client/ui';
import { Resource, ResourceUri } from '@ngxp/rest';
import { saveAs } from 'file-saver';
import { ValidationMessageCode } from 'libs/tech-shared/src/lib/validation/tech.validation.messages';
import { isNil } from 'lodash-es';
import { Observable, of, throwError } from 'rxjs';
import { catchError, map, mergeMap, startWith } from 'rxjs/operators';
......@@ -51,7 +50,7 @@ export class BinaryFileService {
}
handleErrorByStatus(error: HttpErrorResponse): StateResource<any> {
if (isUnprocessableEntity(error.status) && getMessageCode(error.error) === ValidationMessageCode.VALIDATION_FIELD_FILE_SIZE_EXCEEDED) {
if (isUnprocessableEntity(error.status) && isValidationFieldFileSizeExceedError(error.error)) {
this.snackbarService.showError(getMessageForIssue(EMPTY_STRING, error.error.issues[0]));
return createErrorStateResource(error.error);
}
......@@ -74,7 +73,7 @@ export class BinaryFileService {
private buildFileName(file: BinaryFileResource, fileNamePrefix: string): string {
if(isNotNil(fileNamePrefix)){
return `${fileNamePrefix}_${file.name}`;
return sanitizeFileName(`${fileNamePrefix}_${file.name}`);
}
return file.name;
}
......
......@@ -23,6 +23,7 @@
*/
import { Base64 } from 'js-base64';
import { isEmpty, isNil, isNull, isUndefined } from 'lodash-es';
import { sanitize } from 'sanitize-filename-ts';
import { ApiError } from './tech.model';
export const EMPTY_STRING = '';
......@@ -91,16 +92,20 @@ export function convertForDataTest(value: string): string {
}
export function getStringValue(value: null | undefined | string): string {
if (isNull(value) || isUndefined(value)) {
if (isNil(value)) {
return EMPTY_STRING;
}
return value;
}
export function encodeUrlForEmbedding(url: string) {
export function encodeUrlForEmbedding(url: string): string {
return Base64.encodeURI(url);
}
export function decodeUrlFromEmbedding(url: string) {
export function decodeUrlFromEmbedding(url: string): string {
return Base64.decode(url);
}
export function sanitizeFileName(value: any): string {
return sanitize(value);
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ import { AbstractControl, UntypedFormGroup } from '@angular/forms';
import { isNil } from 'lodash-es';
import { ApiError, Issue } from '../tech.model';
import { replacePlaceholder } from '../tech.util';
import { VALIDATION_MESSAGES } from './tech.validation.messages';
import { ValidationMessageCode, VALIDATION_MESSAGES } from './tech.validation.messages';
export function isValidationError(issue: Issue): boolean {
return issue.messageCode.includes('javax.validation.constraints')
......@@ -65,3 +65,7 @@ export function getMessageForIssue(label: string, issue: Issue) {
export function getMessageCode(apiError: ApiError): string {
return apiError.issues[0].messageCode;
}
export function isValidationFieldFileSizeExceedError(error: any){
return getMessageCode(error) === ValidationMessageCode.VALIDATION_FIELD_FILE_SIZE_EXCEEDED;
}
\ No newline at end of file
This diff is collapsed.
......@@ -75,6 +75,7 @@
"js-base64": "^3.7.3",
"lodash-es": "4.17.21",
"rxjs": "^6.6.0",
"sanitize-filename-ts": "^1.0.2",
"tslib": "^2.0.0",
"typeface-roboto": "1.1.13",
"zone.js": "0.11.5"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment