1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Update extension types #743

This commit is contained in:
Patrik J. Braun 2023-11-26 10:25:17 +01:00
parent 5613085843
commit a0d4d7f246
5 changed files with 32 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "pigallery2-extension-kit", "name": "pigallery2-extension-kit",
"version": "2.0.2-edge", "version": "2.0.3-edge",
"description": "Interfaces for developing extensions for pigallery2", "description": "Interfaces for developing extensions for pigallery2",
"author": "Patrik J. Braun", "author": "Patrik J. Braun",
"homepage": "https://github.com/bpatrik/pigallery2", "homepage": "https://github.com/bpatrik/pigallery2",

View File

@ -1,6 +1,6 @@
{ {
"name": "pigallery2", "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)", "description": "This is a photo gallery optimised for running low resource servers (especially on raspberry pi)",
"author": "Patrik J. Braun", "author": "Patrik J. Braun",
"homepage": "https://github.com/bpatrik/pigallery2", "homepage": "https://github.com/bpatrik/pigallery2",

View File

@ -10,11 +10,11 @@ export class ExtensionDecoratorObject {
} }
export const ExtensionDecorator = <I extends [], O>(fn: (ee: IExtensionEvents) => IExtensionEvent<I, O>) => { export const ExtensionDecorator = <I extends unknown[], O>(fn: (ee: IExtensionEvents) => IExtensionEvent<I, O>) => {
return ( return (
target: unknown, target: unknown,
propertyName: string, propertyName: string,
descriptor: PropertyDescriptor descriptor: TypedPropertyDescriptor<(...args:I)=>Promise<O>>
) => { ) => {
const targetMethod = descriptor.value; const targetMethod = descriptor.value;

View File

@ -1,6 +1,6 @@
import {IExtensionAfterEventHandler, IExtensionBeforeEventHandler, IExtensionEvent} from './IExtension'; import {IExtensionAfterEventHandler, IExtensionBeforeEventHandler, IExtensionEvent} from './IExtension';
export class ExtensionEvent<I, O> implements IExtensionEvent<I, O> { export class ExtensionEvent<I extends unknown[], O> implements IExtensionEvent<I, O> {
protected beforeHandlers: IExtensionBeforeEventHandler<I, O>[] = []; protected beforeHandlers: IExtensionBeforeEventHandler<I, O>[] = [];
protected afterHandlers: IExtensionAfterEventHandler<O>[] = []; protected afterHandlers: IExtensionAfterEventHandler<O>[] = [];
@ -28,7 +28,7 @@ export class ExtensionEvent<I, O> implements IExtensionEvent<I, O> {
public async triggerBefore(input: { inputs: I }, event: { stopPropagation: boolean }): Promise<{ inputs: I } | O> { 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) { if (this.beforeHandlers && this.beforeHandlers.length > 0) {
const s = this.beforeHandlers.slice(0); const s = this.beforeHandlers.slice(0);
for (let i = 0; i < s.length; ++i) { for (let i = 0; i < s.length; ++i) {

View File

@ -9,13 +9,22 @@ import {ParamsDictionary} from 'express-serve-static-core';
import {Connection} from 'typeorm'; import {Connection} from 'typeorm';
import {DynamicConfig} from '../../../common/entities/DynamicConfig'; import {DynamicConfig} from '../../../common/entities/DynamicConfig';
import {MediaDTOWithThPath} from '../messenger/Messenger'; 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<I, O> = (input: { inputs: I }, event: { stopPropagation: boolean }) => Promise<{ inputs: I } | O>; export type IExtensionBeforeEventHandler<I extends unknown[], O> = (input: { inputs: I }, event: { stopPropagation: boolean }) => Promise<{
inputs: I
} | O>;
export type IExtensionAfterEventHandler<O> = (output: O) => Promise<O>; export type IExtensionAfterEventHandler<O> = (output: O) => Promise<O>;
export interface IExtensionEvent<I, O> { export interface IExtensionEvent<I extends unknown[], O> {
before: (handler: IExtensionBeforeEventHandler<I, O>) => void; before: (handler: IExtensionBeforeEventHandler<I, O>) => void;
after: (handler: IExtensionAfterEventHandler<O>) => void; after: (handler: IExtensionAfterEventHandler<O>) => void;
} }
@ -29,32 +38,40 @@ export interface IExtensionEvents {
* Events for Directory and Album covers * Events for Directory and Album covers
*/ */
CoverManager: { CoverManager: {
getCoverForAlbum: IExtensionEvent<any, any>; getCoverForAlbum: IExtensionEvent<[{
getCoverForDirectory: IExtensionEvent<any, any> searchQuery: SearchQueryDTO;
}], CoverPhotoDTOWithID>;
getCoverForDirectory: IExtensionEvent<[{
id: number;
name: string;
path: string;
}], CoverPhotoDTOWithID>
/** /**
* Invalidates directory covers for a given directory and every parent * Invalidates directory covers for a given directory and every parent
*/ */
invalidateDirectoryCovers: IExtensionEvent<any, any>; invalidateDirectoryCovers: IExtensionEvent<[ParentDirectoryDTO], void>;
}, },
ImageRenderer: { ImageRenderer: {
/** /**
* Renders a thumbnail or photo * Renders a thumbnail or photo
*/ */
render: IExtensionEvent<any, any> render: IExtensionEvent<[MediaRendererInput | SvgRendererInput], void>
}, },
/** /**
* Reads exif, iptc, etc.. metadata for photos/videos * Reads exif, iptc, etc.. metadata for photos/videos
*/ */
MetadataLoader: { MetadataLoader: {
loadVideoMetadata: IExtensionEvent<any, any>, loadVideoMetadata: IExtensionEvent<[string], VideoMetadata>,
loadPhotoMetadata: IExtensionEvent<any, any> loadPhotoMetadata: IExtensionEvent<[string], PhotoMetadata>
}, },
/** /**
* Scans the storage for a given directory and returns the list of child directories, * Scans the storage for a given directory and returns the list of child directories,
* photos, videos and metafiles * photos, videos and metafiles
*/ */
DiskManager: { DiskManager: {
scanDirectory: IExtensionEvent<any, any> scanDirectory: IExtensionEvent<[
string,
DirectoryScanSettings], ParentDirectoryDTO>
} }
}; };
} }