feat: sync description, add e2e tests
This commit is contained in:
@@ -586,15 +586,11 @@ export class AssetService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateMetadata(dto: ISidecarWriteJob & { description?: string }) {
|
private async updateMetadata(dto: ISidecarWriteJob) {
|
||||||
const { id, description, dateTimeOriginal, latitude, longitude } = dto;
|
const { id, description, dateTimeOriginal, latitude, longitude } = dto;
|
||||||
|
const writes = _.omitBy({ description, dateTimeOriginal, latitude, longitude }, _.isUndefined);
|
||||||
if (description !== undefined) {
|
|
||||||
await this.assetRepository.upsertExif({ assetId: id, description });
|
|
||||||
}
|
|
||||||
|
|
||||||
const writes = _.omitBy({ dateTimeOriginal, latitude, longitude }, _.isUndefined);
|
|
||||||
if (Object.keys(writes).length > 0) {
|
if (Object.keys(writes).length > 0) {
|
||||||
|
await this.assetRepository.upsertExif({ assetId: id, ...writes });
|
||||||
await this.jobRepository.queue({ name: JobName.SIDECAR_WRITE, data: { id, ...writes } });
|
await this.jobRepository.queue({ name: JobName.SIDECAR_WRITE, data: { id, ...writes } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export interface IDeleteFilesJob extends IBaseJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ISidecarWriteJob extends IEntityJob {
|
export interface ISidecarWriteJob extends IEntityJob {
|
||||||
|
description?: string;
|
||||||
dateTimeOriginal?: string;
|
dateTimeOriginal?: string;
|
||||||
latitude?: number;
|
latitude?: number;
|
||||||
longitude?: number;
|
longitude?: number;
|
||||||
|
|||||||
@@ -253,15 +253,16 @@ export class MetadataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleSidecarWrite(job: ISidecarWriteJob) {
|
async handleSidecarWrite(job: ISidecarWriteJob) {
|
||||||
const { id, dateTimeOriginal, latitude, longitude } = job;
|
const { id, description, dateTimeOriginal, latitude, longitude } = job;
|
||||||
const asset = await this.assetRepository.getById(id);
|
const asset = await this.assetRepository.getById(id);
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sidecarPath = asset.sidecarPath || `${asset.originalPath}.xmp`;
|
const sidecarPath = asset.sidecarPath || `${asset.originalPath}.xmp`;
|
||||||
const exif = _.omitBy(
|
const exif = _.omitBy<Tags>(
|
||||||
{
|
{
|
||||||
|
ImageDescription: description,
|
||||||
CreationDate: dateTimeOriginal,
|
CreationDate: dateTimeOriginal,
|
||||||
GPSLatitude: latitude,
|
GPSLatitude: latitude,
|
||||||
GPSLongitude: longitude,
|
GPSLongitude: longitude,
|
||||||
|
|||||||
@@ -700,6 +700,54 @@ describe(`${AssetController.name} (e2e)`, () => {
|
|||||||
expect(status).toEqual(200);
|
expect(status).toEqual(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should update date time original', async () => {
|
||||||
|
const { status, body } = await request(server)
|
||||||
|
.put(`/asset/${asset1.id}`)
|
||||||
|
.set('Authorization', `Bearer ${user1.accessToken}`)
|
||||||
|
.send({ dateTimeOriginal: '2023-11-19T18:11:00.000-07:00' });
|
||||||
|
|
||||||
|
expect(body).toMatchObject({
|
||||||
|
id: asset1.id,
|
||||||
|
exifInfo: expect.objectContaining({ dateTimeOriginal: '2023-11-20T01:11:00.000Z' }),
|
||||||
|
});
|
||||||
|
expect(status).toEqual(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject invalid gps coordinates', async () => {
|
||||||
|
for (const test of [
|
||||||
|
{ latitude: 12 },
|
||||||
|
{ longitude: 12 },
|
||||||
|
{ latitude: 12, longitude: 'abc' },
|
||||||
|
{ latitude: 'abc', longitude: 12 },
|
||||||
|
{ latitude: null, longitude: 12 },
|
||||||
|
{ latitude: 12, longitude: null },
|
||||||
|
{ latitude: 91, longitude: 12 },
|
||||||
|
{ latitude: -91, longitude: 12 },
|
||||||
|
{ latitude: 12, longitude: -181 },
|
||||||
|
{ latitude: 12, longitude: 181 },
|
||||||
|
]) {
|
||||||
|
const { status, body } = await request(server)
|
||||||
|
.put(`/asset/${asset1.id}`)
|
||||||
|
.send(test)
|
||||||
|
.set('Authorization', `Bearer ${user1.accessToken}`);
|
||||||
|
expect(status).toBe(400);
|
||||||
|
expect(body).toEqual(errorStub.badRequest());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update gps data', async () => {
|
||||||
|
const { status, body } = await request(server)
|
||||||
|
.put(`/asset/${asset1.id}`)
|
||||||
|
.set('Authorization', `Bearer ${user1.accessToken}`)
|
||||||
|
.send({ latitude: 12, longitude: 12 });
|
||||||
|
|
||||||
|
expect(body).toMatchObject({
|
||||||
|
id: asset1.id,
|
||||||
|
exifInfo: expect.objectContaining({ latitude: 12, longitude: 12 }),
|
||||||
|
});
|
||||||
|
expect(status).toEqual(200);
|
||||||
|
});
|
||||||
|
|
||||||
it('should set the description', async () => {
|
it('should set the description', async () => {
|
||||||
const { status, body } = await request(server)
|
const { status, body } = await request(server)
|
||||||
.put(`/asset/${asset1.id}`)
|
.put(`/asset/${asset1.id}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user