Move static assets to shared location
This commit is contained in:
+3
-2
@@ -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
|
||||
|
||||
+1
-60
@@ -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 {
|
||||
|
||||
+11
-9
@@ -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<typeof express.static>[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')
|
||||
|
||||
|
||||
+5
-11
@@ -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<string, string> = {}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ export function Gallery (props: GalleryProps) {
|
||||
<meta name="twitter:card" content="summary_large_image"/>
|
||||
</>}
|
||||
<link rel="icon" href="/share/static/favicon.ico" type="image/x-icon"/>
|
||||
<link type="text/css" rel="stylesheet" href={`/share/static/${ASSET_VERSION}/theme.css`}/>
|
||||
<link type="text/css" rel="stylesheet" href={`/share/static/${ASSET_VERSION}/style.css`}/>
|
||||
<link type="text/css" rel="stylesheet" href="/share/static/photoswipe/photoswipe.css"/>
|
||||
<link type="text/css" rel="stylesheet" href={`/share/static/${ASSET_VERSION}/photoswipe-overrides.css`}/>
|
||||
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@@ -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);
|
||||
}
|
||||
@@ -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`).
|
||||
|
||||
@@ -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?: {
|
||||
|
||||
Reference in New Issue
Block a user