Refactor to TypeScript ES modules and add metadata sidebar
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
import { AssetType } from '../types'
|
||||
import { ThemeScript } from './theme'
|
||||
import { GalleryItem, LightboxConfig, MetadataConfig } from '../shared/types'
|
||||
|
||||
export type { GalleryItem, LightboxConfig, MetadataConfig }
|
||||
|
||||
export interface GalleryProps {
|
||||
items: GalleryItem[]
|
||||
title: string
|
||||
description: string
|
||||
publicBaseUrl: string
|
||||
path: string
|
||||
showDownload: boolean
|
||||
showTitle: boolean
|
||||
openItem?: number
|
||||
ogImageItem?: GalleryItem
|
||||
lightboxConfig: LightboxConfig
|
||||
metadataConfig: MetadataConfig
|
||||
groupByDate: boolean
|
||||
}
|
||||
|
||||
export function Gallery (props: GalleryProps) {
|
||||
const initJson = JSON.stringify({
|
||||
items: props.items,
|
||||
openItem: props.openItem,
|
||||
lightboxConfig: props.lightboxConfig,
|
||||
metadataConfig: props.metadataConfig,
|
||||
groupByDate: props.groupByDate
|
||||
})
|
||||
const firstItem = props.items[0]
|
||||
// og:image prefers the album cover (passed via props); for videos, previewUrl
|
||||
// points to the .mp4, so use thumbnailUrl to keep og:image a still JPEG.
|
||||
const ogItem = props.ogImageItem || firstItem
|
||||
const ogImageAsset = ogItem
|
||||
? (ogItem.type === AssetType.video ? ogItem.thumbnailUrl : ogItem.previewUrl)
|
||||
: ''
|
||||
const ogImageUrl = ogItem ? props.publicBaseUrl + ogImageAsset : ''
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<ThemeScript/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>{props.title}</title>
|
||||
<meta property="og:title" content={props.title}/>
|
||||
<meta name="twitter:title" content={props.title}/>
|
||||
{props.description && <>
|
||||
<meta name="description" content={props.description}/>
|
||||
<meta property="og:description" content={props.description}/>
|
||||
<meta property="twitter:description" content={props.description}/>
|
||||
</>}
|
||||
{firstItem && <>
|
||||
<meta property="og:image" content={ogImageUrl}/>
|
||||
<meta name="twitter:image" content={ogImageUrl}/>
|
||||
<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/style.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="/share/static/photoswipe/photoswipe.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="/share/static/photoswipe-overrides.css"/>
|
||||
</head>
|
||||
<body>
|
||||
{(props.showTitle || props.showDownload) && (
|
||||
<header id="header">
|
||||
{props.showTitle && (
|
||||
<div class="header-text">
|
||||
<h1>{props.title || 'Gallery'}</h1>
|
||||
<p class="subtitle">
|
||||
{props.items.length}{' '}
|
||||
{props.items.length === 1 ? 'item' : 'items'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{props.showDownload && (
|
||||
<a id="download-all" href={props.path + '/download'} title="Download all" aria-label="Download all">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path fill="currentColor" d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"/>
|
||||
</svg>
|
||||
</a>
|
||||
)}
|
||||
</header>
|
||||
)}
|
||||
{props.description && (
|
||||
<p id="album-description">{props.description}</p>
|
||||
)}
|
||||
{/* Container is intentionally empty - web.js's virtualization manager
|
||||
populates it with only the tiles within the viewport buffer. */}
|
||||
<div id="gallery"></div>
|
||||
{props.showDownload && (
|
||||
<div id="select-toolbar" hidden>
|
||||
<button id="select-cancel" class="toolbar-btn" type="button" aria-label="Exit selection mode">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path fill="currentColor" d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"/>
|
||||
</svg>
|
||||
</button>
|
||||
<span id="select-count">0 selected</span>
|
||||
<button id="select-all" class="toolbar-btn-text" type="button">Select all</button>
|
||||
<button id="select-download" class="toolbar-btn" type="button" aria-label="Download selected">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path fill="currentColor" d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{/* Init params for web.js (read at module load). Using a JSON script
|
||||
block avoids the cross-script-type coordination problems that come
|
||||
with mixing classic and module scripts. */}
|
||||
<script
|
||||
type="application/json"
|
||||
id="ipp-init"
|
||||
dangerouslySetInnerHTML={{ __html: initJson }}
|
||||
/>
|
||||
<script type="module" src="/share/static/js/client/init.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
export function Home () {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
|
||||
<title></title>
|
||||
<link rel="icon" href="/share/static/favicon.ico" type="image/x-icon"/>
|
||||
<style dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
html, body {
|
||||
margin: 0;
|
||||
height: 100vh;
|
||||
background: #262626;
|
||||
}
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
img {
|
||||
max-width: 280px;
|
||||
height: 280px;
|
||||
opacity: 0.3;
|
||||
}
|
||||
`
|
||||
}}/>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<a href="https://github.com/alangrainger/immich-public-proxy">
|
||||
<img src="/share/static/images/ipp.svg" alt=""/>
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
interface PasswordProps {
|
||||
shareKey: string
|
||||
notifyInvalidPassword: boolean
|
||||
}
|
||||
|
||||
const submitScript = `
|
||||
async function submitForm (formElement) {
|
||||
const formData = new FormData(formElement)
|
||||
try {
|
||||
const res = await fetch('/share/unlock', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(Object.fromEntries(formData.entries()))
|
||||
})
|
||||
if (res.status === 200) {
|
||||
window.location.reload()
|
||||
}
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
document.getElementById('unlock')
|
||||
.addEventListener('submit', function (e) {
|
||||
e.preventDefault()
|
||||
submitForm(this)
|
||||
})
|
||||
`
|
||||
|
||||
export function Password ({ shareKey, notifyInvalidPassword }: PasswordProps) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
|
||||
<title>Password required</title>
|
||||
<link rel="icon" href="/share/static/favicon.ico" type="image/x-icon"/>
|
||||
<link type="text/css" rel="stylesheet" href="/share/static/pico.min.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<header></header>
|
||||
<main class="container">
|
||||
<div class="grid">
|
||||
<div></div>
|
||||
<div>
|
||||
<form id="unlock" method="post">
|
||||
<input
|
||||
type="password"
|
||||
name="password"
|
||||
placeholder="Password"
|
||||
aria-label="Password"
|
||||
required
|
||||
autoFocus
|
||||
/>
|
||||
{notifyInvalidPassword && <small>Invalid password</small>}
|
||||
<input type="hidden" name="key" value={shareKey}/>
|
||||
<button type="submit">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
||||
class="lucide lucide-lock-open">
|
||||
<rect width="18" height="11" x="3" y="11" rx="2" ry="2"/>
|
||||
<path d="M7 11V7a5 5 0 0 1 9.9-1"/>
|
||||
</svg>
|
||||
Unlock
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div></div>
|
||||
</div>
|
||||
</main>
|
||||
<script dangerouslySetInnerHTML={{ __html: submitScript }}/>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { renderToString } from 'preact-render-to-string'
|
||||
import { VNode } from 'preact'
|
||||
|
||||
/**
|
||||
* Render a JSX component to a complete HTML response string.
|
||||
* Prepends the doctype so the result is a valid HTML5 document.
|
||||
*/
|
||||
export function renderPage (component: VNode): string {
|
||||
return '<!DOCTYPE html>' + renderToString(component)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Mirrors Immich's FOUC-prevention pattern: read color-theme from localStorage
|
||||
// (or fall back to OS preference), then add/remove .dark on <html> before paint.
|
||||
// Source: immich-app/immich v2.7.5 web/src/app.html (2026-05-23).
|
||||
const themeScript = `
|
||||
const key = 'color-theme';
|
||||
let theme = localStorage.getItem(key);
|
||||
if (!theme) {
|
||||
theme = { value: 'light', system: true };
|
||||
} else if (theme === 'dark' || theme === 'light') {
|
||||
theme = { value: theme, system: false };
|
||||
localStorage.setItem(key, JSON.stringify(theme));
|
||||
} else {
|
||||
theme = JSON.parse(theme);
|
||||
}
|
||||
let v = theme.value;
|
||||
if (theme.system) {
|
||||
v = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
}
|
||||
if (v === 'dark') document.documentElement.classList.add('dark');
|
||||
else document.documentElement.classList.remove('dark');
|
||||
`
|
||||
|
||||
export function ThemeScript () {
|
||||
return <script dangerouslySetInnerHTML={{ __html: themeScript }}/>
|
||||
}
|
||||
Reference in New Issue
Block a user