chore(server): change save -> update in asset repository (#8055)

* `save` -> `update`

* change return type

* include relations

* fix tests

* remove when mocks

* fix

* stricter typing

* simpler type
This commit is contained in:
Mert
2024-03-19 22:42:10 -04:00
committed by GitHub
parent 9e4bab7494
commit 2daed747cd
14 changed files with 128 additions and 138 deletions

View File

@@ -205,7 +205,7 @@ describe(MediaService.name, () => {
assetMock.getByIds.mockResolvedValue([]);
await sut.handleGenerateJpegThumbnail({ id: assetStub.image.id });
expect(mediaMock.resize).not.toHaveBeenCalled();
expect(assetMock.save).not.toHaveBeenCalledWith();
expect(assetMock.update).not.toHaveBeenCalledWith();
});
it('should skip video thumbnail generation if no video stream', async () => {
@@ -213,7 +213,7 @@ describe(MediaService.name, () => {
assetMock.getByIds.mockResolvedValue([assetStub.video]);
await sut.handleGenerateJpegThumbnail({ id: assetStub.image.id });
expect(mediaMock.resize).not.toHaveBeenCalled();
expect(assetMock.save).not.toHaveBeenCalledWith();
expect(assetMock.update).not.toHaveBeenCalledWith();
});
it('should generate a thumbnail for an image', async () => {
@@ -227,7 +227,7 @@ describe(MediaService.name, () => {
quality: 80,
colorspace: Colorspace.SRGB,
});
expect(assetMock.save).toHaveBeenCalledWith({
expect(assetMock.update).toHaveBeenCalledWith({
id: 'asset-id',
resizePath: 'upload/thumbs/user-id/as/se/asset-id.jpeg',
});
@@ -246,7 +246,7 @@ describe(MediaService.name, () => {
quality: 80,
colorspace: Colorspace.P3,
});
expect(assetMock.save).toHaveBeenCalledWith({
expect(assetMock.update).toHaveBeenCalledWith({
id: 'asset-id',
resizePath: 'upload/thumbs/user-id/as/se/asset-id.jpeg',
});
@@ -271,7 +271,7 @@ describe(MediaService.name, () => {
twoPass: false,
},
);
expect(assetMock.save).toHaveBeenCalledWith({
expect(assetMock.update).toHaveBeenCalledWith({
id: 'asset-id',
resizePath: 'upload/thumbs/user-id/as/se/asset-id.jpeg',
});
@@ -296,7 +296,7 @@ describe(MediaService.name, () => {
twoPass: false,
},
);
expect(assetMock.save).toHaveBeenCalledWith({
expect(assetMock.update).toHaveBeenCalledWith({
id: 'asset-id',
resizePath: 'upload/thumbs/user-id/as/se/asset-id.jpeg',
});
@@ -337,7 +337,7 @@ describe(MediaService.name, () => {
assetMock.getByIds.mockResolvedValue([]);
await sut.handleGenerateWebpThumbnail({ id: assetStub.image.id });
expect(mediaMock.resize).not.toHaveBeenCalled();
expect(assetMock.save).not.toHaveBeenCalledWith();
expect(assetMock.update).not.toHaveBeenCalledWith();
});
it('should generate a thumbnail', async () => {
@@ -350,7 +350,7 @@ describe(MediaService.name, () => {
quality: 80,
colorspace: Colorspace.SRGB,
});
expect(assetMock.save).toHaveBeenCalledWith({
expect(assetMock.update).toHaveBeenCalledWith({
id: 'asset-id',
webpPath: 'upload/thumbs/user-id/as/se/asset-id.webp',
});
@@ -370,7 +370,7 @@ describe(MediaService.name, () => {
quality: 80,
colorspace: Colorspace.P3,
});
expect(assetMock.save).toHaveBeenCalledWith({
expect(assetMock.update).toHaveBeenCalledWith({
id: 'asset-id',
webpPath: 'upload/thumbs/user-id/as/se/asset-id.webp',
});
@@ -397,7 +397,7 @@ describe(MediaService.name, () => {
await sut.handleGenerateThumbhashThumbnail({ id: assetStub.image.id });
expect(mediaMock.generateThumbhash).toHaveBeenCalledWith('/uploads/user-id/thumbs/path.jpg');
expect(assetMock.save).toHaveBeenCalledWith({ id: 'asset-id', thumbhash: thumbhashBuffer });
expect(assetMock.update).toHaveBeenCalledWith({ id: 'asset-id', thumbhash: thumbhashBuffer });
});
});

View File

@@ -172,7 +172,7 @@ export class MediaService {
}
const resizePath = await this.generateThumbnail(asset, 'jpeg');
await this.assetRepository.save({ id: asset.id, resizePath });
await this.assetRepository.update({ id: asset.id, resizePath });
return JobStatus.SUCCESS;
}
@@ -222,7 +222,7 @@ export class MediaService {
}
const webpPath = await this.generateThumbnail(asset, 'webp');
await this.assetRepository.save({ id: asset.id, webpPath });
await this.assetRepository.update({ id: asset.id, webpPath });
return JobStatus.SUCCESS;
}
@@ -233,7 +233,7 @@ export class MediaService {
}
const thumbhash = await this.mediaRepository.generateThumbhash(asset.resizePath);
await this.assetRepository.save({ id: asset.id, thumbhash });
await this.assetRepository.update({ id: asset.id, thumbhash });
return JobStatus.SUCCESS;
}
@@ -286,7 +286,7 @@ export class MediaService {
if (asset.encodedVideoPath) {
this.logger.log(`Transcoded video exists for asset ${asset.id}, but is no longer required. Deleting...`);
await this.jobRepository.queue({ name: JobName.DELETE_FILES, data: { files: [asset.encodedVideoPath] } });
await this.assetRepository.save({ id: asset.id, encodedVideoPath: null });
await this.assetRepository.update({ id: asset.id, encodedVideoPath: null });
}
return JobStatus.SKIPPED;
@@ -321,7 +321,7 @@ export class MediaService {
this.logger.log(`Successfully encoded ${asset.id}`);
await this.assetRepository.save({ id: asset.id, encodedVideoPath: output });
await this.assetRepository.update({ id: asset.id, encodedVideoPath: output });
return JobStatus.SUCCESS;
}