pigallery2-extension-kit 3.9.0-edge → 3.9.1-edge

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/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { IServerExtension, IExtensionObject } from './lib/backend/model/extension/IExtension';
2
+ export type { UIAction, MediaActionArgs } from './lib/backend/model/extension/IExtension';
3
+ export type { UIFormData, UIFormDTO, UIFormField, UIWhen, IMetadataFilter } from './lib/common/entities/extension/IClientUIConfig';
2
4
  export { ExtensionError } from './lib/common/entities/extension/ExtensionError';
@@ -1,5 +1,9 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
2
  export declare class ExtensionMWs {
3
+ /**
4
+ * The UI contributions of the extensions that the user of the request may see (none without a session).
5
+ */
6
+ static getUIConfig(req: Request, res: Response, next: NextFunction): void;
3
7
  static getExtensionList(req: Request, res: Response, next: NextFunction): Promise<void>;
4
8
  static installExtension(req: Request, res: Response, next: NextFunction): Promise<void>;
5
9
  static reloadExtension(req: Request, res: Response, next: NextFunction): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import * as express from 'express';
2
2
  import { NextFunction, Request, Response } from 'express';
3
3
  import { UserRoles } from '../../../common/entities/UserDTO';
4
- import { ExtensionMediaRequest, ExtensionPublicRequest, ExtensionRequest, ExtensionRoutePaths, IExtensionRESTApi, IExtensionRESTRoute } from './IExtension';
4
+ import { ExtensionMediaRequest, ExtensionPublicRequest, ExtensionRequest, ExtensionRoutePaths, IExtensionRESTApi, IExtensionRESTRoute, MediaActionArgs } from './IExtension';
5
5
  import { ILogger } from '../../Logger';
6
6
  export declare class ExpressRouterWrapper implements IExtensionRESTApi {
7
7
  private readonly router;
@@ -21,6 +21,12 @@ export declare class ExpressRouteWrapper implements IExtensionRESTRoute {
21
21
  private readonly extLogger;
22
22
  constructor(router: express.Router, name: string, func: 'get' | 'use' | 'put' | 'post' | 'delete', extLogger: ILogger);
23
23
  mediaJsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, invalidateDirectory: boolean, cb: (req: ExtensionMediaRequest) => unknown): string;
24
+ /**
25
+ * The route of a UI action (see UIExtension.addAction): loads the media of `body.items` that the user may see
26
+ * and calls the handler once per media, one after the other.
27
+ * Not part of the extension API.
28
+ */
29
+ actionResponse(actionId: string, minRole: UserRoles, invalidateDirectory: boolean, handler: (args: MediaActionArgs<unknown>) => unknown): string;
24
30
  jsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, cb: (req: ExtensionRequest) => unknown): string;
25
31
  jsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: null, cb: (req: ExtensionPublicRequest) => unknown): string;
26
32
  rawMiddleware<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles | null, mw: (req: Request, res: Response, next: NextFunction) => void | Promise<void>): string;
@@ -2,11 +2,23 @@ import { FindOptionsWhere } from 'typeorm';
2
2
  import { ExtensionSession, IExtensionGallery, IExtensionMediaRepository } from './IExtension';
3
3
  import { MediaEntity } from '../database/enitites/MediaEntity';
4
4
  import { SessionContext } from '../SessionContext';
5
- import { DirectoryPathDTO } from '../../../common/entities/DirectoryDTO';
5
+ import { DirectoryPathDTO, ParentDirectoryDTO } from '../../../common/entities/DirectoryDTO';
6
+ import { PersonDTO } from '../../../common/entities/PersonDTO';
7
+ import { AlbumBaseDTO } from '../../../common/entities/album/AlbumBaseDTO';
6
8
  export declare class ExtensionGallery implements IExtensionGallery {
7
9
  getMedia(session: ExtensionSession, path: string): Promise<MediaEntity>;
8
10
  getMediaList(session: ExtensionSession, paths: string[]): Promise<MediaEntity[]>;
9
11
  getMediaRepository(session: ExtensionSession): IExtensionMediaRepository;
12
+ /**
13
+ * Like the app's directory listing (GalleryMWs.listDirectory), but from the DB only: it never reads the disk or indexes.
14
+ */
15
+ getDirectory(session: ExtensionSession, path: string): Promise<ParentDirectoryDTO>;
16
+ getPersons(session: ExtensionSession): Promise<PersonDTO[]>;
17
+ getAlbums(session: ExtensionSession): Promise<AlbumBaseDTO[]>;
18
+ /**
19
+ * The same role setting that guards the app's own route of the data.
20
+ */
21
+ private static requireRole;
10
22
  }
11
23
  /**
12
24
  * Media table access through the projection of a session, see {@link IExtensionMediaRepository}.
@@ -30,9 +42,9 @@ export declare class ExtensionMediaRepository implements IExtensionMediaReposito
30
42
  /**
31
43
  * Invalidates the caches of the directories that changed since the last call.
32
44
  */
33
- invalidateChanged(extraDir?: DirectoryPathDTO & {
45
+ invalidateChanged(...extraDirs: (DirectoryPathDTO & {
34
46
  id: number;
35
- }): Promise<void>;
47
+ })[]): Promise<void>;
36
48
  private static faceNames;
37
49
  /**
38
50
  * The current DB rows of the media, by id, if the session may see every one of them.
@@ -5,6 +5,7 @@ import { ExtensionObject } from './ExtensionObject';
5
5
  import { ExtensionRepository } from './ExtensionRepository';
6
6
  import { ExtensionListItem } from '../../../common/entities/extension/ExtensionListItem';
7
7
  import { UIExtensionDTO } from '../../../common/entities/extension/IClientUIConfig';
8
+ import { SessionContext } from '../SessionContext';
8
9
  export declare class ExtensionManager implements IObjectManager {
9
10
  static EXTENSION_API_PATH: string;
10
11
  repository: ExtensionRepository;
@@ -50,7 +51,10 @@ export declare class ExtensionManager implements IObjectManager {
50
51
  * An extension folder is a single, plain folder name inside the extension folder.
51
52
  */
52
53
  private static isFolderName;
53
- getUIExtensionConfigs(): UIExtensionDTO[];
54
+ /**
55
+ * The UI contributions that the user of the session may see (nothing without a session, e.g. on the login page).
56
+ */
57
+ getUIExtensionConfigs(session: SessionContext | undefined): UIExtensionDTO[];
54
58
  private initEvents;
55
59
  private createUniqueExtensionObject;
56
60
  /**
@@ -22,6 +22,8 @@ export declare class ExtensionObject<C> implements IExtensionObject<C> {
22
22
  readonly gallery: ExtensionGallery;
23
23
  /** The REST API routes of this extension. They go away with this object on clean up. */
24
24
  readonly router: import("express-serve-static-core").Router;
25
+ /** The routes of the UI actions. They come before {@link router}, so the extension's own routes can't shadow them. */
26
+ readonly uiRouter: import("express-serve-static-core").Router;
25
27
  private readonly eventsTracker;
26
28
  /**
27
29
  * @param extensionId - Unique ID used internally to track this extension instance (may have _1, _2 suffix if name collision occurs)
@@ -15,9 +15,11 @@ import { MediaRendererInput, SvgRendererInput } from '../fileaccess/PhotoWorker'
15
15
  import { SearchQueryDTO } from '../../../common/entities/SearchQueryDTO';
16
16
  import { CoverPhotoDTOWithID } from '../database/CoverManager';
17
17
  import { DirectoryPathDTO, ParentDirectoryDTO } from '../../../common/entities/DirectoryDTO';
18
+ import { PersonDTO } from '../../../common/entities/PersonDTO';
19
+ import { AlbumBaseDTO } from '../../../common/entities/album/AlbumBaseDTO';
18
20
  import { DirectoryScanSettings } from '../fileaccess/DiskManager';
19
21
  import { SessionContext } from '../SessionContext';
20
- import { IClientMediaButtonConfig, IMediaRequestBodyData } from '../../../common/entities/extension/IClientUIConfig';
22
+ import { UIActionAfter, UIActionBase, UIFormData, UIFormDTO } from '../../../common/entities/extension/IClientUIConfig';
21
23
  import { MediaEntity } from '../database/enitites/MediaEntity';
22
24
  import { VideoConverterInput } from '../fileaccess/VideoConverterWorker';
23
25
  import { ProjectedDirectoryCacheEntity } from '../database/enitites/ProjectedDirectoryCacheEntity';
@@ -127,11 +129,14 @@ export interface IExtensionApp {
127
129
  config: PrivateConfigClass;
128
130
  }
129
131
  export interface IMediaRequestBody {
130
- data: IMediaRequestBodyData;
132
+ data: UIFormData;
131
133
  media: string;
132
134
  }
133
135
  /**
134
- * The session of a request: who asks and which projection (what they may see) applies.
136
+ * The session of a request: who asks and what they may see.
137
+ * What a user may see is called their projection: the media left after their allow and block lists
138
+ * ("Allowed/Blocked query" and "Allowed/Blocked directories" of the user or the default ones in the settings)
139
+ * and, for a sharing link, the shared folder or search.
135
140
  * Pass it to the `extension.gallery` helpers; it only works with the session object the app gave you.
136
141
  */
137
142
  export interface ExtensionSession {
@@ -140,7 +145,10 @@ export interface ExtensionSession {
140
145
  readonly name: string;
141
146
  readonly role: UserRoles;
142
147
  };
143
- /** Same for every session that may see the same media; use it as a cache key. */
148
+ /**
149
+ * A hash of the projection (allow and block lists, sharing): the same for every session that may see the same media.
150
+ * Use it as a cache key for data that depends on what the user may see.
151
+ */
144
152
  readonly projectionKey: string;
145
153
  }
146
154
  /**
@@ -164,7 +172,7 @@ export type ExtensionPublicRequest<B = unknown> = Omit<ExtensionRequest<B>, 'use
164
172
  session: undefined;
165
173
  };
166
174
  /**
167
- * What a media route callback gets: the media of `body.media`, already checked against the user's projection.
175
+ * What a media route callback gets: the media of `body.media`, already checked against what the user may see (projection: allow and block lists, sharing).
168
176
  */
169
177
  export interface ExtensionMediaRequest extends ExtensionRequest<IMediaRequestBody> {
170
178
  media: MediaEntity;
@@ -172,7 +180,7 @@ export interface ExtensionMediaRequest extends ExtensionRequest<IMediaRequestBod
172
180
  repository: IExtensionMediaRepository;
173
181
  }
174
182
  /**
175
- * Access to the media table through the projection of a session: it only finds, changes or deletes media the user may see.
183
+ * Access to the media table through the projection (allow and block lists, sharing) of a session: it only finds, changes or deletes media the user may see.
176
184
  * Every call takes at most 1000 media, and fails as a whole (nothing is written) if one of them is missing or hidden.
177
185
  */
178
186
  export interface IExtensionMediaRepository {
@@ -196,7 +204,7 @@ export interface IExtensionMediaRepository {
196
204
  delete(media: MediaEntity | MediaEntity[]): Promise<void>;
197
205
  }
198
206
  /**
199
- * Gallery data, with the projection (what the user may see) of a session applied.
207
+ * Gallery data, with the projection of a session applied: only what the user may see by their allow and block lists and sharing.
200
208
  */
201
209
  export interface IExtensionGallery {
202
210
  /**
@@ -210,6 +218,23 @@ export interface IExtensionGallery {
210
218
  */
211
219
  getMediaList(session: ExtensionSession, paths: string[]): Promise<MediaEntity[]>;
212
220
  getMediaRepository(session: ExtensionSession): IExtensionMediaRepository;
221
+ /**
222
+ * The directory at the path (relative to the media folder, `''` or `'.'` for the root) with its media and
223
+ * subdirectories, as the user sees it in the app. Reads the DB only: a directory that isn't indexed yet is not found.
224
+ * Throws an {@link ExtensionError} 404 if it does not exist or the user may not see it.
225
+ */
226
+ getDirectory(session: ExtensionSession, path: string): Promise<ParentDirectoryDTO>;
227
+ /**
228
+ * The persons with a face the user may see, with their face count (`cache.count`) and sample face.
229
+ * The faces of a media are in its `metadata.faces`.
230
+ * Throws an {@link ExtensionError} 403 below the `Faces.readAccessMinRole` setting.
231
+ */
232
+ getPersons(session: ExtensionSession): Promise<PersonDTO[]>;
233
+ /**
234
+ * The albums the user may see, with their media count and cover. Empty if albums are disabled.
235
+ * Throws an {@link ExtensionError} 403 below the `Album.readAccessMinRole` setting.
236
+ */
237
+ getAlbums(session: ExtensionSession): Promise<AlbumBaseDTO[]>;
213
238
  }
214
239
  type IdentifierStart = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | Uppercase<'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'> | '_' | '$';
215
240
  type HasUnnamedParam<P extends string> = P extends `${string}${':' | '*'}${infer Rest}` ? Rest extends `${IdentifierStart}${string}` ? HasUnnamedParam<Rest> : true : false;
@@ -365,12 +390,12 @@ export interface IExtensionObject<C = void> {
365
390
  }
366
391
  export interface IUIExtension<_C> {
367
392
  /**
368
- * Adds a new button on to UI to all media (photo, video).
369
- * Implement the server-side click action in the serverSB function.
370
- * @param buttonConfig
371
- * @param serverSB If not set the button will be a fake button (i.e.: only show up not clickable)
393
+ * Adds a button to the UI, e.g. on the media tiles of the grid.
394
+ * With `action.handler`, a click (after the form popup, if it has `action.form`) runs the handler on the server,
395
+ * on a route that the app generates. Without `action`, the button is only an indicator (not clickable).
396
+ * An invalid action is logged and skipped.
372
397
  */
373
- addMediaButton(buttonConfig: IClientMediaButtonConfig, serverSB?: (req: ExtensionMediaRequest) => Promise<void>): void;
398
+ addAction<D = UIFormData>(action: UIAction<D>): void;
374
399
  }
375
400
  export interface IExtensionConfigInit<C> {
376
401
  /**
@@ -402,4 +427,60 @@ export interface IServerExtensionConfig<C> {
402
427
  */
403
428
  initConfig(extension: IExtensionConfigInit<C>): void;
404
429
  }
430
+ /**
431
+ * What the handler of a media action gets, once per media.
432
+ */
433
+ export interface MediaActionArgs<D = UIFormData> {
434
+ /** The media, already checked against what the user may see (projection: allow and block lists, sharing). */
435
+ media: MediaEntity;
436
+ /** What the form popup sent (`{}` without a form). Check it: it comes from the browser. */
437
+ data: D;
438
+ user: UserDTO;
439
+ session: ExtensionSession;
440
+ /** Writes through it only touch media the user may see, see {@link IExtensionMediaRepository}. */
441
+ repository: IExtensionMediaRepository;
442
+ }
443
+ /**
444
+ * A button of an extension, see {@link IUIExtension.addAction}.
445
+ * Example:
446
+ * ```ts
447
+ * extension.ui.addAction({
448
+ * id: 'favorite',
449
+ * label: 'Add to favorites',
450
+ * svgIcon: {viewBox: '0 0 512 512', items: '<path d="…"/>'},
451
+ * target: 'media',
452
+ * placements: ['mediaTile'],
453
+ * when: {media: 'photo', metadata: [{field: 'keywords', comparator: '!contains', value: 'favorite'}]},
454
+ * action: {
455
+ * after: 'reloadContent',
456
+ * handler: async ({media, repository}) => {
457
+ * media.metadata.keywords = [...(media.metadata.keywords ?? []), 'favorite'];
458
+ * await repository.save(media);
459
+ * }
460
+ * }
461
+ * });
462
+ * ```
463
+ */
464
+ export interface UIAction<D = UIFormData> extends UIActionBase {
465
+ /**
466
+ * What a click does. Without it, the button is only an indicator.
467
+ */
468
+ action?: {
469
+ /** A form popup that collects `data` first. Without it, a click runs the handler straight away. */
470
+ form?: UIFormDTO;
471
+ /** What the app does after the handler succeeded. Default: 'none'. */
472
+ after?: UIActionAfter;
473
+ /**
474
+ * Refresh the cached data of the folders of the media after the handler (also if it failed halfway).
475
+ * Default: true. Set it to false if the gallery doesn't change: invalidation is resource-intensive.
476
+ * Writes through `repository` invalidate their folders anyway.
477
+ */
478
+ invalidateDirectory?: boolean;
479
+ /**
480
+ * Runs on the server once per media, one after the other; the first error stops it.
481
+ * Throw an {@link ExtensionError} to show its message in the popup. The default `when.minRole` is `User`.
482
+ */
483
+ handler: (args: MediaActionArgs<D>) => unknown;
484
+ };
485
+ }
405
486
  export {};
@@ -1,9 +1,37 @@
1
1
  import { ExtensionObject } from './ExtensionObject';
2
- import { IClientMediaButtonConfig } from '../../../common/entities/extension/IClientUIConfig';
3
- import { ExtensionMediaRequest, IUIExtension } from './IExtension';
2
+ import { UIActionDTO } from '../../../common/entities/extension/IClientUIConfig';
3
+ import { UserRoles } from '../../../common/entities/UserDTO';
4
+ import { IUIExtension, UIAction } from './IExtension';
4
5
  export declare class UIExtension<C> implements IUIExtension<C> {
5
- private extensionObject;
6
- buttonConfigs: IClientMediaButtonConfig[];
6
+ private readonly extensionObject;
7
+ /** The valid actions, in the order they were added. */
8
+ readonly actions: UIAction<unknown>[];
9
+ private readonly routes;
7
10
  constructor(extensionObject: ExtensionObject<C>);
8
- addMediaButton(buttonConfig: IClientMediaButtonConfig, serverSB?: (req: ExtensionMediaRequest) => Promise<void>): void;
11
+ /**
12
+ * The role an action needs.
13
+ */
14
+ private static minRole;
15
+ /**
16
+ * Why the action is invalid, or null if it is valid.
17
+ */
18
+ private static validate;
19
+ private static validateWhen;
20
+ private static validateAction;
21
+ private static validateForm;
22
+ /**
23
+ * Only the fields the browser needs: no handler, nor anything else the extension put on the object.
24
+ */
25
+ private static toDTO;
26
+ addAction<D>(action: UIAction<D>): void;
27
+ /**
28
+ * Removed in 4.0, and from the types. An old extension that still calls it gets a log line, not a crash.
29
+ */
30
+ addMediaButton(config?: {
31
+ name?: unknown;
32
+ }): void;
33
+ /**
34
+ * The actions that a user with the role may see, as the browser gets them. None without a role (e.g. the login page).
35
+ */
36
+ getActionDTOs(role: UserRoles | undefined): UIActionDTO[];
9
37
  }
@@ -1,6 +1,7 @@
1
1
  import { Express } from 'express';
2
2
  export declare class ExtensionRouter {
3
3
  static route(app: Express): void;
4
+ private static addUIConfig;
4
5
  private static addExtensionList;
5
6
  private static addExtensionInstall;
6
7
  private static addExtensionReload;
@@ -0,0 +1,21 @@
1
+ import { UserRoles } from './entities/UserDTO';
2
+ import { MediaDTO } from './entities/MediaDTO';
3
+ import { IMetadataFilter, UIWhen } from './entities/extension/IClientUIConfig';
4
+ export declare const ExtensionActionUtils: {
5
+ /**
6
+ * The role an action needs if its `when.minRole` is not set: a clickable action is not for sharing links by default.
7
+ */
8
+ defaultMinRole: (clickable: boolean) => UserRoles;
9
+ /**
10
+ * The route that runs an action, relative to the api path.
11
+ */
12
+ actionPath: (extensionId: string, actionId: string) => string;
13
+ /**
14
+ * True if every given part of `when` matches the media and the role.
15
+ */
16
+ matchesWhen: (when: UIWhen | undefined, media: MediaDTO, role: UserRoles | undefined) => boolean;
17
+ /**
18
+ * True if every filter matches (AND).
19
+ */
20
+ matchesMetadata: (filters: IMetadataFilter[], metadata: unknown) => boolean;
21
+ };
@@ -1,162 +1,157 @@
1
1
  import { UserRoles } from '../UserDTO';
2
+ import { CameraMetadata, FaceRegion, PositionMetaData } from '../PhotoDTO';
3
+ import { MediaDimension } from '../MediaDTO';
2
4
  export type IClientMediaFields = 'title' | 'caption' | 'cameraData' | 'positionData' | 'faces' | 'keywords' | 'size' | 'creationDate' | 'creationDateOffset' | 'bitRate' | 'duration' | 'fileSize' | 'fps';
3
5
  export interface IClientSVGIconConfig {
4
6
  /**
5
- * SVG path viewBox. See: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
7
+ * SVG path viewBox, '0 0 512 512' if not set. See: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
6
8
  */
7
- viewBox: string;
9
+ viewBox?: string;
8
10
  /**
9
11
  * Content elements (paths, circles, rects) of the SVG icon. Icons used on the map: fontawesome.com/icons.
10
12
  */
11
13
  items: string;
12
14
  }
13
- export interface IClientMediaButtonPopupFields {
15
+ export type MetadataFilterComparator = '>=' | '<=' | '==' | 'contains' | '!contains';
16
+ export interface IMetadataFilter {
17
+ /** Path of a metadata field, e.g. 'rating' or 'size.width'. */
18
+ field: string;
19
+ comparator: MetadataFilterComparator;
20
+ value: string | number;
21
+ }
22
+ /**
23
+ * When a UI contribution shows up. All the given fields must match.
24
+ * It only hides UI: the server enforces `minRole` on the routes it generates, but not on your own endpoints.
25
+ */
26
+ export interface UIWhen {
14
27
  /**
15
- * Id of the field. This how it will be listed in the body.
28
+ * The lowest role that sees it.
29
+ * Default: `User` for an action with a handler, `LimitedGuest` (everyone, also sharing links) otherwise.
16
30
  */
17
- id: string;
31
+ minRole?: UserRoles;
32
+ /** Only photos or only videos. */
33
+ media?: 'photo' | 'video';
18
34
  /**
19
- * Type of the field.
35
+ * Matched against the metadata of the media, e.g.:
36
+ * [
37
+ * {field: 'rating', comparator: '==', value: 4}, // matches if rating is 4
38
+ * {field: 'size.width', comparator: '>=', value: 400}, // matches if width is >= 400px
39
+ * {field: 'keywords', comparator: 'contains', value: 'favorite'}, // matches if the keywords include 'favorite'
40
+ * {field: 'keywords', comparator: '!contains', value: 'favorite'} // matches if they don't (or if there are no keywords)
41
+ * ]
42
+ * 'contains' and '!contains' work on arrays (exact item match) and on strings (substring match).
43
+ * Matching is case-sensitive. On other field types (e.g. numbers) 'contains' never matches, so '!contains' always does.
20
44
  */
45
+ metadata?: IMetadataFilter[];
46
+ }
47
+ export interface UIFormField {
48
+ /**
49
+ * Id of the field: its key in `data.customFields`.
50
+ */
51
+ id: string;
21
52
  type: 'string' | 'number' | 'boolean';
22
53
  /**
23
- * Label of the field. This string will be shown in the popup.
54
+ * Label of the field, shown in the popup.
24
55
  */
25
56
  label: string;
26
57
  /**
27
- * Default value of the field. Should appropriately to the type.
58
+ * Default value of the field, of its type.
28
59
  */
29
60
  defaultValue?: string | number | boolean;
30
61
  /**
31
- * Keep value across popups. Use this if you would like to use the same value on multiple popups (e.g.: like adding the same keyword to multiple photos).
62
+ * Keep the last value for the next popup of the same action (e.g. to add the same keyword to many photos).
32
63
  */
33
64
  keepValue?: boolean;
34
65
  /**
35
- * If true, the field will be required.
36
- * If boolean, the field will be required to be true to click the button.
66
+ * The field must be filled in; a boolean must be true.
37
67
  */
38
68
  required?: boolean;
39
69
  }
40
- export interface IClientMediaButtonPopupConfig {
41
- /**
42
- * Header of the popup.
43
- */
70
+ /**
71
+ * The built-in form popup of an action.
72
+ */
73
+ export interface UIFormDTO {
74
+ /** Header of the popup, the action's `label` if not set. */
44
75
  header?: string;
45
- /**
46
- * Body of the popup.
47
- */
76
+ /** Text above the fields. */
48
77
  body?: string;
49
- /**
50
- * Button text on the action button.
51
- */
52
- buttonString?: string;
53
- /**
54
- * Fields to show in the popup as editable text fields.
55
- */
78
+ /** Text of the submit button. */
79
+ submitLabel?: string;
80
+ /** Existing metadata of the media to show as editable fields. They arrive as `data.fields`, with their own types. */
56
81
  fields?: IClientMediaFields[];
57
- /**
58
- * Custom fields to show in the popup.
59
- */
60
- customFields?: IClientMediaButtonPopupFields[];
82
+ /** Your own fields. They arrive as `data.customFields`. */
83
+ customFields?: UIFormField[];
61
84
  }
62
85
  /**
63
- * Data that will be sent to the server side when the media button is clicked.
64
- * The data will be sent as a JSON object.
65
- * The keys of the object will be the field names.
66
- * The values will be the field values.
86
+ * What the form popup sends: the keys are the field ids, the values what the user entered.
67
87
  */
68
- export interface IMediaRequestBodyData {
88
+ export interface UIFormData {
69
89
  /**
70
- * Existing metadata fields of a media.
71
- * The numeric ones stay numbers, unless the user edited them in the popup.
90
+ * The metadata fields of the form, as the user left them (with their original type: objects, lists and numbers).
91
+ * A number the user cleared is null, so saving the field clears it too.
92
+ * They come from the browser: check them before you save them.
72
93
  */
73
94
  fields?: {
74
95
  title?: string;
75
96
  caption?: string;
76
- cameraData?: string;
77
- positionData?: string;
78
- faces?: string;
79
- size?: string;
80
- creationDate?: string | number;
97
+ cameraData?: CameraMetadata;
98
+ positionData?: PositionMetaData;
99
+ /** The faces of the media, maybe renamed: each keeps its region, so the popup can't add or remove one. */
100
+ faces?: FaceRegion[];
101
+ size?: MediaDimension;
102
+ creationDate?: number;
81
103
  creationDateOffset?: string;
82
- bitRate?: string | number;
83
- duration?: string | number;
84
- fileSize?: string | number;
85
- fps?: string | number;
86
- keywords?: string;
104
+ bitRate?: number | null;
105
+ duration?: number;
106
+ fileSize?: number;
107
+ fps?: number | null;
108
+ keywords?: string[];
87
109
  };
88
110
  customFields?: Record<string, string | number | boolean>;
89
111
  }
90
- export type MetadataFilterComparator = '>=' | '<=' | '==' | 'contains' | '!contains';
91
- export interface IMetadataFilter {
92
- field: string;
93
- comparator: MetadataFilterComparator;
94
- value: string | number;
95
- }
96
- export interface IClientMediaButtonConfig {
97
- /**
98
- * Name of the button. This is also used as id.
99
- */
100
- name: string;
101
- /**
102
- * Icon of the button. This will be shown in the gallery and also in the lightbox.
103
- * You can look for icons here: https://fontawesome.com
104
- */
112
+ /** What an action works on. Later releases add more. */
113
+ export type UIActionTarget = 'media';
114
+ /** Where an action's button appears. Later releases add more (e.g. the lightbox). */
115
+ export type UIActionPlacement = 'mediaTile';
116
+ /** What the app does after the action succeeded. */
117
+ export type UIActionAfter = 'none' | 'reloadContent' | 'reloadSite';
118
+ /**
119
+ * The parts of an action that the browser gets too.
120
+ */
121
+ export interface UIActionBase {
122
+ /** Unique within the extension; letters, digits, '-' and '_'. */
123
+ id: string;
124
+ /** Tooltip and screen-reader label of the button; the header of the popup, if it has none. */
125
+ label: string;
126
+ /** Icon of the button, e.g. from https://fontawesome.com */
105
127
  svgIcon: IClientSVGIconConfig;
106
- /**
107
- * If true, the button will be hidden on photos
108
- */
109
- skipPhotos?: boolean;
110
- /**
111
- * If true, the button will be hidden on videos
112
- */
113
- skipVideos?: boolean;
114
- /**
115
- * If set, the button will only be shown if the metadata matches this filter.
116
- * example values:
117
- * [
118
- * {field: 'rating', comparator: '==', value: 4}, // matches if rating is 4
119
- * {field: 'size.width', comparator: '>=', value: 400}, // matches if width is >= 400px
120
- * {field: 'keywords', comparator: 'contains', value: 'favorite'}, // matches if the keywords include 'favorite'
121
- * {field: 'keywords', comparator: '!contains', value: 'favorite'} // matches if they don't (or if there are no keywords)
122
- * ]
123
- * 'contains' and '!contains' work on arrays (exact item match) and on strings (substring match).
124
- * Matching is case-sensitive. On other field types (e.g. numbers) 'contains' never matches, so '!contains' always does.
125
- */
126
- metadataFilter?: IMetadataFilter[];
127
- /**
128
- * If true, the button will always be visible, not only on hover.
129
- */
128
+ target: UIActionTarget;
129
+ /** Where the button appears; nothing appears where the action doesn't ask for it. */
130
+ placements: UIActionPlacement[];
131
+ when?: UIWhen;
132
+ /** Media tiles: always shown, not only on hover. */
130
133
  alwaysVisible?: boolean;
131
- /**
132
- * Path to the server side function that will be called when the button is clicked.
133
- * If it is not set, it will be a fake button. (i.e.: only shows up but does not do anything)
134
- */
135
- apiPath?: string;
136
- /**
137
- * Popup config. IF you want conformation before calling the apiPath or want to change media metedata, set this.
138
- */
139
- popup?: IClientMediaButtonPopupConfig;
140
- /**
141
- * If true, after calling the apiPath, the gallery content will be reloaded. (faster than reloadContent)
142
- */
143
- reloadContent?: boolean;
144
- /**
145
- * If true, after calling the apiPath, the whole webpage will be reloaded. (slower than reloadSite)
146
- */
147
- reloadSite?: boolean;
148
- /**
149
- * If set, the button will only be shown to users with this role or higher.
150
- */
151
- minUserRole?: UserRoles;
152
- /**
153
- * If set, the button click will not invalidate the directory.
154
- * Upon invalidation, the whole directory will be recalculated.
155
- * If you change any media file, you should set this to false.
156
- */
157
- skipDirectoryInvalidation?: boolean;
158
134
  }
135
+ /**
136
+ * An action as the browser gets it. Without `action`, it is only an indicator (not clickable).
137
+ */
138
+ export interface UIActionDTO extends UIActionBase {
139
+ action?: {
140
+ form?: UIFormDTO;
141
+ after?: UIActionAfter;
142
+ };
143
+ }
144
+ /**
145
+ * The UI contributions of an extension that the current user may see.
146
+ */
159
147
  export interface UIExtensionDTO {
160
- extensionBasePath: string;
161
- mediaButtons: IClientMediaButtonConfig[];
148
+ extensionId: string;
149
+ actions: UIActionDTO[];
150
+ }
151
+ /**
152
+ * The body of the route that runs an action: the media paths (relative to the media folder) and the form data.
153
+ */
154
+ export interface UIActionRequestBody<D = UIFormData> {
155
+ items: string[];
156
+ data: D;
162
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pigallery2-extension-kit",
3
- "version": "3.9.0-edge",
3
+ "version": "3.9.1-edge",
4
4
  "description": "Interfaces for developing extensions for pigallery2",
5
5
  "author": "Patrik J. Braun",
6
6
  "homepage": "https://github.com/bpatrik/pigallery2",