Skip to content

Commit

Permalink
Update extension types #743
Browse files Browse the repository at this point in the history
  • Loading branch information
bpatrik committed Nov 26, 2023
1 parent 5613085 commit a0d4d7f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/backend/model/extension/ExtensionDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/backend/model/extension/ExtensionEvent.ts
Original file line number Diff line number Diff line change
@@ -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>[] = [];

Expand Down Expand Up @@ -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> {
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) {
Expand Down
39 changes: 28 additions & 11 deletions src/backend/model/extension/IExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


export type IExtensionBeforeEventHandler<I, O> = (input: { inputs: I }, event: { stopPropagation: boolean }) => Promise<{ inputs: I } | O>;
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 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;
}
Expand All @@ -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>
}
};
}
Expand Down

0 comments on commit a0d4d7f

Please sign in to comment.