Skip to content

Commit

Permalink
don't add separate source
Browse files Browse the repository at this point in the history
  • Loading branch information
etnoy committed Dec 19, 2024
1 parent d0bb59f commit a542e87
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 35 deletions.
67 changes: 49 additions & 18 deletions e2e/src/api/specs/library.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,65 +406,93 @@ describe('/libraries', () => {
it('should reimport a modified file', async () => {
const library = await utils.createLibrary(admin.accessToken, {
ownerId: admin.userId,
importPaths: [`${testAssetDirInternal}/temp`],
importPaths: [`${testAssetDirInternal}/temp/reimport`],
});

utils.createImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_000);
utils.createImageFile(`${testAssetDir}/temp/reimport/asset.jpg`);
await utimes(`${testAssetDir}/temp/reimport/asset.jpg`, 447_775_200_000);

await scan(admin.accessToken, library.id);
await utils.waitForQueueFinish(admin.accessToken, 'library');
await utils.waitForQueueFinish(admin.accessToken, 'sidecar');
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');

cpSync(`${testAssetDir}/albums/nature/tanners_ridge.jpg`, `${testAssetDir}/temp/directoryA/assetB.jpg`);
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_001);
cpSync(`${testAssetDir}/albums/nature/tanners_ridge.jpg`, `${testAssetDir}/temp/reimport/asset.jpg`);
await utimes(`${testAssetDir}/temp/reimport/asset.jpg`, 447_775_200_001);

const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ refreshModifiedFiles: true });
.send();
expect(status).toBe(204);

await utils.waitForQueueFinish(admin.accessToken, 'library');
await utils.waitForQueueFinish(admin.accessToken, 'sidecar');
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');
utils.removeImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);

const { assets } = await utils.searchAssets(admin.accessToken, {
libraryId: library.id,
model: 'NIKON D750',
});
expect(assets.count).toBe(1);

expect(assets.count).toEqual(1);

const asset = await utils.getAssetInfo(admin.accessToken, assets.items[0].id);

expect(asset).toEqual(
expect.objectContaining({
originalFileName: 'asset.jpg',
exifInfo: expect.objectContaining({
model: 'NIKON D750',
}),
}),
);

utils.removeImageFile(`${testAssetDir}/temp/reimport/asset.jpg`);
});

it('should not reimport unmodified files', async () => {
const library = await utils.createLibrary(admin.accessToken, {
ownerId: admin.userId,
importPaths: [`${testAssetDirInternal}/temp`],
importPaths: [`${testAssetDirInternal}/temp/reimport`],
});

utils.createImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_000);
utils.createImageFile(`${testAssetDir}/temp/reimport/asset.jpg`);
await utimes(`${testAssetDir}/temp/reimport/asset.jpg`, 447_775_200_000);

await scan(admin.accessToken, library.id);
await utils.waitForQueueFinish(admin.accessToken, 'library');

cpSync(`${testAssetDir}/albums/nature/tanners_ridge.jpg`, `${testAssetDir}/temp/directoryA/assetB.jpg`);
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_000);
cpSync(`${testAssetDir}/albums/nature/tanners_ridge.jpg`, `${testAssetDir}/temp/reimport/asset.jpg`);
await utimes(`${testAssetDir}/temp/reimport/asset.jpg`, 447_775_200_000);

const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ refreshModifiedFiles: true });
.send();
expect(status).toBe(204);

await utils.waitForQueueFinish(admin.accessToken, 'library');
await utils.waitForQueueFinish(admin.accessToken, 'sidecar');
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');
utils.removeImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);

const { assets } = await utils.searchAssets(admin.accessToken, {
libraryId: library.id,
model: 'NIKON D750',
});
expect(assets.count).toBe(0);

expect(assets.count).toEqual(1);

const asset = await utils.getAssetInfo(admin.accessToken, assets.items[0].id);

expect(asset).toEqual(
expect.objectContaining({
originalFileName: 'asset.jpg',
exifInfo: expect.not.objectContaining({
model: 'NIKON D750',
}),
}),
);

utils.removeImageFile(`${testAssetDir}/temp/reimport/asset.jpg`);
});

it('should set an asset offline if its file is missing', async () => {
Expand Down Expand Up @@ -615,6 +643,7 @@ describe('/libraries', () => {
await scan(admin.accessToken, library.id);

await utils.waitForQueueFinish(admin.accessToken, 'library');
await utils.waitForQueueFinish(admin.accessToken, 'sidecar');
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');

const { assets: newAssets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });
Expand All @@ -641,6 +670,7 @@ describe('/libraries', () => {

await scan(admin.accessToken, library.id);
await utils.waitForQueueFinish(admin.accessToken, 'library');
await utils.waitForQueueFinish(admin.accessToken, 'sidecar');
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');

const { assets: newAssets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });
Expand Down Expand Up @@ -668,6 +698,7 @@ describe('/libraries', () => {

await scan(admin.accessToken, library.id);
await utils.waitForQueueFinish(admin.accessToken, 'library');
await utils.waitForQueueFinish(admin.accessToken, 'sidecar');
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');

const { assets: newAssets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });
Expand Down
2 changes: 1 addition & 1 deletion server/src/interfaces/job.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export interface IDelayedJob extends IBaseJob {

export interface IEntityJob extends IBaseJob {
id: string;
source?: 'upload' | 'library-import' | 'sidecar-write' | 'copy';
source?: 'upload' | 'sidecar-write' | 'copy';
notify?: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/services/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class JobService extends BaseService {
}

case JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE: {
if (item.data.source === 'upload' || item.data.source === 'copy' || item.data.source === 'library-import') {
if (item.data.source === 'upload' || item.data.source === 'copy') {
await this.jobRepository.queue({ name: JobName.GENERATE_THUMBNAILS, data: item.data });
}
break;
Expand All @@ -266,7 +266,7 @@ export class JobService extends BaseService {
}

case JobName.GENERATE_THUMBNAILS: {
if (!item.data.notify && item.data.source !== 'upload' && item.data.source === 'library-import') {
if (!item.data.notify && item.data.source !== 'upload') {
break;
}

Expand Down
6 changes: 2 additions & 4 deletions server/src/services/library.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,9 @@ describe(LibraryService.name, () => {
expect(jobMock.queue.mock.calls).toEqual([
[
{
name: JobName.METADATA_EXTRACTION,
name: JobName.SIDECAR_DISCOVERY,
data: {
id: assetStub.image.id,
source: 'upload',
},
},
],
Expand Down Expand Up @@ -467,10 +466,9 @@ describe(LibraryService.name, () => {
expect(jobMock.queue.mock.calls).toEqual([
[
{
name: JobName.METADATA_EXTRACTION,
name: JobName.SIDECAR_DISCOVERY,
data: {
id: assetStub.image.id,
source: 'upload',
},
},
],
Expand Down
5 changes: 3 additions & 2 deletions server/src/services/library.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,10 @@ export class LibraryService extends BaseService {
async queuePostSyncJobs(asset: AssetEntity) {
this.logger.debug(`Queueing metadata extraction for: ${asset.originalPath}`);

// We queue a sidecar discovery which, in turn, queues metadata extraction
await this.jobRepository.queue({
name: JobName.METADATA_EXTRACTION,
data: { id: asset.id, source: 'library-import' },
name: JobName.SIDECAR_DISCOVERY,
data: { id: asset.id },
});
}

Expand Down
12 changes: 5 additions & 7 deletions server/src/services/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,17 @@ export class MetadataService extends BaseService {
}

@OnJob({ name: JobName.METADATA_EXTRACTION, queue: QueueName.METADATA_EXTRACTION })
async handleMetadataExtraction({ id, source }: JobOf<JobName.METADATA_EXTRACTION>): Promise<JobStatus> {
async handleMetadataExtraction({ id }: JobOf<JobName.METADATA_EXTRACTION>): Promise<JobStatus> {
this.logger.verbose(`Extracting metadata for asset ${id}`);

const { metadata, reverseGeocoding } = await this.getConfig({ withCache: true });

if (source === 'library-import') {
await this.processSidecar(id, false);
}

const [asset] = await this.assetRepository.getByIds([id], { faces: { person: false } });

if (!asset) {
return JobStatus.FAILED;
}

this.logger.verbose(`Sidecar path: ${asset.sidecarPath}`);

const stats = await this.storageRepository.stat(asset.originalPath);

const exifTags = await this.getExifTags(asset);
Expand Down Expand Up @@ -736,6 +730,10 @@ export class MetadataService extends BaseService {
return JobStatus.SUCCESS;
}

if (asset.isExternal) {
return JobStatus.SKIPPED;
}

if (!isSync) {
return JobStatus.FAILED;
}
Expand Down

0 comments on commit a542e87

Please sign in to comment.