pigallery2-extension-kit 3.8.1-edge → 3.9.0-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.
Files changed (32) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +3 -0
  3. package/lib/backend/Logger.d.ts +9 -0
  4. package/lib/backend/ProjectPath.d.ts +4 -0
  5. package/lib/backend/exceptions/SearchQueryTooLargeException.d.ts +13 -0
  6. package/lib/backend/middlewares/user/AuthenticationMWs.d.ts +13 -0
  7. package/lib/backend/middlewares/user/OIDCMWs.d.ts +5 -0
  8. package/lib/backend/model/ObjectManagers.d.ts +7 -0
  9. package/lib/backend/model/database/AlbumManager.d.ts +4 -0
  10. package/lib/backend/model/database/GalleryManager.d.ts +10 -0
  11. package/lib/backend/model/database/IObjectManager.d.ts +4 -0
  12. package/lib/backend/model/database/IndexingManager.d.ts +1 -5
  13. package/lib/backend/model/database/PersonManager.d.ts +18 -5
  14. package/lib/backend/model/database/ProjectedCacheManager.d.ts +5 -1
  15. package/lib/backend/model/database/ProjectionAwareManager.d.ts +4 -0
  16. package/lib/backend/model/database/SessionManager.d.ts +10 -1
  17. package/lib/backend/model/extension/ExpressRouterWrapper.d.ts +23 -8
  18. package/lib/backend/model/extension/ExtensionGallery.d.ts +42 -0
  19. package/lib/backend/model/extension/ExtensionObject.d.ts +2 -0
  20. package/lib/backend/model/extension/ExtensionSessions.d.ts +12 -0
  21. package/lib/backend/model/extension/IExtension.d.ts +124 -19
  22. package/lib/backend/model/extension/UIExtension.d.ts +2 -6
  23. package/lib/backend/model/fileaccess/MetadataLoader.d.ts +4 -0
  24. package/lib/common/SearchQueryUtils.d.ts +5 -0
  25. package/lib/common/config/private/PrivateConfig.d.ts +1 -0
  26. package/lib/common/config/public/ClientConfig.d.ts +13 -0
  27. package/lib/common/config/public/ClientConfig.js +84 -8
  28. package/lib/common/entities/Error.d.ts +1 -0
  29. package/lib/common/entities/Error.js +2 -0
  30. package/lib/common/entities/extension/ExtensionError.d.ts +12 -0
  31. package/lib/common/entities/extension/ExtensionError.js +22 -0
  32. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { IServerExtension, IExtensionObject } from './lib/backend/model/extension/IExtension';
2
+ export { ExtensionError } from './lib/common/entities/extension/ExtensionError';
package/index.js CHANGED
@@ -1,2 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtensionError = void 0;
4
+ var ExtensionError_1 = require("./lib/common/entities/extension/ExtensionError");
5
+ Object.defineProperty(exports, "ExtensionError", { enumerable: true, get: function () { return ExtensionError_1.ExtensionError; } });
@@ -11,6 +11,8 @@ export interface ILogger {
11
11
  }
12
12
  export declare const createLoggerWrapper: (TAG: string) => ILogger;
13
13
  export declare class Logger {
14
+ static fileSizeLimit: number;
15
+ private static logFile;
14
16
  static silly(this: void, ...args: LoggerArgs[]): void;
15
17
  static debug(this: void, ...args: LoggerArgs[]): void;
16
18
  static verbose(this: void, ...args: LoggerArgs[]): void;
@@ -18,5 +20,12 @@ export declare class Logger {
18
20
  static warn(this: void, ...args: LoggerArgs[]): void;
19
21
  static error(this: void, ...args: LoggerArgs[]): void;
20
22
  static logLevelForError(e: ErrorCodes): LoggerFunction;
23
+ static closeFile(): void;
24
+ /**
25
+ * Appends a line to Config.Server.Log.file (if set), e.g. for Fail2Ban on hosts without journald (#519).
26
+ * Writes are synchronous, like console output to a file or pipe.
27
+ * If the file can't be written, it logs that once to the console and skips the file until the setting changes.
28
+ */
29
+ private static writeToFile;
21
30
  private static log;
22
31
  }
@@ -11,6 +11,10 @@ export declare class ProjectPathClass {
11
11
  private cfg;
12
12
  init(cfg: PrivateConfigClass): void;
13
13
  normalizeRelative(pathStr: string): string;
14
+ /**
15
+ * Normalises a path from a request, relative to ImageFolder. Null if it would point outside of it.
16
+ */
17
+ normalizeRequestPath(pathStr: string | undefined): string | null;
14
18
  getAbsolutePath(pathStr: string): string;
15
19
  getRelativePathToImages(pathStr: string): string;
16
20
  /**
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The DB refused a search query for its size (too many SQL parameters or a too deep expression).
3
+ * This mostly happens with "some of" queries: they are expanded to every combination of their items.
4
+ */
5
+ export declare class SearchQueryTooLargeException extends Error {
6
+ readonly dbError: unknown;
7
+ private static readonly DB_LIMIT_ERRORS;
8
+ constructor(dbError: unknown);
9
+ /**
10
+ * Returns a SearchQueryTooLargeException if the DB error is about the query size, otherwise the error itself.
11
+ */
12
+ static fromDBError(err: unknown): unknown;
13
+ }
@@ -1,6 +1,7 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
2
  import { UserRoles } from '../../../common/entities/UserDTO';
3
3
  export declare class AuthenticationMWs {
4
+ private static proxyWarningShown;
4
5
  static tryAuthenticate(req: Request, res: Response, next: NextFunction): Promise<void>;
5
6
  static authenticate(req: Request, res: Response, next: NextFunction): Promise<void>;
6
7
  static normalizePathParam(paramName: string): (req: Request, res: Response, next: NextFunction) => void;
@@ -15,6 +16,18 @@ export declare class AuthenticationMWs {
15
16
  * The response for not existing and not available directories. They need to be the same:
16
17
  * GalleryMWs.listDirectory answers not existing directories with the same status and error.
17
18
  */
19
+ /**
20
+ * Logs a failed login in a stable format for fail2ban (see docs/setup/advanced/fail2ban.md):
21
+ * Failed login from IP `<ip>` <details>
22
+ * User input in details must be JSON.stringify-ed: a raw newline would start a new log line
23
+ * that the client controls, e.g. a fake failed login of someone else's IP.
24
+ */
25
+ private static logFailedLogin;
26
+ /**
27
+ * Behind a reverse proxy, req.ip is the proxy's IP unless Server.trustProxy is set,
28
+ * so fail2ban would only ever see (and ban) the proxy. Tell the admin once.
29
+ */
30
+ private static warnIfBehindUntrustedProxy;
18
31
  private static directoryNotFound;
19
32
  static authoriseMedia(paramName: string): (req: Request, res: Response, next: NextFunction) => Promise<void>;
20
33
  static authorise(role: UserRoles): (req: Request, res: Response, next: NextFunction) => void;
@@ -7,4 +7,9 @@ export declare class OIDCMWs {
7
7
  */
8
8
  static redirectToProvider(req: Request, res: Response, next: NextFunction): Promise<void>;
9
9
  static redirectToApp(req: Request, res: Response): void;
10
+ /**
11
+ * The callback is opened by the browser, not by the app: show the error on the login page, not as JSON (#1422).
12
+ * The reason stays in the server log; the login page only tells whether the access was denied.
13
+ */
14
+ static redirectToLoginOnError(err: unknown, req: Request, res: Response, _next: NextFunction): void;
10
15
  }
@@ -33,11 +33,18 @@ export declare class ObjectManagers {
33
33
  private uploadManager;
34
34
  private sessionManager;
35
35
  private initDone;
36
+ private lastDayKey;
37
+ private dayChangePromise;
36
38
  constructor();
37
39
  static getInstance(): ObjectManagers;
38
40
  static reset(): Promise<void>;
39
41
  static isReady(): boolean;
40
42
  init(): Promise<void>;
43
+ /**
44
+ * Calls onNewDay() of the managers once per day key.
45
+ * Called on every request (SessionManager.buildContext), so it is a string compare unless the day changed.
46
+ */
47
+ onDayChangeIfNeeded(): Promise<void>;
41
48
  private initManagers;
42
49
  onDataChange(changedDir?: DirectoryPathDTO | null): Promise<void>;
43
50
  get VersionManager(): VersionManager;
@@ -12,6 +12,10 @@ export declare class AlbumManager extends ProjectionAwareManager<AlbumBaseEntity
12
12
  deleteAlbum(id: number): Promise<void>;
13
13
  deleteAll(): Promise<void>;
14
14
  protected loadEntities(session: SessionContext): Promise<AlbumBaseEntity[]>;
15
+ /**
16
+ * Albums whose own query has a relative date change daily, also for projection keys that do not.
17
+ */
18
+ onNewDay(): Promise<void>;
15
19
  protected invalidateDBCache(): Promise<void>;
16
20
  private updateAlbums;
17
21
  }
@@ -26,7 +26,17 @@ export declare class GalleryManager {
26
26
  * Sets cover for the directory and caches it in the DB
27
27
  */
28
28
  fillCacheForSubDir(connection: DataSource, session: SessionContext, dir: SubDirectoryDTO): Promise<void>;
29
+ /**
30
+ * Splits a media path (relative to the media folder) into the columns it is stored in.
31
+ */
32
+ private static splitMediaPath;
29
33
  getMedia(session: SessionContext, mediaPath: string): Promise<MediaEntity | null>;
34
+ /**
35
+ * The media of the paths (normalised, relative to the media folder), in the same order, with the projection of the session.
36
+ * Null for a path that does not exist or is hidden by the projection.
37
+ * Batched: one query for the directories and one for the media per chunk, no tuple IN (not portable).
38
+ */
39
+ getMediaList(session: SessionContext, mediaPaths: string[]): Promise<(MediaEntity | null)[]>;
30
40
  authoriseMedia(session: SessionContext, mediaPath: string): Promise<boolean>;
31
41
  /**
32
42
  * Metafiles belong to their directory: they are available if the directory is available (see DirectoryAccess).
@@ -1,6 +1,10 @@
1
1
  import { DirectoryPathDTO } from '../../../common/entities/DirectoryDTO';
2
2
  export interface IObjectManager {
3
3
  onNewDataVersion?: (changedDir?: DirectoryPathDTO) => Promise<void>;
4
+ /**
5
+ * Called once a day (see ObjectManagers.onDayChangeIfNeeded): caches of relative dates (date_pattern) go stale.
6
+ */
7
+ onNewDay?: () => Promise<void>;
4
8
  cleanUp?: () => Promise<void>;
5
9
  init?: () => Promise<void>;
6
10
  }
@@ -13,6 +13,7 @@ export declare class IndexingManager {
13
13
  * does not wait for the DB to be saved
14
14
  */
15
15
  indexDirectory(relativeDirectoryName: string, waitForSave?: boolean): Promise<ParentDirectoryDTO>;
16
+ private hasIndexedFiles;
16
17
  resetDB(): Promise<void>;
17
18
  saveToDB(scannedDirectory: ParentDirectoryDTO): Promise<void>;
18
19
  /**
@@ -25,11 +26,6 @@ export declare class IndexingManager {
25
26
  protected saveChildDirs(connection: DataSource, currentDirId: number, scannedDirectory: ParentDirectoryDTO): Promise<void>;
26
27
  protected saveMetaFiles(connection: DataSource, currentDirID: number, scannedDirectory: ParentDirectoryDTO): Promise<void>;
27
28
  protected saveMedia(connection: DataSource, parentDirId: number, media: MediaDTO[]): Promise<void>;
28
- protected savePersonsToMedia(connection: DataSource, parentDirId: number, scannedFaces: {
29
- name: string;
30
- mediaId: number;
31
- }[]): Promise<void>;
32
29
  private checkSavingReady;
33
30
  private saveChunk;
34
- private insertChunk;
35
31
  }
@@ -1,6 +1,5 @@
1
1
  import { PersonEntry } from './enitites/person/PersonEntry';
2
2
  import { PersonDTO } from '../../../common/entities/PersonDTO';
3
- import { DirectoryPathDTO } from '../../../common/entities/DirectoryDTO';
4
3
  import { SessionContext } from '../SessionContext';
5
4
  import { ProjectionAwareManager } from './ProjectionAwareManager';
6
5
  export declare class PersonManager extends ProjectionAwareManager<PersonEntry> {
@@ -14,10 +13,24 @@ export declare class PersonManager extends ProjectionAwareManager<PersonEntry> {
14
13
  name: string;
15
14
  mediaId: number;
16
15
  }[]): Promise<void>;
17
- protected invalidateDBCache(changedDir?: DirectoryPathDTO & {
18
- id?: number;
19
- }): Promise<void>;
16
+ /**
17
+ * Makes the faces (person - media connections) of some media match the given faces (one per face region):
18
+ * adds the missing persons and connections and removes the connections that are gone.
19
+ * @param scope the media whose faces are given: every media of a directory (indexing) or the listed ones
20
+ */
21
+ saveFaces(scope: {
22
+ directoryId: number;
23
+ } | {
24
+ mediaIds: number[];
25
+ }, faces: {
26
+ name: string;
27
+ mediaId: number;
28
+ }[]): Promise<void>;
29
+ /**
30
+ * Invalidates every person, also on the change of a single directory:
31
+ * the faces are already removed from the DB by then, so the persons who lost their last face there can't be found.
32
+ */
33
+ protected invalidateDBCache(): Promise<void>;
20
34
  protected loadEntities(session: SessionContext): Promise<PersonEntry[]>;
21
- private invalidateAllDBCache;
22
35
  private updateCacheForAll;
23
36
  }
@@ -6,7 +6,11 @@ import { DirectoryPathDTO } from '../../../common/entities/DirectoryDTO';
6
6
  import { SessionContext } from '../SessionContext';
7
7
  import { SearchQueryDTO } from '../../../common/entities/SearchQueryDTO';
8
8
  export declare class ProjectedCacheManager implements IObjectManager {
9
- init(): Promise<void>;
9
+ /**
10
+ * Also runs at startup (ObjectManagers.init), to avoid stale growth.
11
+ * Projection keys with a relative date change daily, so the old ones go away here.
12
+ */
13
+ onNewDay(): Promise<void>;
10
14
  onNewDataVersion(changedDir?: DirectoryPathDTO): Promise<void>;
11
15
  /**
12
16
  * Includes all possible projection keys, including the default one and sharing keys too.
@@ -19,6 +19,10 @@ export declare abstract class ProjectionAwareManager<T> implements IObjectManage
19
19
  * Subclasses can override for more specific behavior.
20
20
  */
21
21
  onNewDataVersion(changedDir?: DirectoryPathDTO): Promise<void>;
22
+ /**
23
+ * Drops the lists of the projection keys that changed with the day (relative dates).
24
+ */
25
+ onNewDay(): Promise<void>;
22
26
  /**
23
27
  * Reset the entire memory cache
24
28
  */
@@ -26,7 +26,16 @@ export declare class SessionManager {
26
26
  * Returns with the final projection query (media and directory allow/block lists) of a sharing.
27
27
  */
28
28
  buildAllowListForSharing(sharing: SharingEntity): SearchQueryDTO | null;
29
- createProjectionKey(q: SearchQueryDTO): string;
29
+ /**
30
+ * Calendar-day stamp combining UTC and local dates (SQLite 'now' is UTC, MySQL CURDATE() is server local,
31
+ * and JS mixes both), so relative-date caches refresh across either midnight without a stale window.
32
+ */
33
+ static getDayKey(): string;
34
+ /**
35
+ * The only place that builds a projection key: buildContext and the cache cleanup (getAllProjections) must agree on it.
36
+ */
37
+ createProjectionKey(q: SearchQueryDTO | null): string;
38
+ getProjectionKeyForUser(user: SessionUser): string;
30
39
  buildContext(user: SessionUser): Promise<SessionContext>;
31
40
  getAvailableUserSessions(): Promise<SessionContext[]>;
32
41
  private buildDirectoryFilter;
@@ -1,11 +1,8 @@
1
1
  import * as express from 'express';
2
2
  import { NextFunction, Request, Response } from 'express';
3
- import { UserDTO, UserRoles } from '../../../common/entities/UserDTO';
4
- import { ParamsDictionary } from 'express-serve-static-core';
5
- import { ExtensionRoutePaths, IExtensionRESTApi, IExtensionRESTRoute, IMediaRequestBody } from './IExtension';
3
+ import { UserRoles } from '../../../common/entities/UserDTO';
4
+ import { ExtensionMediaRequest, ExtensionPublicRequest, ExtensionRequest, ExtensionRoutePaths, IExtensionRESTApi, IExtensionRESTRoute } from './IExtension';
6
5
  import { ILogger } from '../../Logger';
7
- import { MediaEntity } from '../database/enitites/MediaEntity';
8
- import { Repository } from 'typeorm';
9
6
  export declare class ExpressRouterWrapper implements IExtensionRESTApi {
10
7
  private readonly router;
11
8
  private readonly name;
@@ -23,9 +20,27 @@ export declare class ExpressRouteWrapper implements IExtensionRESTRoute {
23
20
  private readonly func;
24
21
  private readonly extLogger;
25
22
  constructor(router: express.Router, name: string, func: 'get' | 'use' | 'put' | 'post' | 'delete', extLogger: ILogger);
26
- mediaJsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, invalidateDirectory: boolean, cb: (params: ParamsDictionary, body: IMediaRequestBody, user: UserDTO, media: MediaEntity, repository: Repository<MediaEntity>) => unknown): string;
27
- jsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, cb: (params?: ParamsDictionary, body?: unknown, user?: UserDTO) => unknown): string;
28
- rawMiddleware<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, mw: (req: Request, res: Response, next: NextFunction) => void | Promise<void>): string;
23
+ mediaJsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, invalidateDirectory: boolean, cb: (req: ExtensionMediaRequest) => unknown): string;
24
+ jsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, cb: (req: ExtensionRequest) => unknown): string;
25
+ jsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: null, cb: (req: ExtensionPublicRequest) => unknown): string;
26
+ rawMiddleware<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles | null, mw: (req: Request, res: Response, next: NextFunction) => void | Promise<void>): string;
27
+ /**
28
+ * The object the callbacks get. A public route has no session (and no user).
29
+ */
30
+ private request;
31
+ /**
32
+ * An ExtensionError is sent with its status and message; anything else is logged and answered with a generic 500,
33
+ * so no internals reach the client.
34
+ */
35
+ private handleError;
36
+ /**
37
+ * Callbacks get one object since 4.0. One that declares more parameters expects the old positional arguments:
38
+ * it would get the object as `params` and undefined for the rest, so its route is not registered.
39
+ */
40
+ private isObjectCallback;
41
+ private skip;
42
+ private fullPaths;
43
+ private apiPath;
29
44
  /**
30
45
  * Registers the route on the extension's router.
31
46
  * A route that can't be registered (usually an old extension with an Express 4 path) is logged and skipped:
@@ -0,0 +1,42 @@
1
+ import { FindOptionsWhere } from 'typeorm';
2
+ import { ExtensionSession, IExtensionGallery, IExtensionMediaRepository } from './IExtension';
3
+ import { MediaEntity } from '../database/enitites/MediaEntity';
4
+ import { SessionContext } from '../SessionContext';
5
+ import { DirectoryPathDTO } from '../../../common/entities/DirectoryDTO';
6
+ export declare class ExtensionGallery implements IExtensionGallery {
7
+ getMedia(session: ExtensionSession, path: string): Promise<MediaEntity>;
8
+ getMediaList(session: ExtensionSession, paths: string[]): Promise<MediaEntity[]>;
9
+ getMediaRepository(session: ExtensionSession): IExtensionMediaRepository;
10
+ }
11
+ /**
12
+ * Media table access through the projection of a session, see {@link IExtensionMediaRepository}.
13
+ */
14
+ export declare class ExtensionMediaRepository implements IExtensionMediaRepository {
15
+ private readonly context;
16
+ private readonly deferInvalidation;
17
+ private readonly changedDirs;
18
+ /**
19
+ * @param context the session whose projection applies
20
+ * @param deferInvalidation collect the changed directories until {@link invalidateChanged}
21
+ * (a media route invalidates once, after its callback), instead of invalidating after every call
22
+ */
23
+ constructor(context: SessionContext, deferInvalidation?: boolean);
24
+ find(where?: FindOptionsWhere<MediaEntity> | FindOptionsWhere<MediaEntity>[], options?: {
25
+ skip?: number;
26
+ take?: number;
27
+ }): Promise<MediaEntity[]>;
28
+ save(media: MediaEntity | MediaEntity[]): Promise<void>;
29
+ delete(media: MediaEntity | MediaEntity[]): Promise<void>;
30
+ /**
31
+ * Invalidates the caches of the directories that changed since the last call.
32
+ */
33
+ invalidateChanged(extraDir?: DirectoryPathDTO & {
34
+ id: number;
35
+ }): Promise<void>;
36
+ private static faceNames;
37
+ /**
38
+ * The current DB rows of the media, by id, if the session may see every one of them.
39
+ */
40
+ private loadVisible;
41
+ private changed;
42
+ }
@@ -5,6 +5,7 @@ import { ExpressRouterWrapper } from './ExpressRouterWrapper';
5
5
  import { ExtensionMessengerHandler } from './ExtensionMessengerHandler';
6
6
  import { ExtensionConfig } from './ExtensionConfig';
7
7
  import { UIExtension } from './UIExtension';
8
+ import { ExtensionGallery } from './ExtensionGallery';
8
9
  export declare class ExtensionObject<C> implements IExtensionObject<C> {
9
10
  readonly extensionId: string;
10
11
  readonly extensionName: string;
@@ -18,6 +19,7 @@ export declare class ExtensionObject<C> implements IExtensionObject<C> {
18
19
  readonly RESTApi: ExpressRouterWrapper;
19
20
  readonly messengers: ExtensionMessengerHandler;
20
21
  readonly ui: UIExtension<C>;
22
+ readonly gallery: ExtensionGallery;
21
23
  /** The REST API routes of this extension. They go away with this object on clean up. */
22
24
  readonly router: import("express-serve-static-core").Router;
23
25
  private readonly eventsTracker;
@@ -0,0 +1,12 @@
1
+ import { SessionContext } from '../SessionContext';
2
+ import { ExtensionSession } from './IExtension';
3
+ /**
4
+ * Turns the request's SessionContext into the opaque session that extensions get, and back.
5
+ * The context stays in a WeakMap, so extensions can't read or change the projection, and a session object
6
+ * the app did not create is refused.
7
+ */
8
+ export declare class ExtensionSessions {
9
+ private static readonly contexts;
10
+ static wrap(context: SessionContext): ExtensionSession;
11
+ static unwrap(session: ExtensionSession): SessionContext;
12
+ }
@@ -6,7 +6,7 @@ import { ProjectPathClass } from '../../ProjectPath';
6
6
  import { ILogger } from '../../Logger';
7
7
  import { UserDTO, UserRoles } from '../../../common/entities/UserDTO';
8
8
  import { ParamsDictionary } from 'express-serve-static-core';
9
- import { DataSource, Repository } from 'typeorm';
9
+ import { DataSource, FindOptionsWhere } from 'typeorm';
10
10
  import { DynamicConfig } from '../../../common/entities/DynamicConfig';
11
11
  import { MediaDTOWithThPath } from '../messenger/Messenger';
12
12
  import { PhotoMetadata } from '../../../common/entities/PhotoDTO';
@@ -117,6 +117,10 @@ export interface IExtensionEvents {
117
117
  };
118
118
  };
119
119
  }
120
+ /**
121
+ * DANGEROUS: the internals of the app, with no projection or media access checks.
122
+ * The managers return everything, also what the user of a request may not see. Prefer the other APIs of {@link IExtensionObject}.
123
+ */
120
124
  export interface IExtensionApp {
121
125
  expressApp: express.Express;
122
126
  objectManagers: ObjectManagers;
@@ -126,6 +130,87 @@ export interface IMediaRequestBody {
126
130
  data: IMediaRequestBodyData;
127
131
  media: string;
128
132
  }
133
+ /**
134
+ * The session of a request: who asks and which projection (what they may see) applies.
135
+ * Pass it to the `extension.gallery` helpers; it only works with the session object the app gave you.
136
+ */
137
+ export interface ExtensionSession {
138
+ readonly user: {
139
+ readonly id: number;
140
+ readonly name: string;
141
+ readonly role: UserRoles;
142
+ };
143
+ /** Same for every session that may see the same media; use it as a cache key. */
144
+ readonly projectionKey: string;
145
+ }
146
+ /**
147
+ * What a REST callback gets.
148
+ */
149
+ export interface ExtensionRequest<B = unknown> {
150
+ /** Route params, e.g. `id` of `/item/:id`. */
151
+ params: ParamsDictionary;
152
+ /** The query string, parsed. */
153
+ query: Request['query'];
154
+ /** The JSON body, `{}` if the request has none. */
155
+ body: B;
156
+ user: UserDTO;
157
+ session: ExtensionSession;
158
+ }
159
+ /**
160
+ * What the callback of a public route (`minRole: null`) gets: there is no session.
161
+ */
162
+ export type ExtensionPublicRequest<B = unknown> = Omit<ExtensionRequest<B>, 'user' | 'session'> & {
163
+ user: undefined;
164
+ session: undefined;
165
+ };
166
+ /**
167
+ * What a media route callback gets: the media of `body.media`, already checked against the user's projection.
168
+ */
169
+ export interface ExtensionMediaRequest extends ExtensionRequest<IMediaRequestBody> {
170
+ media: MediaEntity;
171
+ /** Writes through it only touch media the user may see, see {@link IExtensionMediaRepository}. */
172
+ repository: IExtensionMediaRepository;
173
+ }
174
+ /**
175
+ * Access to the media table through the projection of a session: it only finds, changes or deletes media the user may see.
176
+ * Every call takes at most 1000 media, and fails as a whole (nothing is written) if one of them is missing or hidden.
177
+ */
178
+ export interface IExtensionMediaRepository {
179
+ /**
180
+ * Media the user may see, with their directory.
181
+ * @param where conditions on the columns of the media, incl. `metadata` (e.g. `{metadata: {rating: 5}}`)
182
+ * @param options `take` is at most 1000
183
+ */
184
+ find(where?: FindOptionsWhere<MediaEntity> | FindOptionsWhere<MediaEntity>[], options?: {
185
+ skip?: number;
186
+ take?: number;
187
+ }): Promise<MediaEntity[]>;
188
+ /**
189
+ * Saves the `metadata` of existing media (by `id`); never inserts, renames or moves a media.
190
+ * Persons follow `metadata.faces`. The data is lost on the next reindexing of the folder or a DB rebuild.
191
+ */
192
+ save(media: MediaEntity | MediaEntity[]): Promise<void>;
193
+ /**
194
+ * Removes media (by `id`) from the DB, not from the disk: the next indexing adds them back.
195
+ */
196
+ delete(media: MediaEntity | MediaEntity[]): Promise<void>;
197
+ }
198
+ /**
199
+ * Gallery data, with the projection (what the user may see) of a session applied.
200
+ */
201
+ export interface IExtensionGallery {
202
+ /**
203
+ * The media at the path (relative to the media folder, e.g. `2024/trip/photo.jpg`).
204
+ * Throws an {@link ExtensionError} 404 if it does not exist or the user may not see it.
205
+ */
206
+ getMedia(session: ExtensionSession, path: string): Promise<MediaEntity>;
207
+ /**
208
+ * The media at the paths, in the same order. At most 1000 paths (400 above).
209
+ * Throws an {@link ExtensionError} 404 if one of them does not exist or the user may not see it.
210
+ */
211
+ getMediaList(session: ExtensionSession, paths: string[]): Promise<MediaEntity[]>;
212
+ getMediaRepository(session: ExtensionSession): IExtensionMediaRepository;
213
+ }
129
214
  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'> | '_' | '$';
130
215
  type HasUnnamedParam<P extends string> = P extends `${string}${':' | '*'}${infer Rest}` ? Rest extends `${IdentifierStart}${string}` ? HasUnnamedParam<Rest> : true : false;
131
216
  /**
@@ -142,34 +227,46 @@ export type ExtensionRoutePath<P extends string> = P extends `${string}${'(' | '
142
227
  export type ExtensionRoutePaths<P extends readonly string[]> = {
143
228
  readonly [K in keyof P]: ExtensionRoutePath<P[K]>;
144
229
  };
230
+ /**
231
+ * Every callback gets one object ({@link ExtensionRequest}); a callback that declares more than one parameter
232
+ * (the positional arguments before 4.0) is logged and its route is not registered.
233
+ * Errors: throw an {@link ExtensionError} to answer with its status and message (a 401 logs the user out in the app);
234
+ * anything else is logged and answered with a generic 500.
235
+ */
145
236
  export interface IExtensionRESTRoute {
146
237
  /**
147
- * Looks for req.body.media for the media path and calls the callback with that media entry.
148
- * Sends a pigallery2 standard JSON object with payload or error message back to the client.
238
+ * Looks for `body.media` for the media path and calls the callback with that media,
239
+ * if the user may see it (404 otherwise, also for a missing media).
240
+ * Sends a pigallery2 standard JSON object (`'ok'`) or the error back to the client.
241
+ * Doesn't work on `RESTApi.get`: a GET request has no body.
149
242
  * @param paths RESTapi paths, relative to the extension base endpoint, see {@link ExtensionRoutePath}
150
- * @param invalidateDirectory set to false to prevent invalidating the directory.
151
- * Invalidation is resource-intensive and should be avoided if media or its directory is not changed.
152
- * @param minRole set to null to omit auer check (ie make the endpoint public)
153
- * @param cb function callback. `body` is `{}` if the request has no JSON body.
243
+ * @param minRole the lowest role that may call it. Required: a route without it is logged and not registered.
244
+ * @param invalidateDirectory set to true if the callback changes the media or its directory other than through `repository`
245
+ * (writes through `repository` invalidate on their own). Invalidation is resource-intensive.
246
+ * @param cb function callback
154
247
  * @return newly added REST api path
155
248
  */
156
- mediaJsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, invalidateDirectory: boolean, cb: (params: ParamsDictionary, body: IMediaRequestBody, user: UserDTO, media: MediaEntity, repository: Repository<MediaEntity>) => unknown): string;
249
+ mediaJsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, invalidateDirectory: boolean, cb: (req: ExtensionMediaRequest) => unknown): string;
157
250
  /**
158
- * Sends a pigallery2 standard JSON object with payload or error message back to the client.
251
+ * Sends a pigallery2 standard JSON object with the return value of the callback or the error back to the client.
159
252
  * @param paths RESTapi paths, relative to the extension base endpoint, see {@link ExtensionRoutePath}
160
- * @param minRole set to null to omit auer check (ie make the endpoint public)
161
- * @param cb function callback. `body` is `{}` if the request has no JSON body.
253
+ * @param minRole the lowest role that may call it.
254
+ * DANGEROUS: `null` makes the route public (no login, no user, no session).
255
+ * @param cb function callback
162
256
  * @return newly added REST api path
163
257
  */
164
- jsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, cb: (params?: ParamsDictionary, body?: unknown, user?: UserDTO) => unknown): string;
258
+ jsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, cb: (req: ExtensionRequest) => unknown): string;
259
+ jsonResponse<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: null, cb: (req: ExtensionPublicRequest) => unknown): string;
165
260
  /**
166
- * Exposes a standard expressjs (Express 5) middleware
261
+ * Exposes a standard expressjs (Express 5) middleware.
262
+ * DANGEROUS: no projection or media access checks, only the role check. Use it only for data that every user with
263
+ * `minRole` may see, or check the access yourself (e.g. with `extension.gallery`).
167
264
  * @param paths RESTapi paths, relative to the extension base endpoint, see {@link ExtensionRoutePath}
168
- * @param minRole set to null to omit auer check (ie make the endpoint public)
265
+ * @param minRole the lowest role that may call it. DANGEROUS: `null` makes the route public.
169
266
  * @param mw expressjs middleware. `req.body` is `undefined` if the request has no JSON body.
170
267
  * @return newly added REST api path
171
268
  */
172
- rawMiddleware<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles, mw: (req: Request, res: Response, next: NextFunction) => void | Promise<void>): string;
269
+ rawMiddleware<const P extends readonly string[]>(paths: ExtensionRoutePaths<P>, minRole: UserRoles | null, mw: (req: Request, res: Response, next: NextFunction) => void | Promise<void>): string;
173
270
  }
174
271
  export interface IExtensionRESTApi {
175
272
  use: IExtensionRESTRoute;
@@ -180,7 +277,9 @@ export interface IExtensionRESTApi {
180
277
  }
181
278
  export interface IExtensionDB {
182
279
  /**
183
- * Returns with a typeorm SQL connection
280
+ * Returns with a typeorm SQL connection.
281
+ * DANGEROUS: reads and writes every table, with no projection checks. For the media of the gallery, use
282
+ * `extension.gallery`; this is meant for the extension's own tables (see {@link setExtensionTables}).
184
283
  */
185
284
  getSQLConnection(): Promise<DataSource>;
186
285
  /**
@@ -190,7 +289,8 @@ export interface IExtensionDB {
190
289
  setExtensionTables(tables: Function[]): Promise<void>;
191
290
  /**
192
291
  * Exposes all tables. You can use this if you van to have a foreign key to a built-in table.
193
- * Use with caution. This exposes the app's internal working.
292
+ * DANGEROUS: the app's internal tables, with no projection checks; they change between versions and are
293
+ * dropped on a DB rebuild.
194
294
  */
195
295
  _getAllTables(): Function[];
196
296
  }
@@ -218,10 +318,15 @@ export interface IExtensionObject<C = void> {
218
318
  */
219
319
  extensionName: string;
220
320
  /**
221
- * Inner functionality of the app. Use this with caution.
321
+ * Inner functionality of the app.
322
+ * DANGEROUS: no projection or media access checks, see {@link IExtensionApp}.
222
323
  * If you want to go deeper than the standard exposed APIs, you can try doing so here.
223
324
  */
224
325
  _app: IExtensionApp;
326
+ /**
327
+ * Media of the gallery, as the user of a request may see them.
328
+ */
329
+ gallery: IExtensionGallery;
225
330
  /**
226
331
  * Create extension related configuration
227
332
  */
@@ -265,7 +370,7 @@ export interface IUIExtension<_C> {
265
370
  * @param buttonConfig
266
371
  * @param serverSB If not set the button will be a fake button (i.e.: only show up not clickable)
267
372
  */
268
- addMediaButton(buttonConfig: IClientMediaButtonConfig, serverSB?: (params: ParamsDictionary, body: IMediaRequestBody, user: UserDTO, media: MediaEntity, repository: Repository<MediaEntity>) => Promise<void>): void;
373
+ addMediaButton(buttonConfig: IClientMediaButtonConfig, serverSB?: (req: ExtensionMediaRequest) => Promise<void>): void;
269
374
  }
270
375
  export interface IExtensionConfigInit<C> {
271
376
  /**
@@ -1,13 +1,9 @@
1
1
  import { ExtensionObject } from './ExtensionObject';
2
2
  import { IClientMediaButtonConfig } from '../../../common/entities/extension/IClientUIConfig';
3
- import { UserDTO } from '../../../common/entities/UserDTO';
4
- import { ParamsDictionary } from 'express-serve-static-core';
5
- import { MediaEntity } from '../database/enitites/MediaEntity';
6
- import { IMediaRequestBody, IUIExtension } from './IExtension';
7
- import { Repository } from 'typeorm';
3
+ import { ExtensionMediaRequest, IUIExtension } from './IExtension';
8
4
  export declare class UIExtension<C> implements IUIExtension<C> {
9
5
  private extensionObject;
10
6
  buttonConfigs: IClientMediaButtonConfig[];
11
7
  constructor(extensionObject: ExtensionObject<C>);
12
- addMediaButton(buttonConfig: IClientMediaButtonConfig, serverSB: (params: ParamsDictionary, body: IMediaRequestBody, user: UserDTO, media: MediaEntity, repository: Repository<MediaEntity>) => Promise<void>): void;
8
+ addMediaButton(buttonConfig: IClientMediaButtonConfig, serverSB?: (req: ExtensionMediaRequest) => Promise<void>): void;
13
9
  }
@@ -2,6 +2,10 @@ import { PhotoMetadata } from '../../../common/entities/PhotoDTO';
2
2
  import { VideoMetadata } from '../../../common/entities/VideoDTO';
3
3
  export declare class MetadataLoader {
4
4
  private static readonly EMPTY_METADATA;
5
+ /**
6
+ * Same as exifr.parse(), but always closes the file, also when parsing throws.
7
+ */
8
+ private static parseExif;
5
9
  /**
6
10
  * True if exifr returned nothing but errors (with mergeOutput: false it reports them in an 'errors' section).
7
11
  */
@@ -9,6 +9,11 @@ export declare const SearchQueryUtils: {
9
9
  * False if a part of the query has a type that this version does not know, e.g. a hand-edited or outdated search link.
10
10
  */
11
11
  isKnownQuery: (query: SearchQueryDTO) => boolean;
12
+ /**
13
+ * True if the query (or any nested part of it) contains a relative date (`date_pattern`),
14
+ * whose result depends on the current day.
15
+ */
16
+ hasRelativeDate: (query: SearchQueryDTO | null | undefined) => boolean;
12
17
  validateSearchQuery: (query: SearchQueryDTO, what?: string) => void;
13
18
  /**
14
19
  * Validates a directory allow / block list.
@@ -99,6 +99,7 @@ export declare class ServerDuplicatesConfig {
99
99
  export declare class ServerLogConfig {
100
100
  level: LogLevel;
101
101
  sqlLevel: SQLLogLevel;
102
+ file: string;
102
103
  logServerTiming: boolean;
103
104
  }
104
105
  /**
@@ -180,6 +180,19 @@ export declare class ThemeConfig {
180
180
  constructor(name?: string, theme?: string);
181
181
  }
182
182
  export declare class ThemesConfig {
183
+ /**
184
+ * The themes that ship with the app. applyBuiltInThemes() puts them into availableThemes on every config load and
185
+ * settings save, so they can't be deleted or changed and get the fixes of new releases; the settings page shows them read-only.
186
+ */
187
+ static readonly BUILT_IN_THEMES: readonly {
188
+ name: string;
189
+ theme: string;
190
+ }[];
191
+ static isBuiltInTheme(name: string | undefined): boolean;
192
+ /**
193
+ * Puts the built-in themes (unchanged, first) into availableThemes, keeping the custom ones after them.
194
+ */
195
+ static applyBuiltInThemes(themes: ThemesConfig): void;
183
196
  enabled: boolean;
184
197
  defaultMode: ThemeModes;
185
198
  selectedTheme: string;
@@ -8,6 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var ThemesConfig_1;
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.ClientConfig = exports.ClientUploadConfig = exports.ClientExtensionsConfig = exports.ClientUserConfig = exports.ClientUserOIDCConfig = exports.ClientServiceConfig = exports.ClientFacesConfig = exports.ClientMetaFileConfig = exports.ClientMediaConfig = exports.ClientLivePhotoConfig = exports.ClientGPXCompressingConfig = exports.ClientPhotoConfig = exports.ClientVideoConfig = exports.ClientGalleryConfig = exports.ThemesConfig = exports.ThemeConfig = exports.ClientLightboxConfig = exports.AutoUpdateConfig = exports.ClientLightboxTitleConfig = exports.NavBarConfig = exports.NavBarSortingAndGroupingConfig = exports.ClientDirectoryGroupingConfig = exports.ClientDirectorySortingConfig = exports.ClientGroupingConfig = exports.ClientFaceSortingConfig = exports.ClientSortingConfig = exports.NavigationLinkConfig = exports.ClientMapConfig = exports.MapPathGroupConfig = exports.MapPathGroupThemeConfig = exports.PathThemeConfig = exports.SVGIconConfig = exports.MapLayers = exports.ClientRandomPhotoConfig = exports.ClientSharingConfig = exports.ClientAlbumConfig = exports.ClientSearchConfig = exports.AutoCompleteConfig = exports.AutoCompleteItemsPerCategoryConfig = void 0;
13
14
  /* eslint-disable @typescript-eslint/no-inferrable-types */
@@ -1259,7 +1260,7 @@ __decorate([
1259
1260
  name: $localize `Loop Slideshow`,
1260
1261
  priority: Enums_1.ConfigPriority.underTheHood,
1261
1262
  },
1262
- description: $localize `If enabled, lightbox will start from the first photo when it reached the last one.`
1263
+ description: $localize `If enabled, the lightbox starts over from the first photo after the last one, and going back from the first photo jumps to the last one.`
1263
1264
  }),
1264
1265
  __metadata("design:type", Boolean)
1265
1266
  ], ClientLightboxConfig.prototype, "loopSlideshow", void 0);
@@ -1335,9 +1336,18 @@ let ThemesConfig = class ThemesConfig {
1335
1336
  constructor() {
1336
1337
  this.enabled = true;
1337
1338
  this.defaultMode = Enums_1.ThemeModes.auto;
1338
- this.selectedTheme = 'classic';
1339
- this.availableThemes = [
1340
- new ThemeConfig('classic', ':root nav.navbar {\n' +
1339
+ this.selectedTheme = 'modern';
1340
+ this.availableThemes = ThemesConfig_1.BUILT_IN_THEMES.map(th => new ThemeConfig(th.name, th.theme));
1341
+ }
1342
+ static { ThemesConfig_1 = this; }
1343
+ /**
1344
+ * The themes that ship with the app. applyBuiltInThemes() puts them into availableThemes on every config load and
1345
+ * settings save, so they can't be deleted or changed and get the fixes of new releases; the settings page shows them read-only.
1346
+ */
1347
+ static { this.BUILT_IN_THEMES = [
1348
+ {
1349
+ name: 'classic',
1350
+ theme: ':root nav.navbar {\n' +
1341
1351
  '--bs-navbar-color: rgba(255, 255, 255, 0.55);\n' +
1342
1352
  '--bs-navbar-hover-color: rgba(255, 255, 255, 0.75);\n' +
1343
1353
  '--bs-navbar-disabled-color: rgba(255, 255, 255, 0.25);\n' +
@@ -1346,8 +1356,74 @@ let ThemesConfig = class ThemesConfig {
1346
1356
  '--bs-navbar-brand-hover-color: #fff;\n' +
1347
1357
  '--bs-bg-opacity: 1;\n' +
1348
1358
  'background-color: rgba(var(--bs-dark-rgb), var(--bs-bg-opacity)) !important;\n' +
1349
- '}')
1350
- ];
1359
+ '}'
1360
+ },
1361
+ {
1362
+ name: 'modern',
1363
+ theme: '/* light: a white page; darker borders and loading tiles than in Bootstrap */\n' +
1364
+ 'html:not([data-bs-theme=dark]) {\n' +
1365
+ ' --bs-border-color: #d4d4d8;\n' +
1366
+ ' --item-background: #e4e4e7;\n' +
1367
+ '}\n' +
1368
+ '/* a switch that is off: a darker knob and border than in Bootstrap */\n' +
1369
+ 'html:not([data-bs-theme=dark]) .form-switch .form-check-input:not(:checked):not(:focus) {\n' +
1370
+ ' border-color: #a1a1aa;\n' +
1371
+ ' --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'-4 -4 8 8\'%3e%3ccircle r=\'3\' fill=\'rgba%280, 0, 0, 0.55%29\'/%3e%3c/svg%3e");\n' +
1372
+ '}\n' +
1373
+ '[data-bs-theme=dark] .form-switch .form-check-input:not(:checked):not(:focus) {\n' +
1374
+ ' border-color: #71717a;\n' +
1375
+ ' --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'-4 -4 8 8\'%3e%3ccircle r=\'3\' fill=\'rgba%28255, 255, 255, 0.6%29\'/%3e%3c/svg%3e");\n' +
1376
+ '}\n' +
1377
+ '/* navbar links (e.g. Share): darker than the 65% of Bootstrap */\n' +
1378
+ '.navbar {\n' +
1379
+ ' --bs-navbar-color: rgba(var(--bs-emphasis-color-rgb), .8);\n' +
1380
+ '}\n' +
1381
+ '[data-bs-theme=dark] {\n' +
1382
+ ' --bs-body-bg: #18181b;\n' +
1383
+ ' --bs-body-bg-rgb: 24, 24, 27;\n' +
1384
+ ' --bs-secondary-bg: #27272a;\n' +
1385
+ ' --bs-secondary-bg-rgb: 39, 39, 42;\n' +
1386
+ ' --bs-tertiary-bg: #1f1f23;\n' +
1387
+ ' --bs-tertiary-bg-rgb: 31, 31, 35;\n' +
1388
+ ' --item-background: #2a2a2e;\n' +
1389
+ '}\n' +
1390
+ ':root {\n' +
1391
+ ' accent-color: var(--bs-primary);\n' +
1392
+ ' --item-border: 0;\n' +
1393
+ ' --item-radius: .5rem;\n' +
1394
+ ' --item-hover-scale: 100%;\n' +
1395
+ ' --overlay-background: linear-gradient(transparent, rgba(0, 0, 0, .65));\n' +
1396
+ ' --overlay-hover-background: linear-gradient(transparent, rgba(0, 0, 0, .85));\n' +
1397
+ ' --overlay-text-shadow: 0 1px 2px rgba(0, 0, 0, .6);\n' +
1398
+ ' --overlay-font-size: .875rem;\n' +
1399
+ ' --overlay-button-background: rgba(0, 0, 0, .35);\n' +
1400
+ ' --overlay-button-hover-background: rgba(0, 0, 0, .6);\n' +
1401
+ ' --lightbox-title-background: transparent;\n' +
1402
+ ' --lightbox-title-opacity: .9;\n' +
1403
+ ' --lightbox-title-text-shadow: 0 1px 3px rgba(0, 0, 0, .8);\n' +
1404
+ ' --popover-border: 1px solid var(--bs-border-color);\n' +
1405
+ ' --popover-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 8px 24px rgba(0, 0, 0, .18);\n' +
1406
+ ' --separator-color: var(--bs-border-color);\n' +
1407
+ ' --transition-easing: cubic-bezier(.2, .8, .2, 1);\n' +
1408
+ '}\n' +
1409
+ '@media (prefers-reduced-motion: no-preference) {\n' +
1410
+ ' :root {\n' +
1411
+ ' --item-hover-image-scale: 104%;\n' +
1412
+ ' --fade-in-duration: .3s;\n' +
1413
+ ' }\n' +
1414
+ '}'
1415
+ }
1416
+ ]; }
1417
+ static isBuiltInTheme(name) {
1418
+ return ThemesConfig_1.BUILT_IN_THEMES.some(th => th.name === name);
1419
+ }
1420
+ /**
1421
+ * Puts the built-in themes (unchanged, first) into availableThemes, keeping the custom ones after them.
1422
+ */
1423
+ static applyBuiltInThemes(themes) {
1424
+ const custom = (themes.availableThemes || []).filter(th => !ThemesConfig_1.isBuiltInTheme(th.name))
1425
+ .map(th => new ThemeConfig(th.name, th.theme));
1426
+ themes.availableThemes = [...ThemesConfig_1.BUILT_IN_THEMES.map(th => new ThemeConfig(th.name, th.theme)), ...custom];
1351
1427
  }
1352
1428
  };
1353
1429
  exports.ThemesConfig = ThemesConfig;
@@ -1398,7 +1474,7 @@ __decorate([
1398
1474
  }),
1399
1475
  __metadata("design:type", Array)
1400
1476
  ], ThemesConfig.prototype, "availableThemes", void 0);
1401
- exports.ThemesConfig = ThemesConfig = __decorate([
1477
+ exports.ThemesConfig = ThemesConfig = ThemesConfig_1 = __decorate([
1402
1478
  (0, common_1.SubConfigClass)({ tags: { client: true }, softReadonly: true })
1403
1479
  ], ThemesConfig);
1404
1480
  let ClientGalleryConfig = class ClientGalleryConfig {
@@ -1607,7 +1683,7 @@ let ClientPhotoConfig = class ClientPhotoConfig {
1607
1683
  this.thumbnailSizes = [320, 540, 1080, 2160];
1608
1684
  this.concurrentThumbnailGenerations = 1;
1609
1685
  this.concurrentThumbnailGenerationsLimit = 0;
1610
- this.supportedFormats = ['gif', 'jpeg', 'jpg', 'jpe', 'png', 'webp', 'svg', 'avif', 'heic', 'dng', 'arw', 'tiff'];
1686
+ this.supportedFormats = ['gif', 'jpeg', 'jpg', 'jpe', 'png', 'webp', 'svg', 'avif', 'heic', 'dng', 'arw', 'tiff', 'jxl'];
1611
1687
  }
1612
1688
  /**
1613
1689
  * Generates a map for bitwise operation from icon and normal thumbnails
@@ -21,6 +21,7 @@ export declare enum ErrorCodes {
21
21
  TASK_ERROR = 61,
22
22
  JOB_ERROR = 62,
23
23
  LocationLookUp_ERROR = 63,
24
+ SEARCH_QUERY_TOO_LARGE = 64,
24
25
  ALBUM_ERROR = 70,
25
26
  UPLOAD_ERROR = 80,
26
27
  INTERNAL = 500
@@ -26,6 +26,8 @@ var ErrorCodes;
26
26
  ErrorCodes[ErrorCodes["TASK_ERROR"] = 61] = "TASK_ERROR";
27
27
  ErrorCodes[ErrorCodes["JOB_ERROR"] = 62] = "JOB_ERROR";
28
28
  ErrorCodes[ErrorCodes["LocationLookUp_ERROR"] = 63] = "LocationLookUp_ERROR";
29
+ // the DB refused the search for its size, mostly a "some of" query with too many items
30
+ ErrorCodes[ErrorCodes["SEARCH_QUERY_TOO_LARGE"] = 64] = "SEARCH_QUERY_TOO_LARGE";
29
31
  ErrorCodes[ErrorCodes["ALBUM_ERROR"] = 70] = "ALBUM_ERROR";
30
32
  ErrorCodes[ErrorCodes["UPLOAD_ERROR"] = 80] = "UPLOAD_ERROR";
31
33
  ErrorCodes[ErrorCodes["INTERNAL"] = 500] = "INTERNAL";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Throw it from an extension's REST callback to answer with this HTTP status and message,
3
+ * e.g. `throw new ExtensionError(404, 'No rating yet')`. A 401 logs the user out in the app.
4
+ * Any other error is logged and answered with a generic 500.
5
+ */
6
+ export declare class ExtensionError extends Error {
7
+ readonly status: number;
8
+ /** Recognises the error also when the extension ships its own copy of this class (`instanceof` would fail). */
9
+ readonly isExtensionError = true;
10
+ constructor(status: number, message: string);
11
+ static is(e: unknown): e is ExtensionError;
12
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtensionError = void 0;
4
+ /**
5
+ * Throw it from an extension's REST callback to answer with this HTTP status and message,
6
+ * e.g. `throw new ExtensionError(404, 'No rating yet')`. A 401 logs the user out in the app.
7
+ * Any other error is logged and answered with a generic 500.
8
+ */
9
+ class ExtensionError extends Error {
10
+ constructor(status, message) {
11
+ super(message);
12
+ this.status = status;
13
+ /** Recognises the error also when the extension ships its own copy of this class (`instanceof` would fail). */
14
+ this.isExtensionError = true;
15
+ this.name = 'ExtensionError';
16
+ }
17
+ static is(e) {
18
+ return e instanceof Error && e.isExtensionError === true &&
19
+ typeof e.status === 'number';
20
+ }
21
+ }
22
+ exports.ExtensionError = ExtensionError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pigallery2-extension-kit",
3
- "version": "3.8.1-edge",
3
+ "version": "3.9.0-edge",
4
4
  "description": "Interfaces for developing extensions for pigallery2",
5
5
  "author": "Patrik J. Braun",
6
6
  "homepage": "https://github.com/bpatrik/pigallery2",