Compare commits

..

1 Commits

Author SHA1 Message Date
Jason Rasmussen
d268bc59af refactor(web): person service actions 2026-01-20 17:39:12 -05:00
12 changed files with 168 additions and 184 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "immich-core",
"version": "2.4.1 ",
"version": "2.0.1",
"title": "Immich Core",
"description": "Core workflow capabilities for Immich",
"author": "Immich Team",
@@ -12,7 +12,9 @@
"methodName": "filterFileName",
"title": "Filter by filename",
"description": "Filter assets by filename pattern using text matching or regular expressions",
"supportedContexts": ["asset"],
"supportedContexts": [
"asset"
],
"schema": {
"type": "object",
"properties": {
@@ -24,7 +26,11 @@
"matchType": {
"type": "string",
"title": "Match type",
"enum": ["contains", "regex", "exact"],
"enum": [
"contains",
"regex",
"exact"
],
"default": "contains",
"description": "Type of pattern matching to perform"
},
@@ -34,14 +40,18 @@
"description": "Whether matching should be case-sensitive"
}
},
"required": ["pattern"]
"required": [
"pattern"
]
}
},
{
"methodName": "filterFileType",
"title": "Filter by file type",
"description": "Filter assets by file type",
"supportedContexts": ["asset"],
"supportedContexts": [
"asset"
],
"schema": {
"type": "object",
"properties": {
@@ -50,19 +60,26 @@
"title": "File types",
"items": {
"type": "string",
"enum": ["image", "video"]
"enum": [
"image",
"video"
]
},
"description": "Allowed file types"
}
},
"required": ["fileTypes"]
"required": [
"fileTypes"
]
}
},
{
"methodName": "filterPerson",
"title": "Filter by person",
"description": "Filter assets by detected people in the photo",
"supportedContexts": ["person"],
"description": "Filter by detected person",
"supportedContexts": [
"person"
],
"schema": {
"type": "object",
"properties": {
@@ -75,14 +92,15 @@
"description": "List of person to match",
"subType": "people-picker"
},
"matchMode": {
"type": "string",
"title": "Match mode",
"enum": ["any", "all", "exact"],
"default": "any"
"matchAny": {
"type": "boolean",
"default": true,
"description": "Match any name (true) or require all names (false)"
}
},
"required": ["personIds"]
"required": [
"personIds"
]
}
}
],
@@ -91,14 +109,18 @@
"methodName": "actionArchive",
"title": "Archive",
"description": "Move the asset to archive",
"supportedContexts": ["asset"],
"supportedContexts": [
"asset"
],
"schema": {}
},
{
"methodName": "actionFavorite",
"title": "Favorite",
"description": "Mark the asset as favorite or unfavorite",
"supportedContexts": ["asset"],
"supportedContexts": [
"asset"
],
"schema": {
"type": "object",
"properties": {
@@ -114,7 +136,10 @@
"methodName": "actionAddToAlbum",
"title": "Add to Album",
"description": "Add the item to a specified album",
"supportedContexts": ["asset", "person"],
"supportedContexts": [
"asset",
"person"
],
"schema": {
"type": "object",
"properties": {
@@ -125,7 +150,9 @@
"subType": "album-picker"
}
},
"required": ["albumId"]
"required": [
"albumId"
]
}
}
]

View File

@@ -1,6 +1,5 @@
declare module 'main' {
export function filterFileName(): I32;
export function filterPerson(): I32;
export function actionAddToAlbum(): I32;
export function actionArchive(): I32;
}

View File

@@ -9,42 +9,6 @@ function returnOutput(output: any) {
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() {
const input = parseInput();
const { data, config } = input;

View File

@@ -122,7 +122,6 @@ select
"asset_face"."id",
"asset_face"."personId",
"asset_face"."sourceType",
"asset_face"."assetId",
(
select
to_json(obj)

View File

@@ -318,7 +318,6 @@ export class AlbumRepository {
await db
.insertInto('album_asset')
.values(assetIds.map((assetId) => ({ albumId, assetId })))
.onConflict((oc) => oc.columns(['albumId', 'assetId']).doNothing())
.execute();
}
@@ -327,11 +326,7 @@ export class AlbumRepository {
if (values.length === 0) {
return;
}
await this.db
.insertInto('album_asset')
.values(values)
.onConflict((oc) => oc.columns(['albumId', 'assetId']).doNothing())
.execute();
await this.db.insertInto('album_asset').values(values).execute();
}
/**

View File

@@ -44,7 +44,6 @@ 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 }];

View File

@@ -248,7 +248,7 @@ export class PersonRepository {
getFaceForFacialRecognitionJob(id: string) {
return this.db
.selectFrom('asset_face')
.select(['asset_face.id', 'asset_face.personId', 'asset_face.sourceType', 'asset_face.assetId'])
.select(['asset_face.id', 'asset_face.personId', 'asset_face.sourceType'])
.select((eb) =>
jsonObjectFrom(
eb

View File

@@ -540,12 +540,6 @@ 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;

View File

@@ -17,7 +17,6 @@ import { IWorkflowJob, JobItem, JobOf, WorkflowData } from 'src/types';
interface WorkflowContext {
authToken: string;
asset: Asset;
faces?: { faceId: string; personId: string | null }[];
}
interface PluginInput<T = unknown> {
@@ -25,7 +24,6 @@ interface PluginInput<T = unknown> {
config: T;
data: {
asset: Asset;
faces?: { faceId: string; personId: string | null }[];
};
}
@@ -119,9 +117,7 @@ export class PluginService extends BaseService {
private async loadPluginToDatabase(manifest: PluginManifestDto, basePath: string): Promise<void> {
const currentPlugin = await this.pluginRepository.getPluginByName(manifest.name);
const isDev = this.configRepository.isDev();
if (currentPlugin != null && currentPlugin.version === manifest.version && !isDev) {
if (currentPlugin != null && currentPlugin.version === manifest.version) {
this.logger.log(`Plugin ${manifest.name} is up to date (version ${manifest.version}). Skipping`);
return;
}
@@ -182,14 +178,6 @@ 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] },
@@ -242,41 +230,13 @@ export class PluginService extends BaseService {
}
await this.executeActions(workflowActions, context);
this.logger.debug(`Workflow ${workflowId} executed successfully for AssetCreate`);
this.logger.debug(`Workflow ${workflowId} executed successfully`);
return JobStatus.Success;
}
case PluginTriggerType.PersonRecognized: {
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;
this.logger.error('unimplemented');
return JobStatus.Skipped;
}
default: {
@@ -309,7 +269,6 @@ export class PluginService extends BaseService {
config: workflowFilter.filterConfig,
data: {
asset: context.asset,
faces: context.faces,
},
};

View File

@@ -259,9 +259,8 @@ export interface WorkflowData {
asset: Asset;
};
[PluginTriggerType.PersonRecognized]: {
userId: string;
assetId: string;
personId: string;
assetId: string;
};
}

View File

@@ -4,7 +4,13 @@ import { handleError } from '$lib/utils/handle-error';
import { getFormatter } from '$lib/utils/i18n';
import { updatePerson, type PersonResponseDto } from '@immich/sdk';
import { modalManager, toastManager, type ActionItem } from '@immich/ui';
import { mdiCalendarEditOutline } from '@mdi/js';
import {
mdiCalendarEditOutline,
mdiEyeOffOutline,
mdiEyeOutline,
mdiHeartMinusOutline,
mdiHeartOutline,
} from '@mdi/js';
import type { MessageFormatter } from 'svelte-i18n';
export const getPersonActions = ($t: MessageFormatter, person: PersonResponseDto) => {
@@ -14,7 +20,83 @@ export const getPersonActions = ($t: MessageFormatter, person: PersonResponseDto
onAction: () => modalManager.show(PersonEditBirthDateModal, { person }),
};
return { SetDateOfBirth };
const Favorite: ActionItem = {
title: $t('to_favorite'),
icon: mdiHeartOutline,
$if: () => !person.isFavorite,
onAction: () => handleFavoritePerson(person),
};
const Unfavorite: ActionItem = {
title: $t('unfavorite'),
icon: mdiHeartMinusOutline,
$if: () => !!person.isFavorite,
onAction: () => handleUnfavoritePerson(person),
};
const HidePerson: ActionItem = {
title: $t('hide_person'),
icon: mdiEyeOffOutline,
$if: () => !person.isHidden,
onAction: () => handleHidePerson(person),
};
const ShowPerson: ActionItem = {
title: $t('unhide_person'),
icon: mdiEyeOutline,
$if: () => !!person.isHidden,
onAction: () => handleShowPerson(person),
};
return { SetDateOfBirth, Favorite, Unfavorite, HidePerson, ShowPerson };
};
const handleFavoritePerson = async (person: { id: string }) => {
const $t = await getFormatter();
try {
const response = await updatePerson({ id: person.id, personUpdateDto: { isFavorite: true } });
eventManager.emit('PersonUpdate', response);
toastManager.success($t('added_to_favorites'));
} catch (error) {
handleError(error, $t('errors.unable_to_add_remove_favorites', { values: { favorite: false } }));
}
};
const handleUnfavoritePerson = async (person: { id: string }) => {
const $t = await getFormatter();
try {
const response = await updatePerson({ id: person.id, personUpdateDto: { isFavorite: false } });
eventManager.emit('PersonUpdate', response);
toastManager.success($t('removed_from_favorites'));
} catch (error) {
handleError(error, $t('errors.unable_to_add_remove_favorites', { values: { favorite: false } }));
}
};
const handleHidePerson = async (person: { id: string }) => {
const $t = await getFormatter();
try {
const response = await updatePerson({ id: person.id, personUpdateDto: { isHidden: true } });
toastManager.success($t('changed_visibility_successfully'));
eventManager.emit('PersonUpdate', response);
} catch (error) {
handleError(error, $t('errors.unable_to_hide_person'));
}
};
const handleShowPerson = async (person: { id: string }) => {
const $t = await getFormatter();
try {
const response = await updatePerson({ id: person.id, personUpdateDto: { isHidden: false } });
toastManager.success($t('changed_visibility_successfully'));
eventManager.emit('PersonUpdate', response);
} catch (error) {
handleError(error, $t('errors.something_went_wrong'));
}
};
export const handleUpdatePersonBirthDate = async (person: PersonResponseDto, birthDate: string) => {

View File

@@ -4,7 +4,6 @@
import { clickOutside } from '$lib/actions/click-outside';
import { listNavigation } from '$lib/actions/list-navigation';
import { scrollMemoryClearer } from '$lib/actions/scroll-memory';
import ActionMenuItem from '$lib/components/ActionMenuItem.svelte';
import ImageThumbnail from '$lib/components/assets/thumbnail/image-thumbnail.svelte';
import EditNameInput from '$lib/components/faces-page/edit-name-input.svelte';
import MergeFaceSelector from '$lib/components/faces-page/merge-face-selector.svelte';
@@ -42,16 +41,12 @@
import { handleError } from '$lib/utils/handle-error';
import { isExternalUrl } from '$lib/utils/navigation';
import { AssetVisibility, searchPerson, updatePerson, type PersonResponseDto } from '@immich/sdk';
import { LoadingSpinner, modalManager, toastManager } from '@immich/ui';
import { ContextMenuButton, LoadingSpinner, modalManager, toastManager, type ActionItem } from '@immich/ui';
import {
mdiAccountBoxOutline,
mdiAccountMultipleCheckOutline,
mdiArrowLeft,
mdiDotsVertical,
mdiEyeOffOutline,
mdiEyeOutline,
mdiHeartMinusOutline,
mdiHeartOutline,
mdiPlus,
} from '@mdi/js';
import { DateTime } from 'luxon';
@@ -144,37 +139,6 @@
viewMode = PersonPageViewMode.UNASSIGN_ASSETS;
};
const toggleHidePerson = async () => {
try {
await updatePerson({
id: person.id,
personUpdateDto: { isHidden: !person.isHidden },
});
toastManager.success($t('changed_visibility_successfully'));
await goto(previousRoute);
} catch (error) {
handleError(error, $t('errors.unable_to_hide_person'));
}
};
const handleToggleFavorite = async () => {
try {
const updatedPerson = await updatePerson({
id: person.id,
personUpdateDto: { isFavorite: !person.isFavorite },
});
// Invalidate to reload the page data and have the favorite status updated
await invalidateAll();
toastManager.success(updatedPerson.isFavorite ? $t('added_to_favorites') : $t('removed_from_favorites'));
} catch (error) {
handleError(error, $t('errors.unable_to_add_remove_favorites', { values: { favorite: person.isFavorite } }));
}
};
const handleMerge = async (person: PersonResponseDto) => {
await updateAssetCount();
await handleGoBack();
@@ -325,13 +289,35 @@
assetInteraction.clearMultiselect();
};
const onPersonUpdate = (response: PersonResponseDto) => {
if (person.id === response.id) {
return (person = response);
const onPersonUpdate = async (response: PersonResponseDto) => {
if (response.id !== person.id) {
return;
}
if (response.isHidden) {
await goto(previousRoute);
return;
}
person = response;
};
const { SetDateOfBirth } = $derived(getPersonActions($t, person));
const { SetDateOfBirth, Favorite, Unfavorite, HidePerson, ShowPerson } = $derived(getPersonActions($t, person));
const SelectFeaturePhoto: ActionItem = {
title: $t('select_featured_photo'),
icon: mdiAccountBoxOutline,
onAction: () => {
viewMode = PersonPageViewMode.SELECT_PERSON;
},
};
const Merge: ActionItem = {
title: $t('merge_people'),
icon: mdiAccountMultipleCheckOutline,
onAction: () => {
viewMode = PersonPageViewMode.MERGE_PEOPLE;
},
};
</script>
<OnEvents {onPersonUpdate} onAssetsDelete={updateAssetCount} onAssetsArchive={updateAssetCount} />
@@ -507,29 +493,10 @@
{#if viewMode === PersonPageViewMode.VIEW_ASSETS}
<ControlAppBar showBackButton backIcon={mdiArrowLeft} onClose={() => goto(previousRoute)}>
{#snippet trailing()}
<ButtonContextMenu icon={mdiDotsVertical} title={$t('menu')}>
<MenuOption
text={$t('select_featured_photo')}
icon={mdiAccountBoxOutline}
onClick={() => (viewMode = PersonPageViewMode.SELECT_PERSON)}
/>
<MenuOption
text={person.isHidden ? $t('unhide_person') : $t('hide_person')}
icon={person.isHidden ? mdiEyeOutline : mdiEyeOffOutline}
onClick={() => toggleHidePerson()}
/>
<ActionMenuItem action={SetDateOfBirth} />
<MenuOption
text={$t('merge_people')}
icon={mdiAccountMultipleCheckOutline}
onClick={() => (viewMode = PersonPageViewMode.MERGE_PEOPLE)}
/>
<MenuOption
icon={person.isFavorite ? mdiHeartMinusOutline : mdiHeartOutline}
text={person.isFavorite ? $t('unfavorite') : $t('to_favorite')}
onClick={handleToggleFavorite}
/>
</ButtonContextMenu>
<ContextMenuButton
items={[SelectFeaturePhoto, HidePerson, ShowPerson, SetDateOfBirth, Merge, Favorite, Unfavorite]}
aria-label={$t('open')}
/>
{/snippet}
</ControlAppBar>
{/if}