mirror of
https://github.com/immich-app/immich.git
synced 2026-07-15 21:32:32 +03:00
fix(server): workflow date filter, make end date inclusive (#29876)
Co-authored-by: Raul Plesa <raul.plesa@external.grifols.com> Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
This commit is contained in:
@@ -127,7 +127,7 @@ const methods = wrapper<Manifest>({
|
|||||||
assetDateFilter: ({ config, data }) => {
|
assetDateFilter: ({ config, data }) => {
|
||||||
const assetDate = new Date(data.asset.localDateTime);
|
const assetDate = new Date(data.asset.localDateTime);
|
||||||
let startDate = new Date(config.startDate.year, config.startDate.month - 1, config.startDate.day);
|
let startDate = new Date(config.startDate.year, config.startDate.month - 1, config.startDate.day);
|
||||||
let endDate = new Date(config.endDate.year, config.endDate.month - 1, config.endDate.day);
|
let endDate = new Date(config.endDate.year, config.endDate.month - 1, config.endDate.day + 1);
|
||||||
|
|
||||||
if (config.recurring) {
|
if (config.recurring) {
|
||||||
startDate.setFullYear(assetDate.getFullYear());
|
startDate.setFullYear(assetDate.getFullYear());
|
||||||
@@ -142,7 +142,7 @@ const methods = wrapper<Manifest>({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { workflow: { continue: assetDate >= startDate && assetDate <= endDate } };
|
return { workflow: { continue: assetDate >= startDate && assetDate < endDate } };
|
||||||
},
|
},
|
||||||
|
|
||||||
assetLock: ({ config, data }) => {
|
assetLock: ({ config, data }) => {
|
||||||
|
|||||||
@@ -428,6 +428,40 @@ describe('core plugin', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('assetDateFilter', () => {
|
||||||
|
it('should favorite assets created during the first 7 days of a specific year and month', async () => {
|
||||||
|
const { user } = await ctx.newUser();
|
||||||
|
const [{ asset: asset1 }, { asset: asset2 }] = await Promise.all([
|
||||||
|
ctx.newAsset({ ownerId: user.id, localDateTime: new Date('2000-04-01') }),
|
||||||
|
ctx.newAsset({ ownerId: user.id, localDateTime: new Date('2000-04-07T23:59:59Z') }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const workflow = await createWorkflow({
|
||||||
|
ownerId: user.id,
|
||||||
|
trigger: WorkflowTrigger.AssetCreate,
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
method: 'immich-plugin-core#assetDateFilter',
|
||||||
|
config: {
|
||||||
|
startDate: { day: 1, month: 4, year: 2000 },
|
||||||
|
endDate: { day: 7, month: 4, year: 2000 },
|
||||||
|
recurring: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'immich-plugin-core#assetFavorite',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset1.id });
|
||||||
|
await expect(ctx.get(AssetRepository).getById(asset1.id)).resolves.toMatchObject({ isFavorite: true });
|
||||||
|
|
||||||
|
await ctx.sut.handleAssetTrigger({ workflowId: workflow.id, assetId: asset2.id });
|
||||||
|
await expect(ctx.get(AssetRepository).getById(asset2.id)).resolves.toMatchObject({ isFavorite: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('webhook', () => {
|
describe('webhook', () => {
|
||||||
it('should trigger a webhook on asset upload', async () => {
|
it('should trigger a webhook on asset upload', async () => {
|
||||||
const { user } = await ctx.newUser();
|
const { user } = await ctx.newUser();
|
||||||
|
|||||||
Reference in New Issue
Block a user