2.0.0 - full gallery redesign to match Immich
This commit is contained in:
+54
-2
@@ -2,7 +2,7 @@ import dayjs from 'dayjs'
|
||||
import { Response } from 'express-serve-static-core'
|
||||
import { DownloadAll, SharedLink } from './types'
|
||||
|
||||
let config = {}
|
||||
let config: { [key: string]: unknown } = {}
|
||||
try {
|
||||
if (process.env.CONFIG) {
|
||||
// Attempt to parse docker-compose config string into JSON (if specified)
|
||||
@@ -15,6 +15,58 @@ try {
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
// Backward-compat shim: users with a legacy `lightGallery.*` config section
|
||||
// get the few keys most of them had set mapped onto the current
|
||||
// `ipp.lightbox.*` schema, with a single startup notice.
|
||||
if (config.lightGallery && typeof config.lightGallery === 'object') {
|
||||
const lg = config.lightGallery as Record<string, unknown>
|
||||
const mobile = (lg.mobileSettings || {}) as Record<string, unknown>
|
||||
const ipp = (config.ipp || (config.ipp = {})) as Record<string, unknown>
|
||||
const lightbox = (ipp.lightbox || (ipp.lightbox = {})) as Record<string, unknown>
|
||||
// Only fill in fields the user hasn't already set on ipp.lightbox.
|
||||
if (lightbox.showArrows === undefined && lg.controls !== undefined) {
|
||||
lightbox.showArrows = !!lg.controls
|
||||
}
|
||||
if (lightbox.showDownload === undefined && lg.download !== undefined) {
|
||||
lightbox.showDownload = !!lg.download
|
||||
}
|
||||
if (lightbox.mobileArrows === undefined && mobile.controls !== undefined) {
|
||||
lightbox.mobileArrows = !!mobile.controls
|
||||
}
|
||||
console.log(
|
||||
'[IPP] The `lightGallery` config section is deprecated; relevant keys ' +
|
||||
'have been mapped to `ipp.lightbox.*`. See README for the current options.'
|
||||
)
|
||||
}
|
||||
|
||||
// Backward-compat shim: gallery-related keys that used to live directly on
|
||||
// `ipp` now live under `ipp.gallery`. Map legacy keys forward, only filling
|
||||
// in fields the user hasn't already set on the new path.
|
||||
{
|
||||
const ipp = (config.ipp || (config.ipp = {})) as Record<string, unknown>
|
||||
const galleryKeyMigrations: Array<[string, string]> = [
|
||||
['singleImageGallery', 'singleImage'],
|
||||
['singleItemAutoOpen', 'singleItemAutoOpen'],
|
||||
['showGalleryTitle', 'showTitle'],
|
||||
['showGalleryDescription', 'showDescription'],
|
||||
['groupGalleryByDate', 'groupByDate']
|
||||
]
|
||||
const legacyPresent = galleryKeyMigrations.some(([oldKey]) => ipp[oldKey] !== undefined)
|
||||
if (legacyPresent) {
|
||||
const gallery = (ipp.gallery || (ipp.gallery = {})) as Record<string, unknown>
|
||||
for (const [oldKey, newKey] of galleryKeyMigrations) {
|
||||
if (ipp[oldKey] !== undefined && gallery[newKey] === undefined) {
|
||||
gallery[newKey] = ipp[oldKey]
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
'[IPP] Top-level gallery keys (singleImageGallery, singleItemAutoOpen, ' +
|
||||
'showGalleryTitle, showGalleryDescription, groupGalleryByDate) are ' +
|
||||
'deprecated; please move them under `ipp.gallery.*`. See README.'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a configuration option fron config.json using dotted notation.
|
||||
*
|
||||
@@ -22,7 +74,7 @@ try {
|
||||
* @param [defaultOption] - Specify a default option to return if no configuation value is found
|
||||
*
|
||||
* @example
|
||||
* getConfigOption('ipp.singleImageGallery')
|
||||
* getConfigOption('ipp.gallery.singleImage')
|
||||
*/
|
||||
export const getConfigOption = (path: string, defaultOption?: unknown) => {
|
||||
const value = path.split('.').reduce((obj: { [key: string]: unknown }, key) => (obj || {})[key], config)
|
||||
|
||||
+10
-8
@@ -13,6 +13,9 @@ import dayjs from 'dayjs'
|
||||
import { addResponseHeaders, canDownload, getConfigOption, log } from './functions'
|
||||
import render from './render'
|
||||
import { Response } from 'express-serve-static-core'
|
||||
import { h } from 'preact'
|
||||
import { renderPage } from './views/_render'
|
||||
import { Password } from './views/password'
|
||||
import { respondToInvalidRequest } from './invalidRequestHandler'
|
||||
import { encrypt } from './encrypt'
|
||||
|
||||
@@ -90,12 +93,11 @@ class Immich {
|
||||
// Password required - show the visitor the password page
|
||||
if (sharedLinkRes.passwordRequired) {
|
||||
// `request.key` is already sanitised at this point, but it never hurts to be explicit
|
||||
const key = request.key.replace(/[^\w-]/g, '')
|
||||
res.render('password', {
|
||||
key,
|
||||
lgConfig: render.lgConfig,
|
||||
const shareKey = request.key.replace(/[^\w-]/g, '')
|
||||
res.send(renderPage(h(Password, {
|
||||
shareKey,
|
||||
notifyInvalidPassword: !!request.password
|
||||
})
|
||||
})))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -122,13 +124,13 @@ class Immich {
|
||||
// This is an individual item (not a gallery)
|
||||
log('Serving link ' + request.key)
|
||||
const asset = link.assets[0]
|
||||
if (asset.type === AssetType.image && !getConfigOption('ipp.singleImageGallery') && !request.password) {
|
||||
if (asset.type === AssetType.image && !getConfigOption('ipp.gallery.singleImage') && !request.password) {
|
||||
// For photos, output the image directly unless configured to show a gallery,
|
||||
// or unless it's a password-protected link
|
||||
await render.assetBuffer(request, res, link.assets[0], ImageSize.preview)
|
||||
} else {
|
||||
// Show a gallery page
|
||||
const openItem = getConfigOption('ipp.singleItemAutoOpen', true) ? 1 : 0
|
||||
const openItem = getConfigOption('ipp.gallery.singleItemAutoOpen', true) ? 1 : 0
|
||||
await render.gallery(res, link, openItem)
|
||||
}
|
||||
} else {
|
||||
@@ -235,7 +237,7 @@ class Immich {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content-type of a video, for passing back to lightGallery
|
||||
* Get the content-type of a video, for the lightbox <video> element
|
||||
*/
|
||||
async getVideoContentType (asset: Asset) {
|
||||
const data = await this.request(this.buildUrl('/assets/' + encodeURIComponent(asset.id) + '/video/playback', {
|
||||
|
||||
+53
-6
@@ -8,9 +8,12 @@ import render from './render'
|
||||
import dayjs from 'dayjs'
|
||||
import { NextFunction, Request, Response } from 'express-serve-static-core'
|
||||
import { Asset, AssetType, ImageSize, KeyType } from './types'
|
||||
import { addResponseHeaders, getConfigOption, toString } from './functions'
|
||||
import { addResponseHeaders, canDownload, getConfigOption, toString } from './functions'
|
||||
import { decrypt, encrypt } from './encrypt'
|
||||
import { respondToInvalidRequest } from './invalidRequestHandler'
|
||||
import { h } from 'preact'
|
||||
import { renderPage } from './views/_render'
|
||||
import { Home } from './views/home'
|
||||
|
||||
// Extend the Request type with a `password` property
|
||||
declare module 'express-serve-static-core' {
|
||||
@@ -28,10 +31,10 @@ app.use(cookieSession({
|
||||
sameSite: 'strict',
|
||||
secret: crypto.randomBytes(32).toString('base64url')
|
||||
}))
|
||||
// Add the EJS view engine, to render the gallery page
|
||||
app.set('view engine', 'ejs')
|
||||
// For parsing the password unlock form
|
||||
// For parsing the password unlock form and POSTed JSON payloads
|
||||
app.use(express.json())
|
||||
// For parsing the selective-download form POST (form-encoded body)
|
||||
app.use(express.urlencoded({ extended: false, limit: '1mb' }))
|
||||
// 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
|
||||
@@ -111,7 +114,51 @@ app.post('/share/unlock', async (req, res) => {
|
||||
})
|
||||
|
||||
/*
|
||||
* [ROUTE] Catch accidental POST requests to share URLs (e.g. from browser history
|
||||
* [ROUTE] Selective download - POST a list of asset IDs, get a zip of just those.
|
||||
* The list arrives as a single "assets" form field containing a JSON array.
|
||||
* Validates each ID against share.assets so the request can't pull anything
|
||||
* outside the share.
|
||||
*/
|
||||
app.post('/:shareType(share|s)/:key/download', decodeCookie, async (req, res) => {
|
||||
const keyType = immich.getKeyTypeFromShare(req.params.shareType)
|
||||
let requestedIds: unknown
|
||||
try {
|
||||
requestedIds = JSON.parse(String(req.body?.assets ?? '[]'))
|
||||
} catch (e) {
|
||||
respondToInvalidRequest(res, 400, 'Malformed assets list')
|
||||
return
|
||||
}
|
||||
if (!Array.isArray(requestedIds) || requestedIds.length === 0) {
|
||||
respondToInvalidRequest(res, 400, 'No assets selected')
|
||||
return
|
||||
}
|
||||
|
||||
const result = await immich.getShareByKey(req.params.key, req.password, keyType)
|
||||
if (!result?.valid || !result.link) {
|
||||
respondToInvalidRequest(res, 404, 'Invalid share link')
|
||||
return
|
||||
}
|
||||
if (result.passwordRequired) {
|
||||
respondToInvalidRequest(res, 401, 'Password required')
|
||||
return
|
||||
}
|
||||
if (!canDownload(result.link)) {
|
||||
respondToInvalidRequest(res, 403, 'Downloads disabled for this share')
|
||||
return
|
||||
}
|
||||
|
||||
const requested = new Set(requestedIds.map(String))
|
||||
const validAssets = result.link.assets.filter(a => requested.has(a.id))
|
||||
if (validAssets.length === 0) {
|
||||
respondToInvalidRequest(res, 400, 'No valid assets in selection')
|
||||
return
|
||||
}
|
||||
|
||||
await render.downloadAssets(res, result.link, validAssets)
|
||||
})
|
||||
|
||||
/*
|
||||
* [ROUTE] Catch accidental POST requests to share URLs (e.g. from browser history
|
||||
* state issues) and force a clean GET redirect.
|
||||
* See https://github.com/alangrainger/immich-public-proxy/pull/205
|
||||
*/
|
||||
@@ -185,7 +232,7 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r
|
||||
if (getConfigOption('ipp.showHomePage', true)) {
|
||||
app.get(/^\/(|share)\/*$/, (_req, res) => {
|
||||
addResponseHeaders(res)
|
||||
res.render('home')
|
||||
res.send(renderPage(h(Home, {})))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+65
-38
@@ -1,18 +1,15 @@
|
||||
import immich from './immich'
|
||||
import { Response } from 'express-serve-static-core'
|
||||
import { Asset, AssetType, ImageSize, IncomingShareRequest, SharedLink } from './types'
|
||||
import { canDownload, escapeHtml, getConfigOption } from './functions'
|
||||
import { canDownload, escapeHtml, getConfigOption, toString } from './functions'
|
||||
import archiver from 'archiver'
|
||||
import { respondToInvalidRequest } from './invalidRequestHandler'
|
||||
import { sanitize } from './includes/sanitize'
|
||||
import { h } from 'preact'
|
||||
import { renderPage } from './views/_render'
|
||||
import { Gallery, GalleryItem, GalleryProps } from './views/gallery'
|
||||
|
||||
class Render {
|
||||
lgConfig
|
||||
|
||||
constructor () {
|
||||
this.lgConfig = getConfigOption('lightGallery', {})
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream data from Immich back to the client
|
||||
*/
|
||||
@@ -98,23 +95,30 @@ class Render {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a gallery page for a given SharedLink, using EJS and lightGallery.
|
||||
* Render a gallery page for a given SharedLink.
|
||||
*
|
||||
* @param res - ExpressJS Response
|
||||
* @param share - Immich `shared-link` containing the assets to show in the gallery
|
||||
* @param [openItem] - Immediately open a lightbox to the Nth item when the gallery loads
|
||||
* @param [openItem] - Immediately open the lightbox to the Nth item when the gallery loads
|
||||
*/
|
||||
async gallery (res: Response, share: SharedLink, openItem?: number) {
|
||||
// publicBaseUrl is used for the og:image, which requires a fully qualified URL.
|
||||
// You can specify this in your docker-compose file, or send it dynamically as a `publicBaseUrl` header
|
||||
const publicBaseUrl = process.env.PUBLIC_BASE_URL || res.req.headers.publicBaseUrl || (res.req.protocol + '://' + res.req.headers.host)
|
||||
|
||||
// Use .map to generate an array of promises, then await them all to load in parallel.
|
||||
const items = await Promise.all(share.assets.map(async (asset) => {
|
||||
let video, downloadUrl
|
||||
// Date grouping needs chronological order; sort newest-first when enabled
|
||||
// (overrides any album.order the upstream applied).
|
||||
const groupByDate = !!getConfigOption('ipp.gallery.groupByDate', false)
|
||||
if (groupByDate) {
|
||||
share.assets.sort((a, b) => (b.fileCreatedAt || '').localeCompare(a.fileCreatedAt || ''))
|
||||
}
|
||||
|
||||
// Build structured items in parallel
|
||||
const items: GalleryItem[] = await Promise.all(share.assets.map(async (asset): Promise<GalleryItem> => {
|
||||
let videoData: string | undefined
|
||||
let downloadUrl: string | undefined
|
||||
if (asset.type === AssetType.video) {
|
||||
// Populate the data-video property
|
||||
video = JSON.stringify({
|
||||
videoData = JSON.stringify({
|
||||
source: [
|
||||
{
|
||||
src: immich.videoUrl(share.key, asset.id),
|
||||
@@ -129,42 +133,58 @@ class Render {
|
||||
downloadUrl = immich.videoUrl(share.key, asset.id)
|
||||
}
|
||||
if (getConfigOption('ipp.downloadOriginalPhoto', true)) {
|
||||
// Add a download link for the original-size image, if configured in config.json
|
||||
downloadUrl = immich.photoUrl(share.key, asset.id, ImageSize.original)
|
||||
}
|
||||
|
||||
const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail)
|
||||
const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset))
|
||||
const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string' ? escapeHtml(asset.exifInfo.description) : ''
|
||||
const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string'
|
||||
? escapeHtml(asset.exifInfo.description)
|
||||
: ''
|
||||
|
||||
// Create the full HTML element source to pass to the gallery view
|
||||
const itemHtml = [
|
||||
video ? `<a data-video='${video}'` : `<a href="${previewUrl}"`,
|
||||
downloadUrl ? ` data-download-url="${downloadUrl}"` : '',
|
||||
description ? ` data-sub-html='<p>${description}</p>'` : '',
|
||||
` data-download="${this.getFilename(asset)}" data-slide-name="${asset.id}"><img alt="${description}" loading="lazy" src="${thumbnailUrl}" onerror="this.closest('a').classList.add('thumb-error')"/>`,
|
||||
video ? '<div class="play-icon"></div>' : '',
|
||||
'</a>'
|
||||
].join('')
|
||||
let width = asset.exifInfo?.exifImageWidth
|
||||
let height = asset.exifInfo?.exifImageHeight
|
||||
const orientation = asset.exifInfo?.orientation
|
||||
if (orientation && ['5', '6', '7', '8'].includes(orientation) && width && height) {
|
||||
[width, height] = [height, width]
|
||||
}
|
||||
|
||||
return {
|
||||
html: itemHtml,
|
||||
id: asset.id,
|
||||
type: asset.type,
|
||||
previewUrl,
|
||||
thumbnailUrl,
|
||||
previewUrl
|
||||
downloadUrl,
|
||||
videoData,
|
||||
description: description || undefined,
|
||||
downloadFilename: this.getFilename(asset),
|
||||
width,
|
||||
height,
|
||||
thumbhash: asset.thumbhash,
|
||||
fileCreatedAt: asset.fileCreatedAt
|
||||
}
|
||||
}))
|
||||
|
||||
res.render('gallery', {
|
||||
const downloadAllowed = canDownload(share)
|
||||
const props: GalleryProps = {
|
||||
items,
|
||||
openItem,
|
||||
title: this.title(share),
|
||||
description: getConfigOption('ipp.showGalleryDescription', false) ? this.description(share) : '',
|
||||
publicBaseUrl,
|
||||
description: getConfigOption('ipp.gallery.showDescription', false) ? this.description(share) : '',
|
||||
publicBaseUrl: toString(publicBaseUrl),
|
||||
path: '/share/' + share.key,
|
||||
showDownload: canDownload(share),
|
||||
showTitle: getConfigOption('ipp.showGalleryTitle', false),
|
||||
lgConfig: getConfigOption('lightGallery', {})
|
||||
})
|
||||
showDownload: downloadAllowed,
|
||||
showTitle: !!getConfigOption('ipp.gallery.showTitle', false),
|
||||
openItem,
|
||||
lightboxConfig: {
|
||||
// Show download button only if downloading is allowed AND configured.
|
||||
showDownload: downloadAllowed && !!getConfigOption('ipp.lightbox.showDownload', true),
|
||||
showArrows: !!getConfigOption('ipp.lightbox.showArrows', true),
|
||||
mobileArrows: !!getConfigOption('ipp.lightbox.mobileArrows', false)
|
||||
},
|
||||
groupByDate
|
||||
}
|
||||
|
||||
res.send(renderPage(h(Gallery, props)))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,9 +202,17 @@ class Render {
|
||||
}
|
||||
|
||||
/**
|
||||
* Download all assets as a zip file
|
||||
* Download all assets in a share as a zip file
|
||||
*/
|
||||
async downloadAll (res: Response, share: SharedLink) {
|
||||
await this.downloadAssets(res, share, share.assets)
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream the given assets back as a zip file. Caller is responsible for
|
||||
* checking that every asset belongs to the share (security boundary).
|
||||
*/
|
||||
async downloadAssets (res: Response, share: SharedLink, assets: Asset[]) {
|
||||
const downloadOriginalAsset = getConfigOption('ipp.downloadOriginalPhoto', true)
|
||||
res.setHeader('Content-Type', 'application/zip')
|
||||
let filename = (sanitize(this.title(share)) || 'photos') + '.zip'
|
||||
@@ -192,7 +220,7 @@ class Render {
|
||||
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${filename}`)
|
||||
const archive = archiver('zip', { zlib: { level: 6 } })
|
||||
archive.pipe(res)
|
||||
await Promise.all(share.assets.map(async (asset) => {
|
||||
await Promise.all(assets.map(async (asset) => {
|
||||
const endpoint = downloadOriginalAsset ? 'original' : 'thumbnail'
|
||||
const url = immich.buildUrl(immich.apiUrl() + '/assets/' + encodeURIComponent(asset.id) + '/' + endpoint, {
|
||||
key: asset.key,
|
||||
@@ -200,7 +228,6 @@ class Render {
|
||||
size: downloadOriginalAsset ? '' : 'preview'
|
||||
})
|
||||
const data = await fetch(url)
|
||||
// Check the response for validity
|
||||
if (!data.ok) {
|
||||
console.warn(`Failed to fetch asset: ${asset.id}`)
|
||||
return
|
||||
|
||||
@@ -12,6 +12,11 @@ export enum KeyType {
|
||||
|
||||
export interface ExifInfo {
|
||||
description?: string;
|
||||
exifImageWidth?: number;
|
||||
exifImageHeight?: number;
|
||||
// EXIF orientation string ("1".."8") or null. Values 5-8 indicate the image
|
||||
// is rotated 90°/270°, so the displayed aspect ratio swaps width/height.
|
||||
orientation?: string | null;
|
||||
}
|
||||
|
||||
export enum AlbumType {
|
||||
@@ -30,6 +35,8 @@ export interface Asset {
|
||||
type: AssetType;
|
||||
isTrashed: boolean;
|
||||
exifInfo?: ExifInfo;
|
||||
// Base64-encoded thumbhash for tasteful blur placeholders during lazy-load
|
||||
thumbhash?: string;
|
||||
}
|
||||
|
||||
export interface Album {
|
||||
|
||||
@@ -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 }}/>
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import { AssetType } from '../types'
|
||||
import { ThemeScript } from './_theme'
|
||||
|
||||
export interface GalleryItem {
|
||||
id: string
|
||||
type: AssetType
|
||||
previewUrl: string
|
||||
thumbnailUrl: string
|
||||
downloadUrl?: string
|
||||
// pre-stringified JSON describing the video source (used to build a <video>
|
||||
// element for video slides in the PhotoSwipe lightbox)
|
||||
videoData?: string
|
||||
// already-escaped HTML fragment used as a caption in the lightbox
|
||||
description?: string
|
||||
downloadFilename: string
|
||||
// Display dimensions after EXIF orientation correction; needed for the
|
||||
// pre-computed justified-rows layout that virtualization depends on.
|
||||
width?: number
|
||||
height?: number
|
||||
// Base64-encoded thumbhash for an optional blur placeholder behind each tile
|
||||
thumbhash?: string
|
||||
// ISO date string from Immich; used to group tiles by month when enabled.
|
||||
fileCreatedAt?: string
|
||||
}
|
||||
|
||||
export interface LightboxConfig {
|
||||
showArrows: boolean
|
||||
showDownload: boolean
|
||||
mobileArrows: boolean
|
||||
}
|
||||
|
||||
export interface GalleryProps {
|
||||
items: GalleryItem[]
|
||||
title: string
|
||||
description: string
|
||||
publicBaseUrl: string
|
||||
path: string
|
||||
showDownload: boolean
|
||||
showTitle: boolean
|
||||
openItem?: number
|
||||
lightboxConfig: LightboxConfig
|
||||
groupByDate: boolean
|
||||
}
|
||||
|
||||
export function Gallery (props: GalleryProps) {
|
||||
const initJson = JSON.stringify({
|
||||
items: props.items,
|
||||
openItem: props.openItem,
|
||||
lightboxConfig: props.lightboxConfig,
|
||||
groupByDate: props.groupByDate
|
||||
})
|
||||
const firstItem = props.items[0]
|
||||
const ogImageUrl = firstItem ? props.publicBaseUrl + firstItem.previewUrl : ''
|
||||
|
||||
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/web.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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user