refactor(server): mime types (#3197)

* refactor(server): mime type check

* chore: open api

* chore: remove duplicate test
This commit is contained in:
Jason Rasmussen
2023-07-10 13:56:45 -04:00
committed by GitHub
parent 785f61ba70
commit 6180828ed2
26 changed files with 287 additions and 324 deletions

View File

@@ -17,7 +17,7 @@ import { PersonService } from './person.service';
const responseDto: PersonResponseDto = {
id: 'person-1',
name: 'Person 1',
thumbnailPath: '/path/to/thumbnail',
thumbnailPath: '/path/to/thumbnail.jpg',
};
describe(PersonService.name, () => {
@@ -74,7 +74,7 @@ describe(PersonService.name, () => {
it('should serve the thumbnail', async () => {
personMock.getById.mockResolvedValue(personStub.noName);
await sut.getThumbnail(authStub.admin, 'person-1');
expect(storageMock.createReadStream).toHaveBeenCalledWith('/path/to/thumbnail', 'image/jpeg');
expect(storageMock.createReadStream).toHaveBeenCalledWith('/path/to/thumbnail.jpg', 'image/jpeg');
});
});
@@ -150,7 +150,7 @@ describe(PersonService.name, () => {
expect(personMock.delete).toHaveBeenCalledWith(personStub.noName);
expect(jobMock.queue).toHaveBeenCalledWith({
name: JobName.DELETE_FILES,
data: { files: ['/path/to/thumbnail'] },
data: { files: ['/path/to/thumbnail.jpg'] },
});
});
});

View File

@@ -2,6 +2,7 @@ import { PersonEntity } from '@app/infra/entities';
import { BadRequestException, Inject, Injectable, Logger, NotFoundException } from '@nestjs/common';
import { AssetResponseDto, mapAsset } from '../asset';
import { AuthUserDto } from '../auth';
import { mimeTypes } from '../domain.constant';
import { IJobRepository, JobName } from '../job';
import { ImmichReadStream, IStorageRepository } from '../storage';
import { mapPerson, PersonResponseDto, PersonUpdateDto } from './person.dto';
@@ -44,7 +45,7 @@ export class PersonService {
throw new NotFoundException();
}
return this.storageRepository.createReadStream(person.thumbnailPath, 'image/jpeg');
return this.storageRepository.createReadStream(person.thumbnailPath, mimeTypes.lookup(person.thumbnailPath));
}
async getAssets(authUser: AuthUserDto, personId: string): Promise<AssetResponseDto[]> {