Skip to content

Commit

Permalink
fix(ui) - handling unicode and special charachters at cover
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkbln committed Nov 23, 2024
1 parent 0fb7971 commit 8cd64da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions client/src/lib/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ export const getImageResolution = (
};
img.src = URL.createObjectURL(file);
};

export const removeUnicodeAndSpecialCharacters = (userName: string): string => {
return userName
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.replace(/ /g, '-')
.replace(/[^a-zA-Z0-9\s-]/g, "");
}
8 changes: 5 additions & 3 deletions client/src/sagas/helpers/podcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ import * as request from '../../lib/request';
import { selectors } from '../../store';
import { type locales } from '../../types/locales.types';
import { type category } from '../../types/categories.types';
import { extractImageType } from '../../lib/image';
import { extractImageType, removeUnicodeAndSpecialCharacters} from '../../lib/image';

function transferPodcastCoverFromData(imageData: string, imageName: string) {
const parts: string[] = imageData.split(',');
const imageType: string | null = extractImageType(parts[0]);
const name = removeUnicodeAndSpecialCharacters(imageName);

const image = {
base64Data: parts[1],
name: imageName,
name: name + 'cover',
type: imageType
};

request.post(request.origin('/api/v1/save_podcast_image'), { params: {}, data: image });
}

function transferPodcastCoverFromURL(imageUrl: string, podcastName: string) {
const name = podcastName.replace(/ /g, '-');
const name = removeUnicodeAndSpecialCharacters(podcastName);

const image = {
name: name + '-cover',
url: imageUrl
Expand Down

0 comments on commit 8cd64da

Please sign in to comment.