MM-31705 allow file local path to use multiple dots (#5109)
* MM-31705 allow file local path to use multiple dots * Add unit test
This commit is contained in:
parent
0d590c742f
commit
2e790212f9
2 changed files with 30 additions and 2 deletions
|
|
@ -283,7 +283,24 @@ export const hashCode = (str) => {
|
|||
export function getLocalFilePathFromFile(dir, file) {
|
||||
if (dir) {
|
||||
if (file?.name) {
|
||||
const [filename, extension] = file.name.split('.');
|
||||
let extension = file.extension;
|
||||
let filename = file.name;
|
||||
|
||||
if (!extension) {
|
||||
extension = getExtensionFromMime(file.mime_type);
|
||||
}
|
||||
|
||||
if (extension && filename.includes(`.${extension}`)) {
|
||||
filename = filename.replace(`.${extension}`, '');
|
||||
} else {
|
||||
const fileParts = file.name.split('.');
|
||||
|
||||
if (fileParts.length > 1) {
|
||||
extension = fileParts.pop();
|
||||
filename = fileParts.join('.');
|
||||
}
|
||||
}
|
||||
|
||||
return `${dir}/${filename}-${hashCode(file.id)}.${extension}`;
|
||||
} else if (file?.id && file?.extension) {
|
||||
return `${dir}/${file.id}.${file.extension}`;
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ describe('getExtensionFromContentDisposition', () => {
|
|||
it('should return the path for the document file', () => {
|
||||
const file = {
|
||||
id: generateId(),
|
||||
name: 'Some other doocument.txt',
|
||||
name: 'Some other document.txt',
|
||||
extension: 'txt',
|
||||
};
|
||||
|
||||
|
|
@ -126,4 +126,15 @@ describe('getExtensionFromContentDisposition', () => {
|
|||
const [filename] = file.name.split('.');
|
||||
expect(localFile).toBe(`${DeviceTypes.DOCUMENTS_PATH}/${filename}-${hashCode(file.id)}.${file.extension}`);
|
||||
});
|
||||
|
||||
it('should return the path for the document file including multiple dots in the filename', () => {
|
||||
const file = {
|
||||
id: generateId(),
|
||||
name: 'Some.other.document.txt',
|
||||
extension: 'txt',
|
||||
};
|
||||
const expectedFilename = 'Some.other.document';
|
||||
const localFile = getLocalPath(file);
|
||||
expect(localFile).toBe(`${DeviceTypes.DOCUMENTS_PATH}/${expectedFilename}-${hashCode(file.id)}.${file.extension}`);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue