Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(server): save original file name with extension #7679

Merged
merged 15 commits into from
Mar 7, 2024
1 change: 0 additions & 1 deletion e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions e2e/src/api/specs/asset.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ describe('/asset', () => {
input: 'formats/jpg/el_torcal_rocks.jpg',
expected: {
type: AssetTypeEnum.Image,
originalFileName: 'el_torcal_rocks',
originalFileName: 'el_torcal_rocks.jpg',
resized: true,
exifInfo: {
dateTimeOriginal: '2012-08-05T11:39:59.000Z',
Expand All @@ -518,7 +518,7 @@ describe('/asset', () => {
input: 'formats/heic/IMG_2682.heic',
expected: {
type: AssetTypeEnum.Image,
originalFileName: 'IMG_2682',
originalFileName: 'IMG_2682.heic',
resized: true,
fileCreatedAt: '2019-03-21T16:04:22.348Z',
exifInfo: {
Expand All @@ -543,7 +543,7 @@ describe('/asset', () => {
input: 'formats/png/density_plot.png',
expected: {
type: AssetTypeEnum.Image,
originalFileName: 'density_plot',
originalFileName: 'density_plot.png',
resized: true,
exifInfo: {
exifImageWidth: 800,
Expand All @@ -558,7 +558,7 @@ describe('/asset', () => {
input: 'formats/raw/Nikon/D80/glarus.nef',
expected: {
type: AssetTypeEnum.Image,
originalFileName: 'glarus',
originalFileName: 'glarus.nef',
resized: true,
fileCreatedAt: '2010-07-20T17:27:12.000Z',
exifInfo: {
Expand All @@ -580,7 +580,7 @@ describe('/asset', () => {
input: 'formats/raw/Nikon/D700/philadelphia.nef',
expected: {
type: AssetTypeEnum.Image,
originalFileName: 'philadelphia',
originalFileName: 'philadelphia.nef',
resized: true,
fileCreatedAt: '2016-09-22T22:10:29.060Z',
exifInfo: {
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/api/specs/shared-link.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe('/shared-link', () => {
expect(body.assets).toHaveLength(1);
expect(body.assets[0]).toEqual(
expect.objectContaining({
originalFileName: 'example',
originalFileName: 'example.png',
localDateTime: expect.any(String),
fileCreatedAt: expect.any(String),
exifInfo: expect.any(Object),
Expand Down
36 changes: 36 additions & 0 deletions server/e2e/api/specs/asset.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,42 @@ describe(`${AssetController.name} (e2e)`, () => {
expect(asset).toMatchObject({ id: body.id, isFavorite: true });
});

it('should have correct original file name and extension (simple)', async () => {
const { body, status } = await request(server)
.post('/asset/upload')
.set('Authorization', `Bearer ${user1.accessToken}`)
.field('deviceAssetId', 'example-image')
.field('deviceId', 'TEST')
.field('fileCreatedAt', new Date().toISOString())
.field('fileModifiedAt', new Date().toISOString())
.field('isFavorite', 'true')
.field('duration', '0:00:00.000000')
.attach('assetData', randomBytes(32), 'example.jpg');
expect(status).toBe(201);
expect(body).toEqual({ id: expect.any(String), duplicate: false });

const asset = await api.assetApi.get(server, user1.accessToken, body.id);
expect(asset).toMatchObject({ id: body.id, originalFileName: 'example.jpg' });
});

it('should have correct original file name and extension (complex)', async () => {
const { body, status } = await request(server)
.post('/asset/upload')
.set('Authorization', `Bearer ${user1.accessToken}`)
.field('deviceAssetId', 'example-image')
.field('deviceId', 'TEST')
.field('fileCreatedAt', new Date().toISOString())
.field('fileModifiedAt', new Date().toISOString())
.field('isFavorite', 'true')
.field('duration', '0:00:00.000000')
.attach('assetData', randomBytes(32), 'example.complex.ext.jpg');
expect(status).toBe(201);
expect(body).toEqual({ id: expect.any(String), duplicate: false });

const asset = await api.assetApi.get(server, user1.accessToken, body.id);
expect(asset).toMatchObject({ id: body.id, originalFileName: 'example.complex.ext.jpg' });
});

it('should not upload the same asset twice', async () => {
const content = randomBytes(32);
await api.assetApi.upload(server, user1.accessToken, 'example-image', { content });
Expand Down
2 changes: 1 addition & 1 deletion server/src/immich/api-v1/asset/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export class AssetService {
duration: dto.duration || null,
isVisible: dto.isVisible ?? true,
livePhotoVideo: livePhotoAssetId === null ? null : ({ id: livePhotoAssetId } as AssetEntity),
originalFileName: parse(file.originalName).name,
originalFileName: parse(file.originalName).name + parse(file.originalName).ext,
alextran1502 marked this conversation as resolved.
Show resolved Hide resolved
sidecarPath: sidecarPath || null,
isReadOnly: dto.isReadOnly ?? false,
isOffline: dto.isOffline ?? false,
Expand Down