Require Immich 3.x; code cleanup
This commit is contained in:
@@ -3,12 +3,10 @@ import { resolve } from 'path'
|
||||
|
||||
export type Config = Record<string, unknown>
|
||||
|
||||
/** Where each app keeps its config file, and how it upgrades legacy config shapes. */
|
||||
/** Where each app keeps its config file. */
|
||||
export interface LoadConfigOptions {
|
||||
/** Absolute path of the bundled config file, used when `IPP_CONFIG` is unset. */
|
||||
defaultPath?: string
|
||||
/** Rewrites legacy keys in place before the config is cached. */
|
||||
migrate?: (config: Config) => void
|
||||
}
|
||||
|
||||
// Module-level cache populated by `loadConfig()`. Access through
|
||||
@@ -19,8 +17,8 @@ let currentConfig: Config = {}
|
||||
|
||||
/**
|
||||
* Read the runtime configuration from `process.env.CONFIG` (an inline JSON
|
||||
* string, typically set in docker-compose) or from the config file. Applies
|
||||
* the app's `migrate` hook, caches the result, and returns it.
|
||||
* string, typically set in docker-compose) or from the config file, cache
|
||||
* the result, and return it.
|
||||
*
|
||||
* The default path comes from the app, not from this module's location:
|
||||
* core is compiled into its own package, so a path relative to `__dirname`
|
||||
@@ -29,7 +27,7 @@ let currentConfig: Config = {}
|
||||
* Called once from each app's `index.ts` at startup. Safe to call again in
|
||||
* tests with a fresh env to reset state.
|
||||
*/
|
||||
export function loadConfig ({ defaultPath, migrate }: LoadConfigOptions = {}): Config {
|
||||
export function loadConfig ({ defaultPath }: LoadConfigOptions = {}): Config {
|
||||
let config: Config = {}
|
||||
try {
|
||||
if (process.env.CONFIG) {
|
||||
@@ -48,7 +46,6 @@ export function loadConfig ({ defaultPath, migrate }: LoadConfigOptions = {}): C
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
migrate?.(config)
|
||||
currentConfig = config
|
||||
return config
|
||||
}
|
||||
|
||||
+1
-17
@@ -1,7 +1,5 @@
|
||||
import { NextFunction, Request, Response } from 'express-serve-static-core'
|
||||
import { getConfigOption } from './config/access'
|
||||
import { respondToInvalidRequest } from './invalidRequest'
|
||||
import { log } from './utils/log'
|
||||
|
||||
/**
|
||||
* Apply the response headers configured under `ipp.responseHeaders` to the
|
||||
@@ -15,7 +13,7 @@ export function addResponseHeaders (res: Response): void {
|
||||
})
|
||||
}
|
||||
|
||||
/** Stop browsers and shared caches storing a response from a password-protected share. */
|
||||
/** Stop browsers and shared caches storing a response: a password-protected share, or an error. */
|
||||
export function addNoStoreHeaders (res: Response): void {
|
||||
res.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
|
||||
res.set('Pragma', 'no-cache')
|
||||
@@ -31,17 +29,3 @@ export function asyncHandler (fn: (req: Request, res: Response, next: NextFuncti
|
||||
fn(req, res, next).catch(next)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminal Express error middleware. Logs the error server-side, then applies the
|
||||
* same privacy policy as any other invalid request.
|
||||
*/
|
||||
export function errorHandler (err: unknown, req: Request, res: Response, _next: NextFunction): void {
|
||||
log.error('Error handling ' + req.method + ' ' + req.path + ' - ' +
|
||||
(err instanceof Error ? (err.stack || err.message) : String(err)))
|
||||
if (res.headersSent) {
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
respondToInvalidRequest(res, 404, 'Unhandled error for ' + req.path)
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ export async function accessible () {
|
||||
}
|
||||
|
||||
// Minimum Immich server version IPP is compatible with
|
||||
export const MIN_IMMICH_VERSION: ImmichVersion = { major: 2, minor: 0, patch: 0 }
|
||||
export const MIN_IMMICH_VERSION: ImmichVersion = { major: 3, minor: 0, patch: 0 }
|
||||
|
||||
const formatVersion = (v: ImmichVersion) => `${v.major}.${v.minor}.${v.patch}`
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Response } from 'express-serve-static-core'
|
||||
import { NextFunction, Request, Response } from 'express-serve-static-core'
|
||||
import { getConfigOption } from './config/access'
|
||||
import { addNoStoreHeaders } from './http'
|
||||
import { log } from './utils/log'
|
||||
|
||||
/** The public contract of a 404 handler, kept stable for operator replacements. */
|
||||
@@ -60,7 +61,25 @@ export function setInvalidRequestHandler (fn: InvalidRequestHandler): void {
|
||||
/**
|
||||
* Answer an invalid request through the registered handler. Every caller, in
|
||||
* core and in the apps, goes through here so a replacement applies everywhere.
|
||||
*
|
||||
* Never cacheable: routes apply `ipp.responseHeaders` (a 30-day public TTL by
|
||||
* default) before they know the request is valid.
|
||||
*/
|
||||
export function respondToInvalidRequest (res: Response, defaultResponse: number | string | null, logMessage = ''): void {
|
||||
addNoStoreHeaders(res)
|
||||
handler(res, defaultResponse, logMessage)
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminal Express error middleware. Logs the error server-side, then applies the
|
||||
* same privacy policy as any other invalid request.
|
||||
*/
|
||||
export function errorHandler (err: unknown, req: Request, res: Response, _next: NextFunction): void {
|
||||
log.error('Error handling ' + req.method + ' ' + req.path + ' - ' +
|
||||
(err instanceof Error ? (err.stack || err.message) : String(err)))
|
||||
if (res.headersSent) {
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
respondToInvalidRequest(res, 404, 'Unhandled error for ' + req.path)
|
||||
}
|
||||
|
||||
@@ -10,11 +10,6 @@ export enum KeyType {
|
||||
|
||||
export interface ExifInfo {
|
||||
description?: string;
|
||||
exifImageWidth?: number;
|
||||
exifImageHeight?: number;
|
||||
// EXIF orientation string ("1".."8") or null. Values 5-8 indicate the image
|
||||
// is rotated 90°/270°, so the displayed aspect ratio swaps width/height.
|
||||
orientation?: string | null;
|
||||
// Additional EXIF fields surfaced by Immich for the metadata sidebar
|
||||
// (gated server-side by ipp.showMetadata.exif.* and .location.* config).
|
||||
dateTimeOriginal?: string | null;
|
||||
|
||||
Reference in New Issue
Block a user