From a0d4d7f24675d6222ff27ee9165117c314f1f1c8 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 26 Nov 2023 10:25:17 +0100 Subject: [PATCH] Update extension types #743 --- extension/package.json | 2 +- package.json | 2 +- .../model/extension/ExtensionDecorator.ts | 4 +-- src/backend/model/extension/ExtensionEvent.ts | 4 +-- src/backend/model/extension/IExtension.ts | 35 ++++++++++++++----- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/extension/package.json b/extension/package.json index 4e282561..46a16123 100644 --- a/extension/package.json +++ b/extension/package.json @@ -1,6 +1,6 @@ { "name": "pigallery2-extension-kit", - "version": "2.0.2-edge", + "version": "2.0.3-edge", "description": "Interfaces for developing extensions for pigallery2", "author": "Patrik J. Braun", "homepage": "https://github.com/bpatrik/pigallery2", diff --git a/package.json b/package.json index b6c77533..40f81ba5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pigallery2", - "version": "2.0.2-edge", + "version": "2.0.3-edge", "description": "This is a photo gallery optimised for running low resource servers (especially on raspberry pi)", "author": "Patrik J. Braun", "homepage": "https://github.com/bpatrik/pigallery2", diff --git a/src/backend/model/extension/ExtensionDecorator.ts b/src/backend/model/extension/ExtensionDecorator.ts index a0870f49..81165960 100644 --- a/src/backend/model/extension/ExtensionDecorator.ts +++ b/src/backend/model/extension/ExtensionDecorator.ts @@ -10,11 +10,11 @@ export class ExtensionDecoratorObject { } -export const ExtensionDecorator = (fn: (ee: IExtensionEvents) => IExtensionEvent) => { +export const ExtensionDecorator = (fn: (ee: IExtensionEvents) => IExtensionEvent) => { return ( target: unknown, propertyName: string, - descriptor: PropertyDescriptor + descriptor: TypedPropertyDescriptor<(...args:I)=>Promise> ) => { const targetMethod = descriptor.value; diff --git a/src/backend/model/extension/ExtensionEvent.ts b/src/backend/model/extension/ExtensionEvent.ts index 231b7b53..f9257205 100644 --- a/src/backend/model/extension/ExtensionEvent.ts +++ b/src/backend/model/extension/ExtensionEvent.ts @@ -1,6 +1,6 @@ import {IExtensionAfterEventHandler, IExtensionBeforeEventHandler, IExtensionEvent} from './IExtension'; -export class ExtensionEvent implements IExtensionEvent { +export class ExtensionEvent implements IExtensionEvent { protected beforeHandlers: IExtensionBeforeEventHandler[] = []; protected afterHandlers: IExtensionAfterEventHandler[] = []; @@ -28,7 +28,7 @@ export class ExtensionEvent implements IExtensionEvent { public async triggerBefore(input: { inputs: I }, event: { stopPropagation: boolean }): Promise<{ inputs: I } | O> { - let pipe: { inputs: I } | O = input; + let pipe: { inputs: I} | O = input; if (this.beforeHandlers && this.beforeHandlers.length > 0) { const s = this.beforeHandlers.slice(0); for (let i = 0; i < s.length; ++i) { diff --git a/src/backend/model/extension/IExtension.ts b/src/backend/model/extension/IExtension.ts index cd59cf0e..aa5b6f53 100644 --- a/src/backend/model/extension/IExtension.ts +++ b/src/backend/model/extension/IExtension.ts @@ -9,13 +9,22 @@ import {ParamsDictionary} from 'express-serve-static-core'; import {Connection} from 'typeorm'; import {DynamicConfig} from '../../../common/entities/DynamicConfig'; import {MediaDTOWithThPath} from '../messenger/Messenger'; +import {PhotoMetadata} from '../../../common/entities/PhotoDTO'; +import {VideoMetadata} from '../../../common/entities/VideoDTO'; +import {MediaRendererInput, SvgRendererInput} from '../fileaccess/PhotoWorker'; +import {SearchQueryDTO} from '../../../common/entities/SearchQueryDTO'; +import {CoverPhotoDTOWithID} from '../database/CoverManager'; +import {ParentDirectoryDTO} from '../../../common/entities/DirectoryDTO'; +import {DirectoryScanSettings} from '../fileaccess/DiskManager'; -export type IExtensionBeforeEventHandler = (input: { inputs: I }, event: { stopPropagation: boolean }) => Promise<{ inputs: I } | O>; +export type IExtensionBeforeEventHandler = (input: { inputs: I }, event: { stopPropagation: boolean }) => Promise<{ + inputs: I +} | O>; export type IExtensionAfterEventHandler = (output: O) => Promise; -export interface IExtensionEvent { +export interface IExtensionEvent { before: (handler: IExtensionBeforeEventHandler) => void; after: (handler: IExtensionAfterEventHandler) => void; } @@ -29,32 +38,40 @@ export interface IExtensionEvents { * Events for Directory and Album covers */ CoverManager: { - getCoverForAlbum: IExtensionEvent; - getCoverForDirectory: IExtensionEvent + getCoverForAlbum: IExtensionEvent<[{ + searchQuery: SearchQueryDTO; + }], CoverPhotoDTOWithID>; + getCoverForDirectory: IExtensionEvent<[{ + id: number; + name: string; + path: string; + }], CoverPhotoDTOWithID> /** * Invalidates directory covers for a given directory and every parent */ - invalidateDirectoryCovers: IExtensionEvent; + invalidateDirectoryCovers: IExtensionEvent<[ParentDirectoryDTO], void>; }, ImageRenderer: { /** * Renders a thumbnail or photo */ - render: IExtensionEvent + render: IExtensionEvent<[MediaRendererInput | SvgRendererInput], void> }, /** * Reads exif, iptc, etc.. metadata for photos/videos */ MetadataLoader: { - loadVideoMetadata: IExtensionEvent, - loadPhotoMetadata: IExtensionEvent + loadVideoMetadata: IExtensionEvent<[string], VideoMetadata>, + loadPhotoMetadata: IExtensionEvent<[string], PhotoMetadata> }, /** * Scans the storage for a given directory and returns the list of child directories, * photos, videos and metafiles */ DiskManager: { - scanDirectory: IExtensionEvent + scanDirectory: IExtensionEvent<[ + string, + DirectoryScanSettings], ParentDirectoryDTO> } }; }