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",
"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",

View File

@ -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",

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 (
target: unknown,
propertyName: string,
descriptor: PropertyDescriptor
descriptor: TypedPropertyDescriptor<(...args:I)=>Promise<O>>
) => {
const targetMethod = descriptor.value;

View File

@ -1,6 +1,6 @@
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 afterHandlers: IExtensionAfterEventHandler<O>[] = [];

View File

@ -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<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 interface IExtensionEvent<I, O> {
export interface IExtensionEvent<I extends unknown[], O> {
before: (handler: IExtensionBeforeEventHandler<I, O>) => void;
after: (handler: IExtensionAfterEventHandler<O>) => void;
}
@ -29,32 +38,40 @@ export interface IExtensionEvents {
* Events for Directory and Album covers
*/
CoverManager: {
getCoverForAlbum: IExtensionEvent<any, any>;
getCoverForDirectory: IExtensionEvent<any, any>
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<any, any>;
invalidateDirectoryCovers: IExtensionEvent<[ParentDirectoryDTO], void>;
},
ImageRenderer: {
/**
* Renders a thumbnail or photo
*/
render: IExtensionEvent<any, any>
render: IExtensionEvent<[MediaRendererInput | SvgRendererInput], void>
},
/**
* Reads exif, iptc, etc.. metadata for photos/videos
*/
MetadataLoader: {
loadVideoMetadata: IExtensionEvent<any, any>,
loadPhotoMetadata: IExtensionEvent<any, any>
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<any, any>
scanDirectory: IExtensionEvent<[
string,
DirectoryScanSettings], ParentDirectoryDTO>
}
};
}