mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
fix: asset type filter (#29190)
This commit is contained in:
parent
40cffcd414
commit
53fe26593c
4 changed files with 41 additions and 10 deletions
|
|
@ -184,22 +184,22 @@
|
|||
"uiHints": ["Filter"]
|
||||
},
|
||||
{
|
||||
"name": "filterFileType",
|
||||
"title": "Filter by file type",
|
||||
"description": "Filter assets by file type",
|
||||
"name": "assetTypeFilter",
|
||||
"title": "Filter by asset type",
|
||||
"description": "Filter assets by type",
|
||||
"types": ["AssetV1"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"fileTypes": {
|
||||
"title": "File types",
|
||||
"description": "Allowed file types",
|
||||
"allowedTypes": {
|
||||
"title": "Asset types",
|
||||
"description": "Allowed asset types",
|
||||
"type": "string",
|
||||
"array": true,
|
||||
"enum": ["image", "video"]
|
||||
"enum": ["IMAGE", "VIDEO", "AUDIO", "OTHER"]
|
||||
}
|
||||
},
|
||||
"required": ["fileTypes"]
|
||||
"required": ["types"]
|
||||
},
|
||||
"uiHints": ["Filter"]
|
||||
},
|
||||
|
|
|
|||
1
packages/plugin-core/src/index.d.ts
vendored
1
packages/plugin-core/src/index.d.ts
vendored
|
|
@ -14,6 +14,7 @@ declare module 'main' {
|
|||
export function assetFileFilter(): I32;
|
||||
export function assetMissingTimeZoneFilter(): I32;
|
||||
export function assetLocationFilter(): I32;
|
||||
export function assetTypeFilter(): I32;
|
||||
|
||||
// updates
|
||||
export function assetFavorite(): I32;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { wrapper } from '@immich/plugin-sdk';
|
||||
import { AssetVisibility, WorkflowType } from '@immich/sdk';
|
||||
import { AssetTypeEnum, AssetVisibility, WorkflowType } from '@immich/sdk';
|
||||
|
||||
type AssetFileFilterConfig = {
|
||||
pattern: string;
|
||||
|
|
@ -95,6 +95,12 @@ export const assetLocationFilter = () => {
|
|||
});
|
||||
};
|
||||
|
||||
export const assetTypeFilter = () => {
|
||||
return wrapper<WorkflowType.AssetV1, { allowedTypes: AssetTypeEnum[] }>(({ config, data }) => {
|
||||
return { workflow: { continue: config.allowedTypes.includes(data.asset.type) } };
|
||||
});
|
||||
};
|
||||
|
||||
export const assetFavorite = () => {
|
||||
return wrapper<WorkflowType.AssetV1, { inverse?: boolean }>(({ config, data }) => {
|
||||
const target = config.inverse ? false : true;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { WorkflowStepConfig, WorkflowTrigger } from '@immich/plugin-sdk';
|
|||
import { Kysely } from 'kysely';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { PluginManifestDto } from 'src/dtos/plugin-manifest.dto';
|
||||
import { AssetVisibility, LogLevel } from 'src/enum';
|
||||
import { AssetType, AssetVisibility, LogLevel } from 'src/enum';
|
||||
import { AccessRepository } from 'src/repositories/access.repository';
|
||||
import { AlbumRepository } from 'src/repositories/album.repository';
|
||||
import { AssetRepository } from 'src/repositories/asset.repository';
|
||||
|
|
@ -403,4 +403,28 @@ describe('core plugin', () => {
|
|||
await expect(ctx.get(AssetRepository).getById(asset.id)).resolves.toMatchObject({ isFavorite: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe('assetTypeFilter', () => {
|
||||
it('should favorite asset if it is a video', async () => {
|
||||
const { user } = await ctx.newUser();
|
||||
const { asset } = await ctx.newAsset({ ownerId: user.id, type: AssetType.Video });
|
||||
|
||||
const workflow = await createWorkflow({
|
||||
ownerId: user.id,
|
||||
trigger: WorkflowTrigger.AssetCreate,
|
||||
steps: [
|
||||
{
|
||||
method: 'immich-plugin-core#assetTypeFilter',
|
||||
config: { allowedTypes: ['VIDEO'] },
|
||||
},
|
||||
{
|
||||
method: 'immich-plugin-core#assetFavorite',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await expect(ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset.id })).resolves.toBeUndefined();
|
||||
await expect(ctx.get(AssetRepository).getById(asset.id)).resolves.toMatchObject({ isFavorite: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue