fix(web+mobile): consistent filename handling (#2534)

This commit is contained in:
Michel Heusschen 2023-05-28 03:53:29 +02:00 committed by GitHub
parent 6c6c5ef651
commit 7f0ad8e2d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 25 deletions

View file

@ -108,8 +108,17 @@ export async function bulkDownload(
* an empty string when not found.
*/
export function getFilenameExtension(filename: string): string {
const lastIndex = filename.lastIndexOf('.');
return filename.slice(lastIndex + 1).toLowerCase();
const lastIndex = Math.max(0, filename.lastIndexOf('.'));
const startIndex = (lastIndex || Infinity) + 1;
return filename.slice(startIndex).toLowerCase();
}
/**
* Returns the filename of an asset including file extension
*/
export function getAssetFilename(asset: AssetResponseDto): string {
const fileExtension = getFilenameExtension(asset.originalPath);
return `${asset.originalFileName}.${fileExtension}`;
}
/**