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
|
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/loader.ts loadConfig() reads env / file; the app passes its default path
|
||||||
config/access.ts getConfigOption() reads the loaded config
|
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
|
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
|
session.ts Cookie session, decodeCookie, unlock handler, invalid-password response
|
||||||
encrypt.ts Cookie-session encryption for password-protected shares
|
encrypt.ts Cookie-session encryption for password-protected shares
|
||||||
utils/ log, sanitize (filenames), text (escaping), ttlLruCache, webStream
|
utils/ log, sanitize (filenames), text (escaping), ttlLruCache, webStream
|
||||||
view/ Page renderer, theme script, password page
|
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
|
tests/ Vitest unit tests for core
|
||||||
app/
|
app/
|
||||||
config.json Runtime configuration, overrideable via volume or inline
|
config.json Runtime configuration, overrideable via volume or inline
|
||||||
@@ -73,7 +74,7 @@ app/
|
|||||||
client/ Client gallery, virtualisation, lightbox, sidebar
|
client/ Client gallery, virtualisation, lightbox, sidebar
|
||||||
public/ Static assets served as-is
|
public/ Static assets served as-is
|
||||||
photoswipe/ Vendored PhotoSwipe v5
|
photoswipe/ Vendored PhotoSwipe v5
|
||||||
thumbhash/, fonts/, images/
|
thumbhash/, images/
|
||||||
style.css, photoswipe-overrides.css
|
style.css, photoswipe-overrides.css
|
||||||
tests/ Vitest unit tests for IPP
|
tests/ Vitest unit tests for IPP
|
||||||
docs/ User docs site (VitePress); docs/README.md explains its structure
|
docs/ User docs site (VitePress); docs/README.md explains its structure
|
||||||
|
|||||||
+1
-60
@@ -1,50 +1,10 @@
|
|||||||
/*
|
/* Theme tokens, the Inter font and the page base come from @ipp/core's theme.css */
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
:root {
|
: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
|
/* Horizontal inset for textual page content (title, description, group
|
||||||
headers). The grid itself goes edge-to-edge on mobile so it doesn't use
|
headers). The grid itself goes edge-to-edge on mobile so it doesn't use
|
||||||
this value. */
|
this value. */
|
||||||
--gutter: 32px;
|
--gutter: 32px;
|
||||||
|
|
||||||
color-scheme: light;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 640px) {
|
@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) ===== */
|
/* ===== Justified-rows / square-grid gallery (tiles are absolute-positioned by JS) ===== */
|
||||||
|
|
||||||
#gallery {
|
#gallery {
|
||||||
|
|||||||
+11
-9
@@ -10,6 +10,7 @@ import {
|
|||||||
Asset,
|
Asset,
|
||||||
AssetType,
|
AssetType,
|
||||||
asyncHandler,
|
asyncHandler,
|
||||||
|
CORE_PUBLIC_DIR,
|
||||||
decodeCookie,
|
decodeCookie,
|
||||||
enforceMinimumImmichVersion,
|
enforceMinimumImmichVersion,
|
||||||
errorHandler,
|
errorHandler,
|
||||||
@@ -65,17 +66,18 @@ app.use(sessionMiddleware({ name: 'session' }))
|
|||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
// For parsing the selective-download form POST (form-encoded body)
|
// For parsing the selective-download form POST (form-encoded body)
|
||||||
app.use(express.urlencoded({ extended: false, limit: '1mb' }))
|
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.
|
// Cache-busted, immutable static assets under a per-release version segment.
|
||||||
const inProduction = process.env.NODE_ENV === 'production'
|
const inProduction = process.env.NODE_ENV === 'production'
|
||||||
app.use('/share/static/' + ASSET_VERSION, express.static('public', {
|
serveStatic('/share/static/' + ASSET_VERSION, { immutable: inProduction, maxAge: inProduction ? '365d' : 0 })
|
||||||
immutable: inProduction,
|
serveStatic('/share/static')
|
||||||
maxAge: inProduction ? '365d' : 0,
|
// The same assets on /, to allow for /robots.txt and /favicon.ico
|
||||||
setHeaders: addResponseHeaders
|
serveStatic('/')
|
||||||
}))
|
|
||||||
// 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 }))
|
|
||||||
// Remove the X-Powered-By ExpressJS header
|
// Remove the X-Powered-By ExpressJS header
|
||||||
app.disable('x-powered-by')
|
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 {
|
import {
|
||||||
assetFetchUrl,
|
assetFetchUrl,
|
||||||
authHeadersForAsset,
|
authHeadersForAsset,
|
||||||
@@ -20,14 +20,8 @@ import { pipeline } from 'stream/promises'
|
|||||||
* to serve them, and the upstream failure surfaces as a client 404.
|
* 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) {
|
export async function assetBuffer (req: IncomingShareRequest, res: Response, asset: Asset, size?: ImageSize | string, share?: SharedLink, forceVideoPlayback = false) {
|
||||||
/*
|
// A cancelled download must not leave Immich streaming #288
|
||||||
Abort the upstream fetch as soon as the visitor goes away, so a cancelled
|
const upstream = abortOnClose(res)
|
||||||
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()
|
|
||||||
|
|
||||||
const headerList = ['content-type', 'content-length', 'last-modified', 'etag']
|
const headerList = ['content-type', 'content-length', 'last-modified', 'etag']
|
||||||
const fetchHeaders: Record<string, string> = {}
|
const fetchHeaders: Record<string, string> = {}
|
||||||
@@ -78,9 +72,9 @@ export async function assetBuffer (req: IncomingShareRequest, res: Response, ass
|
|||||||
const reqHeaders = await authHeadersForAsset(asset)
|
const reqHeaders = await authHeadersForAsset(asset)
|
||||||
let data: globalThis.Response
|
let data: globalThis.Response
|
||||||
try {
|
try {
|
||||||
data = await fetch(url, { headers: { ...fetchHeaders, ...reqHeaders }, signal: upstream.signal })
|
data = await fetch(url, { headers: { ...fetchHeaders, ...reqHeaders }, signal: upstream })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (upstream.signal.aborted) return // visitor left before Immich answered
|
if (upstream.aborted) return // visitor left before Immich answered
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ export function Gallery (props: GalleryProps) {
|
|||||||
<meta name="twitter:card" content="summary_large_image"/>
|
<meta name="twitter:card" content="summary_large_image"/>
|
||||||
</>}
|
</>}
|
||||||
<link rel="icon" href="/share/static/favicon.ico" type="image/x-icon"/>
|
<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/${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/photoswipe/photoswipe.css"/>
|
||||||
<link type="text/css" rel="stylesheet" href={`/share/static/${ASSET_VERSION}/photoswipe-overrides.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 { NextFunction, Request, Response } from 'express-serve-static-core'
|
||||||
|
import { resolve } from 'path'
|
||||||
import { getConfigOption } from './config/access'
|
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
|
* Apply the response headers configured under `ipp.responseHeaders` to the
|
||||||
* given Response. Used by route handlers to attach the default Cache-Control
|
* 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')
|
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
|
* Wrap an async route handler so a rejected promise is passed to Express's
|
||||||
* error chain (and on to `errorHandler`).
|
* error chain (and on to `errorHandler`).
|
||||||
|
|||||||
@@ -73,12 +73,17 @@ export interface ImmichVersion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SharedLink {
|
export interface SharedLink {
|
||||||
|
// Immich's id for the link itself, not the album
|
||||||
|
id?: string;
|
||||||
key: string;
|
key: string;
|
||||||
keyType: KeyType;
|
keyType: KeyType;
|
||||||
|
slug?: string | null;
|
||||||
type: string;
|
type: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
assets: Asset[];
|
assets: Asset[];
|
||||||
allowDownload?: boolean;
|
allowDownload?: boolean;
|
||||||
|
// The owner's "Allow public user to upload" toggle
|
||||||
|
allowUpload?: boolean;
|
||||||
showMetadata?: boolean;
|
showMetadata?: boolean;
|
||||||
password?: string;
|
password?: string;
|
||||||
album?: {
|
album?: {
|
||||||
|
|||||||
Reference in New Issue
Block a user