Extract @ipp/core npm workspace package
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { AssetType } from '../types'
|
||||
import { ThemeScript } from './theme'
|
||||
import { AssetType, jsonForInlineScript, ThemeScript } from '@ipp/core'
|
||||
import { GalleryItem, LightboxConfig, MetadataConfig, GroupByDateMode } from '../shared/types'
|
||||
import { ASSET_VERSION } from '../version'
|
||||
import { jsonForInlineScript } from '../utils/text'
|
||||
|
||||
export type { GalleryItem, LightboxConfig, MetadataConfig, GroupByDateMode }
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
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>
|
||||
)
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
// 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