Initial work on upload app server

This commit is contained in:
Alan Grainger
2026-10-06 10:07:20 +13:00
parent 9e6c00da35
commit 95ac498cf0
38 changed files with 1493 additions and 40 deletions
+10
View File
@@ -1,6 +1,7 @@
import { NextFunction, Request, Response } from 'express-serve-static-core'
import { resolve } from 'path'
import { getConfigOption } from './config/access'
import { accessible } from './immich/client'
/** Static assets both apps serve from core: pico, the Inter font, the favicon and theme.css. */
export const CORE_PUBLIC_DIR = resolve(__dirname, '../public')
@@ -36,6 +37,15 @@ export function abortOnClose (res: Response): AbortSignal {
return controller.signal
}
/** `GET /healthcheck`: `ok` while Immich answers, else 503. */
export async function healthcheck (_req: Request, res: Response): Promise<void> {
if (await accessible()) {
res.send('ok')
} else {
res.status(503).send()
}
}
/**
* Wrap an async route handler so a rejected promise is passed to Express's
* error chain (and on to `errorHandler`).
+6
View File
@@ -1,5 +1,6 @@
import dayjs from 'dayjs'
import { KeyType, SharedLink, SharedLinkResult } from '../types'
import { getConfigOption } from '../config/access'
import { log } from '../utils/log'
import { cachedPromise, TtlLruCache } from '../utils/ttlLruCache'
import { apiUrl, buildUrl } from './client'
@@ -16,6 +17,11 @@ import { apiUrl, buildUrl } from './client'
*/
const tokenCache = new TtlLruCache<Promise<string | null>>({ ttlMs: 120_000, max: 100 })
/** Whether this is a slug link and the operator has turned slug links off. */
export function slugLinksDisabled (keyType: KeyType): boolean {
return keyType === KeyType.slug && !getConfigOption('ipp.allowSlugLinks', true)
}
/**
* Display title for a shared link. Prefers the user-set link description,
* falls back to the album name (for album shares), or a generic placeholder.
+1
View File
@@ -10,6 +10,7 @@ export * from './config/access'
export * from './http'
export * from './invalidRequest'
export * from './session'
export * from './version'
export * from './encrypt'
export * from './utils/log'
export * from './utils/webStream'
+16
View File
@@ -12,3 +12,19 @@ export function readableFromWeb (body: ReadableStream<Uint8Array>): Readable {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return Readable.fromWeb(body as any)
}
/**
* Build a `fetch` init that streams `body` as the request body.
*
* Node's fetch refuses a stream body unless `duplex: 'half'` is set, but that
* option is absent from the DOM `RequestInit` the project's `lib` resolves
* to, so it has to go on behind a cast.
*/
export function streamingRequestInit (init: RequestInit, body: Readable): RequestInit {
return {
...init,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body: Readable.toWeb(body) as any,
duplex: 'half'
} as RequestInit
}
+15
View File
@@ -0,0 +1,15 @@
import { readFileSync } from 'fs'
/**
* Resolve the running application version. Prefers the APP_VERSION env var
* baked in at Docker build time (see the Dockerfiles); falls back to the
* app's package.json for local dev, and finally to 'dev' if neither is readable.
*/
export function resolveAppVersion (packageJsonPath: string): string {
if (process.env.APP_VERSION) return process.env.APP_VERSION
try {
return JSON.parse(readFileSync(packageJsonPath, 'utf-8')).version || 'dev'
} catch {
return 'dev'
}
}