From 9e6c00da3521fab814d7826474ff7ecfb3fe50b7 Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:28:53 +1300 Subject: [PATCH] Move static assets to shared location --- CONTRIBUTING.md | 5 +- app/public/style.css | 61 +---------------- app/src/index.ts | 20 +++--- app/src/stream/asset.ts | 16 ++--- app/src/view/gallery.tsx | 1 + {app => shared}/public/favicon.ico | Bin .../public/fonts/Inter-LICENSE.txt | 0 .../fonts/inter-latin-wght-normal.woff2 | Bin {app => shared}/public/pico.min.css | 0 shared/public/theme.css | 62 ++++++++++++++++++ shared/src/http.ts | 16 +++++ shared/src/types.ts | 5 ++ 12 files changed, 104 insertions(+), 82 deletions(-) rename {app => shared}/public/favicon.ico (100%) rename {app => shared}/public/fonts/Inter-LICENSE.txt (100%) rename {app => shared}/public/fonts/inter-latin-wght-normal.woff2 (100%) rename {app => shared}/public/pico.min.css (100%) create mode 100644 shared/public/theme.css diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b010be8..3183a77 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,12 +41,13 @@ shared/ @ipp/core - read-side only, knows nothing about galler immich/share.ts fetchSharedLink, password login + token cache, auth headers, title config/loader.ts loadConfig() reads env / file; the app passes its default path config/access.ts getConfigOption() reads the loaded config - http.ts Operator-configured and no-store response headers, asyncHandler + http.ts Operator-configured and no-store response headers, abortOnClose, asyncHandler, CORE_PUBLIC_DIR invalidRequest.ts The 404 policy (never cached), errorHandler, and setInvalidRequestHandler for the app's own handler file session.ts Cookie session, decodeCookie, unlock handler, invalid-password response encrypt.ts Cookie-session encryption for password-protected shares utils/ log, sanitize (filenames), text (escaping), ttlLruCache, webStream view/ Page renderer, theme script, password page + public/ Static assets both apps serve: pico, Inter font, favicon, theme.css (tokens and page base) tests/ Vitest unit tests for core app/ config.json Runtime configuration, overrideable via volume or inline @@ -73,7 +74,7 @@ app/ client/ Client gallery, virtualisation, lightbox, sidebar public/ Static assets served as-is photoswipe/ Vendored PhotoSwipe v5 - thumbhash/, fonts/, images/ + thumbhash/, images/ style.css, photoswipe-overrides.css tests/ Vitest unit tests for IPP docs/ User docs site (VitePress); docs/README.md explains its structure diff --git a/app/public/style.css b/app/public/style.css index 2f7a703..5e3874c 100644 --- a/app/public/style.css +++ b/app/public/style.css @@ -1,50 +1,10 @@ -/* - Tokens ported from immich-app/immich v2.7.5 (web/src/app.css, 2026-05-23). - Re-check approximately once a year for visual drift. - - Font note: Immich uses "GoogleSans" (Google's proprietary font, not freely - distributed). We use a system font stack with Inter from Google Fonts as a - visually-close substitute. Same approach Immich's open-source consumers use. -*/ - -/* Inter (OFL-1.1, see fonts/Inter-LICENSE.txt). Single variable WOFF2 covers - all weights from 100-900, so we can use any weight in CSS without an extra - network request. Vendored locally so IPP runs cleanly air-gapped. */ -@font-face { - font-family: 'Inter'; - src: url('/share/static/fonts/inter-latin-wght-normal.woff2') format('woff2-variations'); - font-weight: 100 900; - font-style: normal; - font-display: swap; -} +/* Theme tokens, the Inter font and the page base come from @ipp/core's theme.css */ :root { - /* Immich light-mode tokens (RGB triplets so they compose via rgb(var(...))) */ - --immich-primary: 66 80 175; - --immich-bg: 255 255 255; - --immich-fg: 0 0 0; - --immich-gray: 235 235 235; - - /* Immich dark-mode tokens */ - --immich-dark-primary: 172 203 250; - --immich-dark-bg: 10 10 10; - --immich-dark-fg: 229 231 235; - --immich-dark-gray: 33 33 33; - - /* Active palette - light by default; html.dark overrides below */ - --color-bg: rgb(var(--immich-bg)); - --color-fg: rgb(var(--immich-fg)); - --color-primary: rgb(var(--immich-primary)); - --color-gray: rgb(var(--immich-gray)); - - --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; - /* Horizontal inset for textual page content (title, description, group headers). The grid itself goes edge-to-edge on mobile so it doesn't use this value. */ --gutter: 32px; - - color-scheme: light; } @media (max-width: 640px) { @@ -53,25 +13,6 @@ } } -html.dark { - --color-bg: rgb(var(--immich-dark-bg)); - --color-fg: rgb(var(--immich-dark-fg)); - --color-primary: rgb(var(--immich-dark-primary)); - --color-gray: rgb(var(--immich-dark-gray)); - - color-scheme: dark; -} - -* { box-sizing: border-box; } - -html, body { - margin: 0; - height: 100%; - background: var(--color-bg); - color: var(--color-fg); - font-family: var(--font-sans); -} - /* ===== Justified-rows / square-grid gallery (tiles are absolute-positioned by JS) ===== */ #gallery { diff --git a/app/src/index.ts b/app/src/index.ts index 93940e6..c75e3d9 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -10,6 +10,7 @@ import { Asset, AssetType, asyncHandler, + CORE_PUBLIC_DIR, decodeCookie, enforceMinimumImmichVersion, errorHandler, @@ -65,17 +66,18 @@ app.use(sessionMiddleware({ name: 'session' })) app.use(express.json()) // For parsing the selective-download form POST (form-encoded body) app.use(express.urlencoded({ extended: false, limit: '1mb' })) +/** Serve IPP's own `public` folder, then core's, at `path`. */ +function serveStatic (path: string, options: Parameters[1] = {}) { + for (const dir of ['public', CORE_PUBLIC_DIR]) { + app.use(path, express.static(dir, { ...options, setHeaders: addResponseHeaders })) + } +} // Cache-busted, immutable static assets under a per-release version segment. const inProduction = process.env.NODE_ENV === 'production' -app.use('/share/static/' + ASSET_VERSION, express.static('public', { - immutable: inProduction, - maxAge: inProduction ? '365d' : 0, - setHeaders: addResponseHeaders -})) -// Serve static assets from the 'public' folder as /share/static -app.use('/share/static', express.static('public', { setHeaders: addResponseHeaders })) -// Serve the same assets on /, to allow for /robots.txt and /favicon.ico -app.use(express.static('public', { setHeaders: addResponseHeaders })) +serveStatic('/share/static/' + ASSET_VERSION, { immutable: inProduction, maxAge: inProduction ? '365d' : 0 }) +serveStatic('/share/static') +// The same assets on /, to allow for /robots.txt and /favicon.ico +serveStatic('/') // Remove the X-Powered-By ExpressJS header app.disable('x-powered-by') diff --git a/app/src/stream/asset.ts b/app/src/stream/asset.ts index 95638a9..a267df8 100644 --- a/app/src/stream/asset.ts +++ b/app/src/stream/asset.ts @@ -1,4 +1,4 @@ -import { Asset, log, readableFromWeb, respondToInvalidRequest, SharedLink } from '@ipp/core' +import { abortOnClose, Asset, log, readableFromWeb, respondToInvalidRequest, SharedLink } from '@ipp/core' import { assetFetchUrl, authHeadersForAsset, @@ -20,14 +20,8 @@ import { pipeline } from 'stream/promises' * to serve them, and the upstream failure surfaces as a client 404. */ export async function assetBuffer (req: IncomingShareRequest, res: Response, asset: Asset, size?: ImageSize | string, share?: SharedLink, forceVideoPlayback = false) { - /* - Abort the upstream fetch as soon as the visitor goes away, so a cancelled - download doesn't leave Immich streaming #288. - */ - const upstream = new AbortController() - const onClose = () => { if (!res.writableFinished) upstream.abort() } - res.once('close', onClose) - if (res.closed) onClose() + // A cancelled download must not leave Immich streaming #288 + const upstream = abortOnClose(res) const headerList = ['content-type', 'content-length', 'last-modified', 'etag'] const fetchHeaders: Record = {} @@ -78,9 +72,9 @@ export async function assetBuffer (req: IncomingShareRequest, res: Response, ass const reqHeaders = await authHeadersForAsset(asset) let data: globalThis.Response try { - data = await fetch(url, { headers: { ...fetchHeaders, ...reqHeaders }, signal: upstream.signal }) + data = await fetch(url, { headers: { ...fetchHeaders, ...reqHeaders }, signal: upstream }) } catch (e) { - if (upstream.signal.aborted) return // visitor left before Immich answered + if (upstream.aborted) return // visitor left before Immich answered throw e } diff --git a/app/src/view/gallery.tsx b/app/src/view/gallery.tsx index 9dc298f..5ae39d5 100644 --- a/app/src/view/gallery.tsx +++ b/app/src/view/gallery.tsx @@ -63,6 +63,7 @@ export function Gallery (props: GalleryProps) { } + diff --git a/app/public/favicon.ico b/shared/public/favicon.ico similarity index 100% rename from app/public/favicon.ico rename to shared/public/favicon.ico diff --git a/app/public/fonts/Inter-LICENSE.txt b/shared/public/fonts/Inter-LICENSE.txt similarity index 100% rename from app/public/fonts/Inter-LICENSE.txt rename to shared/public/fonts/Inter-LICENSE.txt diff --git a/app/public/fonts/inter-latin-wght-normal.woff2 b/shared/public/fonts/inter-latin-wght-normal.woff2 similarity index 100% rename from app/public/fonts/inter-latin-wght-normal.woff2 rename to shared/public/fonts/inter-latin-wght-normal.woff2 diff --git a/app/public/pico.min.css b/shared/public/pico.min.css similarity index 100% rename from app/public/pico.min.css rename to shared/public/pico.min.css diff --git a/shared/public/theme.css b/shared/public/theme.css new file mode 100644 index 0000000..80e4dbd --- /dev/null +++ b/shared/public/theme.css @@ -0,0 +1,62 @@ +/* + Tokens ported from immich-app/immich v2.7.5 (web/src/app.css, 2026-05-23). + Re-check approximately once a year for visual drift. + + Font note: Immich uses "GoogleSans" (Google's proprietary font, not freely + distributed). We use a system font stack with Inter from Google Fonts as a + visually-close substitute. Same approach Immich's open-source consumers use. +*/ + +/* Inter (OFL-1.1, see fonts/Inter-LICENSE.txt). Single variable WOFF2 covers + all weights from 100-900, so we can use any weight in CSS without an extra + network request. Vendored locally so IPP runs cleanly air-gapped. */ +@font-face { + font-family: 'Inter'; + src: url('fonts/inter-latin-wght-normal.woff2') format('woff2-variations'); + font-weight: 100 900; + font-style: normal; + font-display: swap; +} + +:root { + /* Immich light-mode tokens (RGB triplets so they compose via rgb(var(...))) */ + --immich-primary: 66 80 175; + --immich-bg: 255 255 255; + --immich-fg: 0 0 0; + --immich-gray: 235 235 235; + + /* Immich dark-mode tokens */ + --immich-dark-primary: 172 203 250; + --immich-dark-bg: 10 10 10; + --immich-dark-fg: 229 231 235; + --immich-dark-gray: 33 33 33; + + /* Active palette - light by default; html.dark overrides below */ + --color-bg: rgb(var(--immich-bg)); + --color-fg: rgb(var(--immich-fg)); + --color-primary: rgb(var(--immich-primary)); + --color-gray: rgb(var(--immich-gray)); + + --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; + + color-scheme: light; +} + +html.dark { + --color-bg: rgb(var(--immich-dark-bg)); + --color-fg: rgb(var(--immich-dark-fg)); + --color-primary: rgb(var(--immich-dark-primary)); + --color-gray: rgb(var(--immich-dark-gray)); + + color-scheme: dark; +} + +* { box-sizing: border-box; } + +html, body { + margin: 0; + height: 100%; + background: var(--color-bg); + color: var(--color-fg); + font-family: var(--font-sans); +} diff --git a/shared/src/http.ts b/shared/src/http.ts index 149c244..3b7c8f3 100644 --- a/shared/src/http.ts +++ b/shared/src/http.ts @@ -1,6 +1,10 @@ import { NextFunction, Request, Response } from 'express-serve-static-core' +import { resolve } from 'path' import { getConfigOption } from './config/access' +/** Static assets both apps serve from core: pico, the Inter font, the favicon and theme.css. */ +export const CORE_PUBLIC_DIR = resolve(__dirname, '../public') + /** * Apply the response headers configured under `ipp.responseHeaders` to the * given Response. Used by route handlers to attach the default Cache-Control @@ -20,6 +24,18 @@ export function addNoStoreHeaders (res: Response): void { res.set('Expires', '0') } +/** + * A signal that aborts when the visitor's connection closes before the + * response has finished, so the request to Immich stops with it. + */ +export function abortOnClose (res: Response): AbortSignal { + const controller = new AbortController() + const onClose = () => { if (!res.writableFinished) controller.abort() } + res.once('close', onClose) + if (res.closed) onClose() + return controller.signal +} + /** * Wrap an async route handler so a rejected promise is passed to Express's * error chain (and on to `errorHandler`). diff --git a/shared/src/types.ts b/shared/src/types.ts index 77d8b7a..3bf0290 100644 --- a/shared/src/types.ts +++ b/shared/src/types.ts @@ -73,12 +73,17 @@ export interface ImmichVersion { } export interface SharedLink { + // Immich's id for the link itself, not the album + id?: string; key: string; keyType: KeyType; + slug?: string | null; type: string; description?: string; assets: Asset[]; allowDownload?: boolean; + // The owner's "Allow public user to upload" toggle + allowUpload?: boolean; showMetadata?: boolean; password?: string; album?: {