mirror of
https://github.com/immich-app/immich.git
synced 2025-01-10 13:56:47 +01:00
b71d7e33bb
* refactor(server): calculate asset type server-side
* chore: open api
* chore: remove comments
* fix: linting
* update
* Revert "update"
This reverts commit dc58702923
.
* fix: upload LivePhotos
* chore: remove unused request fields for upload
* remove unused method
* mobile-fix: livePhoto filename
* fix: revert check for livephotos filename and extension
---------
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import type { AssetResponseDto } from '@api';
|
|
import { describe, expect, it } from '@jest/globals';
|
|
import { getAssetFilename, getFilenameExtension } from './asset-utils';
|
|
|
|
describe('get file extension from filename', () => {
|
|
it('returns the extension without including the dot', () => {
|
|
expect(getFilenameExtension('filename.txt')).toEqual('txt');
|
|
});
|
|
|
|
it('takes the last file extension and ignores the rest', () => {
|
|
expect(getFilenameExtension('filename.txt.pdf')).toEqual('pdf');
|
|
expect(getFilenameExtension('filename.txt.pdf.jpg')).toEqual('jpg');
|
|
});
|
|
|
|
it('returns an empty string when no file extension is found', () => {
|
|
expect(getFilenameExtension('filename')).toEqual('');
|
|
expect(getFilenameExtension('filename.')).toEqual('');
|
|
expect(getFilenameExtension('filename..')).toEqual('');
|
|
expect(getFilenameExtension('.filename')).toEqual('');
|
|
});
|
|
|
|
it('returns the extension from a filepath', () => {
|
|
expect(getFilenameExtension('/folder/file.txt')).toEqual('txt');
|
|
expect(getFilenameExtension('./folder/file.txt')).toEqual('txt');
|
|
expect(getFilenameExtension('~/folder/file.txt')).toEqual('txt');
|
|
expect(getFilenameExtension('./folder/.file.txt')).toEqual('txt');
|
|
expect(getFilenameExtension('/folder.with.dots/file.txt')).toEqual('txt');
|
|
});
|
|
});
|
|
|
|
describe('get asset filename', () => {
|
|
it('returns the filename including file extension', () => {
|
|
[
|
|
{
|
|
asset: {
|
|
originalFileName: 'filename',
|
|
originalPath: 'upload/library/test/2016/2016-08-30/filename.jpg',
|
|
},
|
|
result: 'filename.jpg',
|
|
},
|
|
{
|
|
asset: {
|
|
originalFileName: 'new-filename',
|
|
originalPath: 'upload/library/89d14e47-a40d-4cae-a347-a914cdef1f22/2016/2016-08-30/filename.jpg',
|
|
},
|
|
result: 'new-filename.jpg',
|
|
},
|
|
{
|
|
asset: {
|
|
originalFileName: 'new-filename.txt',
|
|
originalPath: 'upload/library/test/2016/2016-08-30/filename.txt.jpg',
|
|
},
|
|
result: 'new-filename.txt.jpg',
|
|
},
|
|
].forEach(({ asset, result }) => {
|
|
expect(getAssetFilename(asset as AssetResponseDto)).toEqual(result);
|
|
});
|
|
});
|
|
});
|