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:
+19
-46
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "immich-core",
|
"name": "immich-core",
|
||||||
"version": "2.0.1",
|
"version": "2.4.1 ",
|
||||||
"title": "Immich Core",
|
"title": "Immich Core",
|
||||||
"description": "Core workflow capabilities for Immich",
|
"description": "Core workflow capabilities for Immich",
|
||||||
"author": "Immich Team",
|
"author": "Immich Team",
|
||||||
@@ -12,9 +12,7 @@
|
|||||||
"methodName": "filterFileName",
|
"methodName": "filterFileName",
|
||||||
"title": "Filter by filename",
|
"title": "Filter by filename",
|
||||||
"description": "Filter assets by filename pattern using text matching or regular expressions",
|
"description": "Filter assets by filename pattern using text matching or regular expressions",
|
||||||
"supportedContexts": [
|
"supportedContexts": ["asset"],
|
||||||
"asset"
|
|
||||||
],
|
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -26,11 +24,7 @@
|
|||||||
"matchType": {
|
"matchType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"title": "Match type",
|
"title": "Match type",
|
||||||
"enum": [
|
"enum": ["contains", "regex", "exact"],
|
||||||
"contains",
|
|
||||||
"regex",
|
|
||||||
"exact"
|
|
||||||
],
|
|
||||||
"default": "contains",
|
"default": "contains",
|
||||||
"description": "Type of pattern matching to perform"
|
"description": "Type of pattern matching to perform"
|
||||||
},
|
},
|
||||||
@@ -40,18 +34,14 @@
|
|||||||
"description": "Whether matching should be case-sensitive"
|
"description": "Whether matching should be case-sensitive"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["pattern"]
|
||||||
"pattern"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"methodName": "filterFileType",
|
"methodName": "filterFileType",
|
||||||
"title": "Filter by file type",
|
"title": "Filter by file type",
|
||||||
"description": "Filter assets by file type",
|
"description": "Filter assets by file type",
|
||||||
"supportedContexts": [
|
"supportedContexts": ["asset"],
|
||||||
"asset"
|
|
||||||
],
|
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -60,26 +50,19 @@
|
|||||||
"title": "File types",
|
"title": "File types",
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": ["image", "video"]
|
||||||
"image",
|
|
||||||
"video"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"description": "Allowed file types"
|
"description": "Allowed file types"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["fileTypes"]
|
||||||
"fileTypes"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"methodName": "filterPerson",
|
"methodName": "filterPerson",
|
||||||
"title": "Filter by person",
|
"title": "Filter by person",
|
||||||
"description": "Filter by detected person",
|
"description": "Filter assets by detected people in the photo",
|
||||||
"supportedContexts": [
|
"supportedContexts": ["person"],
|
||||||
"person"
|
|
||||||
],
|
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -92,15 +75,14 @@
|
|||||||
"description": "List of person to match",
|
"description": "List of person to match",
|
||||||
"subType": "people-picker"
|
"subType": "people-picker"
|
||||||
},
|
},
|
||||||
"matchAny": {
|
"matchMode": {
|
||||||
"type": "boolean",
|
"type": "string",
|
||||||
"default": true,
|
"title": "Match mode",
|
||||||
"description": "Match any name (true) or require all names (false)"
|
"enum": ["any", "all", "exact"],
|
||||||
|
"default": "any"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["personIds"]
|
||||||
"personIds"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -109,18 +91,14 @@
|
|||||||
"methodName": "actionArchive",
|
"methodName": "actionArchive",
|
||||||
"title": "Archive",
|
"title": "Archive",
|
||||||
"description": "Move the asset to archive",
|
"description": "Move the asset to archive",
|
||||||
"supportedContexts": [
|
"supportedContexts": ["asset"],
|
||||||
"asset"
|
|
||||||
],
|
|
||||||
"schema": {}
|
"schema": {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"methodName": "actionFavorite",
|
"methodName": "actionFavorite",
|
||||||
"title": "Favorite",
|
"title": "Favorite",
|
||||||
"description": "Mark the asset as favorite or unfavorite",
|
"description": "Mark the asset as favorite or unfavorite",
|
||||||
"supportedContexts": [
|
"supportedContexts": ["asset"],
|
||||||
"asset"
|
|
||||||
],
|
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -136,10 +114,7 @@
|
|||||||
"methodName": "actionAddToAlbum",
|
"methodName": "actionAddToAlbum",
|
||||||
"title": "Add to Album",
|
"title": "Add to Album",
|
||||||
"description": "Add the item to a specified album",
|
"description": "Add the item to a specified album",
|
||||||
"supportedContexts": [
|
"supportedContexts": ["asset", "person"],
|
||||||
"asset",
|
|
||||||
"person"
|
|
||||||
],
|
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -150,9 +125,7 @@
|
|||||||
"subType": "album-picker"
|
"subType": "album-picker"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["albumId"]
|
||||||
"albumId"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Vendored
+1
@@ -1,5 +1,6 @@
|
|||||||
declare module 'main' {
|
declare module 'main' {
|
||||||
export function filterFileName(): I32;
|
export function filterFileName(): I32;
|
||||||
|
export function filterPerson(): I32;
|
||||||
export function actionAddToAlbum(): I32;
|
export function actionAddToAlbum(): I32;
|
||||||
export function actionArchive(): I32;
|
export function actionArchive(): I32;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,42 @@ function returnOutput(output: any) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function filterPerson() {
|
||||||
|
const input = parseInput();
|
||||||
|
|
||||||
|
const { data, config } = input;
|
||||||
|
const { personIds, matchMode } = config;
|
||||||
|
|
||||||
|
const faces = data.faces || [];
|
||||||
|
|
||||||
|
if (faces.length === 0) {
|
||||||
|
return returnOutput({ passed: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
const assetPersonIds: string[] = faces
|
||||||
|
.filter((face: { personId: string | null }) => face.personId !== null)
|
||||||
|
.map((face: { personId: string }) => face.personId);
|
||||||
|
|
||||||
|
let passed = false;
|
||||||
|
|
||||||
|
if (!personIds || personIds.length === 0) {
|
||||||
|
passed = true;
|
||||||
|
} else if (matchMode === 'any') {
|
||||||
|
passed = personIds.some((id: string) => assetPersonIds.includes(id));
|
||||||
|
} else if (matchMode === 'all') {
|
||||||
|
passed = personIds.every((id: string) => assetPersonIds.includes(id));
|
||||||
|
} else if (matchMode === 'exact') {
|
||||||
|
const uniquePersonIds = new Set(personIds);
|
||||||
|
const uniqueAssetPersonIds = new Set(assetPersonIds);
|
||||||
|
|
||||||
|
passed =
|
||||||
|
uniquePersonIds.size === uniqueAssetPersonIds.size &&
|
||||||
|
personIds.every((id: string) => uniqueAssetPersonIds.has(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnOutput({ passed });
|
||||||
|
}
|
||||||
|
|
||||||
export function filterFileName() {
|
export function filterFileName() {
|
||||||
const input = parseInput();
|
const input = parseInput();
|
||||||
const { data, config } = input;
|
const { data, config } = input;
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ select
|
|||||||
"asset_face"."id",
|
"asset_face"."id",
|
||||||
"asset_face"."personId",
|
"asset_face"."personId",
|
||||||
"asset_face"."sourceType",
|
"asset_face"."sourceType",
|
||||||
|
"asset_face"."assetId",
|
||||||
(
|
(
|
||||||
select
|
select
|
||||||
to_json(obj)
|
to_json(obj)
|
||||||
|
|||||||
@@ -318,6 +318,7 @@ export class AlbumRepository {
|
|||||||
await db
|
await db
|
||||||
.insertInto('album_asset')
|
.insertInto('album_asset')
|
||||||
.values(assetIds.map((assetId) => ({ albumId, assetId })))
|
.values(assetIds.map((assetId) => ({ albumId, assetId })))
|
||||||
|
.onConflict((oc) => oc.columns(['albumId', 'assetId']).doNothing())
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +327,11 @@ export class AlbumRepository {
|
|||||||
if (values.length === 0) {
|
if (values.length === 0) {
|
||||||
return;
|
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
|
// asset events
|
||||||
AssetCreate: [{ asset: Asset }];
|
AssetCreate: [{ asset: Asset }];
|
||||||
|
PersonRecognized: [{ assetId: string; ownerId: string; personId: string }];
|
||||||
AssetTag: [{ assetId: string }];
|
AssetTag: [{ assetId: string }];
|
||||||
AssetUntag: [{ assetId: string }];
|
AssetUntag: [{ assetId: string }];
|
||||||
AssetHide: [{ assetId: string; userId: string }];
|
AssetHide: [{ assetId: string; userId: string }];
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ export class PersonRepository {
|
|||||||
getFaceForFacialRecognitionJob(id: string) {
|
getFaceForFacialRecognitionJob(id: string) {
|
||||||
return this.db
|
return this.db
|
||||||
.selectFrom('asset_face')
|
.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) =>
|
.select((eb) =>
|
||||||
jsonObjectFrom(
|
jsonObjectFrom(
|
||||||
eb
|
eb
|
||||||
|
|||||||
@@ -536,6 +536,12 @@ export class PersonService extends BaseService {
|
|||||||
if (personId) {
|
if (personId) {
|
||||||
this.logger.debug(`Assigning face ${id} to person ${personId}`);
|
this.logger.debug(`Assigning face ${id} to person ${personId}`);
|
||||||
await this.personRepository.reassignFaces({ faceIds: [id], newPersonId: 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;
|
return JobStatus.Success;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { IWorkflowJob, JobItem, JobOf, WorkflowData } from 'src/types';
|
|||||||
interface WorkflowContext {
|
interface WorkflowContext {
|
||||||
authToken: string;
|
authToken: string;
|
||||||
asset: Asset;
|
asset: Asset;
|
||||||
|
faces?: { faceId: string; personId: string | null }[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PluginInput<T = unknown> {
|
interface PluginInput<T = unknown> {
|
||||||
@@ -24,6 +25,7 @@ interface PluginInput<T = unknown> {
|
|||||||
config: T;
|
config: T;
|
||||||
data: {
|
data: {
|
||||||
asset: Asset;
|
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> {
|
private async loadPluginToDatabase(manifest: PluginManifestDto, basePath: string): Promise<void> {
|
||||||
const currentPlugin = await this.pluginRepository.getPluginByName(manifest.name);
|
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`);
|
this.logger.log(`Plugin ${manifest.name} is up to date (version ${manifest.version}). Skipping`);
|
||||||
return;
|
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>(
|
private async handleTrigger<T extends PluginTriggerType>(
|
||||||
triggerType: T,
|
triggerType: T,
|
||||||
params: { ownerId: string; event: WorkflowData[T] },
|
params: { ownerId: string; event: WorkflowData[T] },
|
||||||
@@ -230,13 +242,41 @@ export class PluginService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.executeActions(workflowActions, context);
|
await this.executeActions(workflowActions, context);
|
||||||
this.logger.debug(`Workflow ${workflowId} executed successfully`);
|
this.logger.debug(`Workflow ${workflowId} executed successfully for AssetCreate`);
|
||||||
return JobStatus.Success;
|
return JobStatus.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PluginTriggerType.PersonRecognized: {
|
case PluginTriggerType.PersonRecognized: {
|
||||||
this.logger.error('unimplemented');
|
const data = event as WorkflowData[PluginTriggerType.PersonRecognized];
|
||||||
return JobStatus.Skipped;
|
|
||||||
|
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: {
|
default: {
|
||||||
@@ -269,6 +309,7 @@ export class PluginService extends BaseService {
|
|||||||
config: workflowFilter.filterConfig,
|
config: workflowFilter.filterConfig,
|
||||||
data: {
|
data: {
|
||||||
asset: context.asset,
|
asset: context.asset,
|
||||||
|
faces: context.faces,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -265,8 +265,9 @@ export interface WorkflowData {
|
|||||||
asset: Asset;
|
asset: Asset;
|
||||||
};
|
};
|
||||||
[PluginTriggerType.PersonRecognized]: {
|
[PluginTriggerType.PersonRecognized]: {
|
||||||
personId: string;
|
userId: string;
|
||||||
assetId: string;
|
assetId: string;
|
||||||
|
personId: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user