pigallery2-extension-kit 2.0.2-edge → 2.0.3-edge2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -2
- package/events.drawio +1 -0
- package/events.png +0 -0
- package/index.js +0 -3
- package/index.js.map +1 -1
- package/index.ts +1 -1
- package/lib/backend/model/extension/ExtensionDecorator.d.ts +1 -1
- package/lib/backend/model/extension/ExtensionEvent.d.ts +3 -7
- package/lib/backend/model/extension/IExtension.d.ts +30 -14
- package/package.json +28 -2
- package/ext-enums.tsconfig.json +0 -11
- package/ext-interface.tsconfig.json +0 -12
package/README.md
CHANGED
|
@@ -1,3 +1,109 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pigallery2 Extension
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
See feature issue for more information: [#743](https://github.com/bpatrik/pigallery2/issues/743).
|
|
4
|
+
|
|
5
|
+
See sample extension at https://github.com/bpatrik/pigallery2-sample-extension.
|
|
6
|
+
|
|
7
|
+
# Extension Usage
|
|
8
|
+
|
|
9
|
+
Extension folder can be set through config. For the docker-ised version,
|
|
10
|
+
they live under the `config/extension` folder in their own subdirectory.
|
|
11
|
+
|
|
12
|
+
# Extension development
|
|
13
|
+
|
|
14
|
+
## Minimal setup
|
|
15
|
+
|
|
16
|
+
You need at least a `server.js` in your extension folder that exports a `init(ext) {}` function.
|
|
17
|
+
|
|
18
|
+
## Recommended setup
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
<path to the extension fodler>/myextension/package.js <- this is optional. You can add extra npm packages here
|
|
22
|
+
<path to the extension fodler>/myextension/server.js <- this is needed
|
|
23
|
+
```
|
|
24
|
+
Where `<path to the extension fodler>` is what you set in the config and `myextension` is the name of your extension.
|
|
25
|
+
Note: you do not need to add your `node_modules` folder. The app will call `npm intall` when initializing your extension.
|
|
26
|
+
## Extension environment
|
|
27
|
+
|
|
28
|
+
The app runs the extension the following way:
|
|
29
|
+
* It reads all extensions in `<path to the extension fodler>/**` folder
|
|
30
|
+
* Checks if `package.js` is present. If yes installs the packages
|
|
31
|
+
* Checks if `server.js` is present. If yes, calls the `init` function.
|
|
32
|
+
|
|
33
|
+
### Init and cleanup lifecycle
|
|
34
|
+
There is also a `cleanUp` function that you can implement in your extension.
|
|
35
|
+
The app can call your `init` and `cleanUp` functions any time.
|
|
36
|
+
Always calls the `init` first then `cleanUp` later.
|
|
37
|
+
Main use-case: `init` is called on app startup. `cleanUp` and `init` called later when there is a new config change.
|
|
38
|
+
|
|
39
|
+
## Extension interface
|
|
40
|
+
|
|
41
|
+
The app calls the `init` and `cleanUp` function with a `IExtensionObject` object.
|
|
42
|
+
See https://github.com/bpatrik/pigallery2/blob/master/src/backend/model/extension/IExtension.ts for details.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
`IExtensionObject` exposes lifecycle events, configs, RestAPis with some limitation.
|
|
46
|
+
Changes made during the these public apis you do not need to clean up in the `cleanUp` function.
|
|
47
|
+
App also exposes private `_app` object to provide access to low level API. Any changes made here needs clean up.
|
|
48
|
+
|
|
49
|
+
## server.js
|
|
50
|
+
|
|
51
|
+
See sample server.js at https://github.com/bpatrik/pigallery2-sample-extension.
|
|
52
|
+
|
|
53
|
+
It is recommended to do the development in `ts`, so creating a `server.ts`.
|
|
54
|
+
Note: You need to manually transpile your `server.ts` file to `server.js` as the app does not do that for you.
|
|
55
|
+
This doc assumes you do the development in `ts`.
|
|
56
|
+
|
|
57
|
+
### server.ts
|
|
58
|
+
|
|
59
|
+
You can import package from both the main app package.json and from your extension package.json.
|
|
60
|
+
To import packages from the main app, you import as usual.
|
|
61
|
+
For packages from the extension, you always need to write relative path. i.e.: prefix with `./node_modules`
|
|
62
|
+
```ts
|
|
63
|
+
// Including dev-kit interfaces. It is not necessary, only helps development with types.
|
|
64
|
+
// You need to prefix them with ./node_modules
|
|
65
|
+
import {IExtensionObject} from './node_modules/pigallery2-extension-kit';
|
|
66
|
+
|
|
67
|
+
// Including prod extension packages. You need to prefix them with ./node_modules
|
|
68
|
+
// lodash does not have types
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
import * as _ from './node_modules/lodash';
|
|
72
|
+
|
|
73
|
+
// Importing packages that are available in the main app (listed in the packages.json in pigallery2)
|
|
74
|
+
import {Column, Entity, Index, PrimaryGeneratedColumn} from 'typeorm';
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
#### pigallery2 extension dev-kit
|
|
79
|
+
|
|
80
|
+
It is recommended to use the `pigallery2-extension-kit` node package.
|
|
81
|
+
`npm install pigallery2-extension-kit --save` to your extension.
|
|
82
|
+
|
|
83
|
+
`pigallery2-extension-kit` contains the type definitions and enums for the app.
|
|
84
|
+
This node package is basically includes the all definitions of the app and exports the `IExtensionObject` that the `init` function receives.
|
|
85
|
+
|
|
86
|
+
You can then `import {IExtensionObject} from './node_modules/pigallery2-extension-kit';`
|
|
87
|
+
|
|
88
|
+
See https://github.com/bpatrik/pigallery2/blob/master/src/backend/model/extension/IExtension.ts to understand what contains `IExtensionObject`.
|
|
89
|
+
|
|
90
|
+
NOTE: this is not needed to create an extension it only helps your IDE and your development. These type definitions are removed when you compile `ts` to `js`.
|
|
91
|
+
|
|
92
|
+
#### `init` function
|
|
93
|
+
|
|
94
|
+
You need to implement the `init` function for a working extension:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
|
|
98
|
+
export const init = async (extension: IExtensionObject<void>): Promise<void> => {
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### pigallery2 lifecycle `events`
|
|
104
|
+
|
|
105
|
+
Tha app exposes multiple interfaces for the extensions to interact with the main app. `events` are one of the main interfaces.
|
|
106
|
+
Here are their flow:
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+

|
package/events.drawio
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<mxfile host="app.diagrams.net" modified="2023-11-25T15:41:12.760Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" etag="2TdW26wLRN6yi1qc34DG" version="20.2.7" type="device"><diagram id="9mL0kDflCIzzHydUxYXW" name="Page-1">5Vtbc9o4FP41zOw+kLElbOCRhLTbmaabaWa37aPACtbWtlhZBOivX8mWL7IMmGBMwnY6E+sgS7bO+b5zkdyDd+HmI0NL/4F6OOgBy9v04LQHgG0D0JP/LW+bStzxKBUsGPFUp0LwRH5hJbSUdEU8HGsdOaUBJ0tdOKdRhOdckyHG6Frv9kwDfdYlWmBD8DRHgSn9Rjzup9IRGBbyPzBZ+NnMtjtOfwlR1lm9Sewjj65LInjfg3eMUp5ehZs7HMjFy9Ylve/Djl/zB2M44k1uYF+W1hg8rm5frDAcfQj+ev523wduOswLClbqjdXT8m22BNgTK6KalHGfLmiEgvtCesvoKvKwnMcSraLPZ0qXQmgL4T+Y861SL1pxKkQ+DwP1azqnnGjnyylRTFdsjve9Ub60wiYxDTFnW3EfwwHi5EUfHynjWOT98lsfKREzA0sZMhwrLWZmnNlnNgRHbIG5uqvQwoQxtC11W8oO8e55hk7tNGo0cZEOmLVKr1iIEr0fYwMjwwY+U+RJpPmrcBYhEsTyFSIpWvqU07jWRj6jmQC/plcUkEUkrudCjZgJwQtmnAh0TdQPIfG81IRwTH6hWTKeNCK1UGJw57bnTHMbkQPgTa8G+urmAnBl69lj/KatqOH71o0NXVdTiELHa60p60Kfn2PMK6ptR5mGLidzTpmhMMFGS3m5CoO0Q6GbRI+PNCacUKmjGeWchjXK4xLdZXXTFQ9IhO9yLrb26c1A905NuDr4bEe11wUjQyXyS2TsWrsVo637sYsMG5Bm5E2k+5HGH6A4JnN9qXTKFOvAtt/LjR+yceNkzemm/ON0m7U2hH9XI8rr9C5Y+ad+LMaQjfIQj5gRsTISoSWVtUfHgkkSetzTz6k3gJKGnRoNZ7IT2d22dAPLKSQbIn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LY2AS3hnsIMzdmG52t8edYFls27zFfMVk9mGuXGX+PdVLP31hWsl0NIj6Do0deuboRkXvXN4ZUfUD8Nrx15QN3UPaG7bXMvJGnjwmAAYZ/Xtls6nnT8DhU0Ov14nUOCpjug0oJgFwqs5UAP3n+OUSBkO7HeGFGCeK0hO1ORfVfTKZ2lEPh3zSx+jgSPdLzt1frnTYzRwcAl2eQM5Mxh3xUqvS3Ur1ZXhsIsvlcxDVXcCP8nWQoGqRjuRn0KRtH7FwkyYyF1ZcvE2txWrecjo4qGy+84dfjuIMb/dq+z/DpoVmVoLzIABjjwXXBPu657nwlY9qHxxM6w7aNKSVYtm8ZVtutrFt8rw/j8=</diagram></mxfile>
|
package/events.png
ADDED
|
Binary file
|
package/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IServerExtension = void 0;
|
|
4
|
-
var IExtension_1 = require("./lib/src/backend/model/extension/IExtension");
|
|
5
|
-
Object.defineProperty(exports, "IServerExtension", { enumerable: true, get: function () { return IExtension_1.IServerExtension; } });
|
|
6
3
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":""}
|
package/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {IServerExtension} from './lib/
|
|
1
|
+
export {IServerExtension,IExtensionObject} from './lib/backend/model/extension/IExtension';
|
|
2
2
|
|
|
@@ -3,4 +3,4 @@ export declare class ExtensionDecoratorObject {
|
|
|
3
3
|
static events: IExtensionEvents;
|
|
4
4
|
static init(events: IExtensionEvents): void;
|
|
5
5
|
}
|
|
6
|
-
export declare const ExtensionDecorator: <I extends [], O>(fn: (ee: IExtensionEvents) => IExtensionEvent<I, O>) => (target: unknown, propertyName: string, descriptor:
|
|
6
|
+
export declare const ExtensionDecorator: <I extends unknown[], O>(fn: (ee: IExtensionEvents) => IExtensionEvent<I, O>) => (target: unknown, propertyName: string, descriptor: TypedPropertyDescriptor<(...args: I) => Promise<O>>) => TypedPropertyDescriptor<(...args: I) => Promise<O>>;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { IExtensionAfterEventHandler, IExtensionBeforeEventHandler, IExtensionEvent } from './IExtension';
|
|
2
|
-
export declare class ExtensionEvent<I, O> implements IExtensionEvent<I, O> {
|
|
2
|
+
export declare class ExtensionEvent<I extends unknown[], O> implements IExtensionEvent<I, O> {
|
|
3
3
|
protected beforeHandlers: IExtensionBeforeEventHandler<I, O>[];
|
|
4
4
|
protected afterHandlers: IExtensionAfterEventHandler<O>[];
|
|
5
5
|
before(handler: IExtensionBeforeEventHandler<I, O>): void;
|
|
6
6
|
after(handler: IExtensionAfterEventHandler<O>): void;
|
|
7
7
|
offAfter(handler: IExtensionAfterEventHandler<O>): void;
|
|
8
8
|
offBefore(handler: IExtensionBeforeEventHandler<I, O>): void;
|
|
9
|
-
triggerBefore(input: {
|
|
10
|
-
inputs: I;
|
|
11
|
-
}, event: {
|
|
9
|
+
triggerBefore(input: I, event: {
|
|
12
10
|
stopPropagation: boolean;
|
|
13
|
-
}): Promise<
|
|
14
|
-
inputs: I;
|
|
15
|
-
} | O>;
|
|
11
|
+
}): Promise<I | O>;
|
|
16
12
|
triggerAfter(output: O): Promise<O>;
|
|
17
13
|
}
|
|
@@ -9,15 +9,18 @@ import { ParamsDictionary } from 'express-serve-static-core';
|
|
|
9
9
|
import { Connection } from 'typeorm';
|
|
10
10
|
import { DynamicConfig } from '../../../common/entities/DynamicConfig';
|
|
11
11
|
import { MediaDTOWithThPath } from '../messenger/Messenger';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
import { PhotoMetadata } from '../../../common/entities/PhotoDTO';
|
|
13
|
+
import { VideoMetadata } from '../../../common/entities/VideoDTO';
|
|
14
|
+
import { MediaRendererInput, SvgRendererInput } from '../fileaccess/PhotoWorker';
|
|
15
|
+
import { SearchQueryDTO } from '../../../common/entities/SearchQueryDTO';
|
|
16
|
+
import { CoverPhotoDTOWithID } from '../database/CoverManager';
|
|
17
|
+
import { ParentDirectoryDTO } from '../../../common/entities/DirectoryDTO';
|
|
18
|
+
import { DirectoryScanSettings } from '../fileaccess/DiskManager';
|
|
19
|
+
export declare type IExtensionBeforeEventHandler<I extends unknown[], O> = (input: I, event: {
|
|
15
20
|
stopPropagation: boolean;
|
|
16
|
-
}) => Promise<
|
|
17
|
-
inputs: I;
|
|
18
|
-
} | O>;
|
|
21
|
+
}) => Promise<I | O>;
|
|
19
22
|
export declare type IExtensionAfterEventHandler<O> = (output: O) => Promise<O>;
|
|
20
|
-
export interface IExtensionEvent<I, O> {
|
|
23
|
+
export interface IExtensionEvent<I extends unknown[], O> {
|
|
21
24
|
before: (handler: IExtensionBeforeEventHandler<I, O>) => void;
|
|
22
25
|
after: (handler: IExtensionAfterEventHandler<O>) => void;
|
|
23
26
|
}
|
|
@@ -30,32 +33,45 @@ export interface IExtensionEvents {
|
|
|
30
33
|
* Events for Directory and Album covers
|
|
31
34
|
*/
|
|
32
35
|
CoverManager: {
|
|
33
|
-
getCoverForAlbum: IExtensionEvent<
|
|
34
|
-
|
|
36
|
+
getCoverForAlbum: IExtensionEvent<[
|
|
37
|
+
{
|
|
38
|
+
searchQuery: SearchQueryDTO;
|
|
39
|
+
}
|
|
40
|
+
], CoverPhotoDTOWithID>;
|
|
41
|
+
getCoverForDirectory: IExtensionEvent<[
|
|
42
|
+
{
|
|
43
|
+
id: number;
|
|
44
|
+
name: string;
|
|
45
|
+
path: string;
|
|
46
|
+
}
|
|
47
|
+
], CoverPhotoDTOWithID>;
|
|
35
48
|
/**
|
|
36
49
|
* Invalidates directory covers for a given directory and every parent
|
|
37
50
|
*/
|
|
38
|
-
invalidateDirectoryCovers: IExtensionEvent<
|
|
51
|
+
invalidateDirectoryCovers: IExtensionEvent<[ParentDirectoryDTO], void>;
|
|
39
52
|
};
|
|
40
53
|
ImageRenderer: {
|
|
41
54
|
/**
|
|
42
55
|
* Renders a thumbnail or photo
|
|
43
56
|
*/
|
|
44
|
-
render: IExtensionEvent<
|
|
57
|
+
render: IExtensionEvent<[MediaRendererInput | SvgRendererInput], void>;
|
|
45
58
|
};
|
|
46
59
|
/**
|
|
47
60
|
* Reads exif, iptc, etc.. metadata for photos/videos
|
|
48
61
|
*/
|
|
49
62
|
MetadataLoader: {
|
|
50
|
-
loadVideoMetadata: IExtensionEvent<
|
|
51
|
-
loadPhotoMetadata: IExtensionEvent<
|
|
63
|
+
loadVideoMetadata: IExtensionEvent<[string], VideoMetadata>;
|
|
64
|
+
loadPhotoMetadata: IExtensionEvent<[string], PhotoMetadata>;
|
|
52
65
|
};
|
|
53
66
|
/**
|
|
54
67
|
* Scans the storage for a given directory and returns the list of child directories,
|
|
55
68
|
* photos, videos and metafiles
|
|
56
69
|
*/
|
|
57
70
|
DiskManager: {
|
|
58
|
-
scanDirectory: IExtensionEvent<
|
|
71
|
+
scanDirectory: IExtensionEvent<[
|
|
72
|
+
string,
|
|
73
|
+
DirectoryScanSettings
|
|
74
|
+
], ParentDirectoryDTO>;
|
|
59
75
|
};
|
|
60
76
|
};
|
|
61
77
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pigallery2-extension-kit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3-edge2",
|
|
4
4
|
"description": "Interfaces for developing extensions for pigallery2",
|
|
5
5
|
"author": "Patrik J. Braun",
|
|
6
6
|
"homepage": "https://github.com/bpatrik/pigallery2",
|
|
7
|
-
"license": "MIT"
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"typeconfig": "2.1.2",
|
|
10
|
+
"typeorm": "0.3.12",
|
|
11
|
+
"@types/archiver": "5.3.1",
|
|
12
|
+
"@types/bcrypt": "5.0.0",
|
|
13
|
+
"@types/bcryptjs": "2.4.2",
|
|
14
|
+
"@types/chai": "4.3.4",
|
|
15
|
+
"@types/cookie-parser": "1.4.3",
|
|
16
|
+
"@types/cookie-session": "2.0.44",
|
|
17
|
+
"@types/csurf": "1.11.2",
|
|
18
|
+
"@types/ejs": "3.1.2",
|
|
19
|
+
"@types/express": "4.17.17",
|
|
20
|
+
"@types/express-jwt": "6.0.4",
|
|
21
|
+
"@types/fluent-ffmpeg": "2.1.21",
|
|
22
|
+
"@types/gulp": "4.0.10",
|
|
23
|
+
"@types/gulp-zip": "4.0.2",
|
|
24
|
+
"@types/jasmine": "4.3.1",
|
|
25
|
+
"@types/jsonwebtoken": "9.0.1",
|
|
26
|
+
"@types/leaflet": "1.9.1",
|
|
27
|
+
"@types/leaflet.markercluster": "1.5.1",
|
|
28
|
+
"@types/node": "18.15.0",
|
|
29
|
+
"@types/node-geocoder": "4.2.0",
|
|
30
|
+
"@types/nodemailer": "6.4.9",
|
|
31
|
+
"@types/sharp": "0.31.1",
|
|
32
|
+
"@types/xml2js": "0.4.11"
|
|
33
|
+
}
|
|
8
34
|
}
|
package/ext-enums.tsconfig.json
DELETED