mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
feat: filter by person
This commit is contained in:
@@ -119,6 +119,7 @@ select
|
||||
"asset_face"."id",
|
||||
"asset_face"."personId",
|
||||
"asset_face"."sourceType",
|
||||
"asset_face"."assetId",
|
||||
(
|
||||
select
|
||||
to_json(obj)
|
||||
|
||||
@@ -318,6 +318,7 @@ export class AlbumRepository {
|
||||
await db
|
||||
.insertInto('album_asset')
|
||||
.values(assetIds.map((assetId) => ({ albumId, assetId })))
|
||||
.onConflict((oc) => oc.columns(['albumId', 'assetId']).doNothing())
|
||||
.execute();
|
||||
}
|
||||
|
||||
@@ -326,7 +327,11 @@ export class AlbumRepository {
|
||||
if (values.length === 0) {
|
||||
return;
|
||||
}
|
||||
await this.db.insertInto('album_asset').values(values).execute();
|
||||
await this.db
|
||||
.insertInto('album_asset')
|
||||
.values(values)
|
||||
.onConflict((oc) => oc.columns(['albumId', 'assetId']).doNothing())
|
||||
.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,6 +44,7 @@ type EventMap = {
|
||||
|
||||
// asset events
|
||||
AssetCreate: [{ asset: Asset }];
|
||||
PersonRecognized: [{ assetId: string; ownerId: string; personId: string }];
|
||||
AssetTag: [{ assetId: string }];
|
||||
AssetUntag: [{ assetId: string }];
|
||||
AssetHide: [{ assetId: string; userId: string }];
|
||||
|
||||
@@ -241,7 +241,7 @@ export class PersonRepository {
|
||||
getFaceForFacialRecognitionJob(id: string) {
|
||||
return this.db
|
||||
.selectFrom('asset_face')
|
||||
.select(['asset_face.id', 'asset_face.personId', 'asset_face.sourceType'])
|
||||
.select(['asset_face.id', 'asset_face.personId', 'asset_face.sourceType', 'asset_face.assetId'])
|
||||
.select((eb) =>
|
||||
jsonObjectFrom(
|
||||
eb
|
||||
|
||||
@@ -536,6 +536,12 @@ export class PersonService extends BaseService {
|
||||
if (personId) {
|
||||
this.logger.debug(`Assigning face ${id} to person ${personId}`);
|
||||
await this.personRepository.reassignFaces({ faceIds: [id], newPersonId: personId });
|
||||
|
||||
await this.eventRepository.emit('PersonRecognized', {
|
||||
assetId: face.assetId,
|
||||
ownerId: face.asset.ownerId,
|
||||
personId,
|
||||
});
|
||||
}
|
||||
|
||||
return JobStatus.Success;
|
||||
|
||||
@@ -17,6 +17,7 @@ import { IWorkflowJob, JobItem, JobOf, WorkflowData } from 'src/types';
|
||||
interface WorkflowContext {
|
||||
authToken: string;
|
||||
asset: Asset;
|
||||
faces?: { faceId: string; personId: string | null }[];
|
||||
}
|
||||
|
||||
interface PluginInput<T = unknown> {
|
||||
@@ -24,6 +25,7 @@ interface PluginInput<T = unknown> {
|
||||
config: T;
|
||||
data: {
|
||||
asset: Asset;
|
||||
faces?: { faceId: string; personId: string | null }[];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,7 +119,9 @@ export class PluginService extends BaseService {
|
||||
|
||||
private async loadPluginToDatabase(manifest: PluginManifestDto, basePath: string): Promise<void> {
|
||||
const currentPlugin = await this.pluginRepository.getPluginByName(manifest.name);
|
||||
if (currentPlugin != null && currentPlugin.version === manifest.version) {
|
||||
const isDev = this.configRepository.isDev();
|
||||
|
||||
if (currentPlugin != null && currentPlugin.version === manifest.version && !isDev) {
|
||||
this.logger.log(`Plugin ${manifest.name} is up to date (version ${manifest.version}). Skipping`);
|
||||
return;
|
||||
}
|
||||
@@ -178,6 +182,14 @@ export class PluginService extends BaseService {
|
||||
});
|
||||
}
|
||||
|
||||
@OnEvent({ name: 'PersonRecognized' })
|
||||
async handlePersonRecognized({ assetId, ownerId, personId }: ArgOf<'PersonRecognized'>) {
|
||||
await this.handleTrigger(PluginTriggerType.PersonRecognized, {
|
||||
ownerId,
|
||||
event: { userId: ownerId, assetId, personId },
|
||||
});
|
||||
}
|
||||
|
||||
private async handleTrigger<T extends PluginTriggerType>(
|
||||
triggerType: T,
|
||||
params: { ownerId: string; event: WorkflowData[T] },
|
||||
@@ -230,13 +242,41 @@ export class PluginService extends BaseService {
|
||||
}
|
||||
|
||||
await this.executeActions(workflowActions, context);
|
||||
this.logger.debug(`Workflow ${workflowId} executed successfully`);
|
||||
this.logger.debug(`Workflow ${workflowId} executed successfully for AssetCreate`);
|
||||
return JobStatus.Success;
|
||||
}
|
||||
|
||||
case PluginTriggerType.PersonRecognized: {
|
||||
this.logger.error('unimplemented');
|
||||
return JobStatus.Skipped;
|
||||
const data = event as WorkflowData[PluginTriggerType.PersonRecognized];
|
||||
|
||||
const asset = await this.assetRepository.getById(data.assetId);
|
||||
if (!asset) {
|
||||
this.logger.error(`Asset ${data.assetId} not found for workflow ${workflowId}`);
|
||||
return JobStatus.Failed;
|
||||
}
|
||||
|
||||
const authToken = this.cryptoRepository.signJwt({ userId: data.userId }, this.pluginJwtSecret);
|
||||
|
||||
const faces = await this.personRepository.getFaces(data.assetId);
|
||||
const facePayload = faces.map((face) => ({
|
||||
faceId: face.id,
|
||||
personId: face.personId,
|
||||
}));
|
||||
|
||||
const context = {
|
||||
authToken,
|
||||
asset,
|
||||
faces: facePayload,
|
||||
};
|
||||
|
||||
const filtersPassed = await this.executeFilters(workflowFilters, context);
|
||||
if (!filtersPassed) {
|
||||
return JobStatus.Skipped;
|
||||
}
|
||||
|
||||
await this.executeActions(workflowActions, context);
|
||||
this.logger.debug(`Workflow ${workflowId} executed successfully for PersonRecognized`);
|
||||
return JobStatus.Success;
|
||||
}
|
||||
|
||||
default: {
|
||||
@@ -269,6 +309,7 @@ export class PluginService extends BaseService {
|
||||
config: workflowFilter.filterConfig,
|
||||
data: {
|
||||
asset: context.asset,
|
||||
faces: context.faces,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
+2
-1
@@ -265,8 +265,9 @@ export interface WorkflowData {
|
||||
asset: Asset;
|
||||
};
|
||||
[PluginTriggerType.PersonRecognized]: {
|
||||
personId: string;
|
||||
userId: string;
|
||||
assetId: string;
|
||||
personId: string;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user