release: v0.15.0 (#585)
Eighteen changes since v0.14.0. See CHANGELOG.md for the full list and the upgrade notes (bump IMAGE_CACHE_VERSION).
This commit is contained in:
@@ -82,6 +82,14 @@ const ROUTES: {
|
||||
method: 'GET',
|
||||
args: () => [new NextRequest('http://localhost/api/admin/doctor')],
|
||||
},
|
||||
{
|
||||
// Lists album titles and raw asset UUIDs.
|
||||
name: 'GET /api/admin/alt-text',
|
||||
path: 'alt-text',
|
||||
load: () => import('../alt-text/route'),
|
||||
method: 'GET',
|
||||
args: () => [],
|
||||
},
|
||||
{
|
||||
name: 'GET /api/admin/assets',
|
||||
path: 'assets',
|
||||
|
||||
83
app/api/admin/alt-text/route.ts
Normal file
83
app/api/admin/alt-text/route.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import { immich } from '@/lib/immich';
|
||||
import {
|
||||
albumPaths,
|
||||
buildAltTextReport,
|
||||
pickImmichWebUrl,
|
||||
type AltTextAlbumInput,
|
||||
} from '@/lib/admin/alt-text';
|
||||
|
||||
/**
|
||||
* Immich's *External domain* setting, or null when unset or unreadable. A
|
||||
* failure here must not cost the report — the links just fall back.
|
||||
*/
|
||||
async function immichExternalDomain(apiUrl: string, apiKey: string, timeoutMs: number) {
|
||||
try {
|
||||
const res = await fetch(`${apiUrl}/server/config`, {
|
||||
headers: { 'x-api-key': apiKey, Accept: 'application/json' },
|
||||
signal: AbortSignal.timeout(timeoutMs),
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const body = (await res.json()) as { externalDomain?: string };
|
||||
return body.externalDomain ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alt-text coverage of every published album, for the diagnostics page.
|
||||
*
|
||||
* Goes through `immich.getAlbum()`, so it shares the album cache with the
|
||||
* public site: a check right after browsing the gallery costs no Immich calls.
|
||||
* An album that fails to load is counted, not fatal — the rest still report.
|
||||
*/
|
||||
export async function GET() {
|
||||
if (!isAdminEnabled()) {
|
||||
return NextResponse.json({ error: 'Admin not enabled' }, { status: 403 });
|
||||
}
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const config = getConfig();
|
||||
if (config.needsCredentials) {
|
||||
return NextResponse.json({ error: 'Not configured' }, { status: 503 });
|
||||
}
|
||||
|
||||
const paths = albumPaths(config.subpages);
|
||||
const inputs: AltTextAlbumInput[] = [];
|
||||
let unreadable = 0;
|
||||
|
||||
const [albums, externalDomain] = await Promise.all([
|
||||
Promise.all(config.albums.map((id) => immich.getAlbum(id).catch(() => undefined))),
|
||||
immichExternalDomain(config.immich.apiUrl, config.immich.apiKey, config.immichTimeoutMs),
|
||||
]);
|
||||
const immichLink = pickImmichWebUrl(externalDomain, config.immich.apiUrl);
|
||||
albums.forEach((album, i) => {
|
||||
if (!album) {
|
||||
// null is "Immich says it does not exist" — the doctor's album-ids check
|
||||
// already reports that. undefined is a failed request.
|
||||
if (album === undefined) unreadable++;
|
||||
return;
|
||||
}
|
||||
inputs.push({
|
||||
id: album.id,
|
||||
name: album.albumName,
|
||||
path: paths.get(config.albums[i]) ?? '/',
|
||||
assets: album.assets,
|
||||
});
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
...buildAltTextReport(inputs, config.exif.caption),
|
||||
unreadable,
|
||||
immichUrl: immichLink.url,
|
||||
immichUrlSource: immichLink.source,
|
||||
},
|
||||
{ headers: { 'Cache-Control': 'no-store' } },
|
||||
);
|
||||
}
|
||||
@@ -2,18 +2,24 @@ import { NextResponse } from 'next/server';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth';
|
||||
import { listBackups, restoreBackup } from '@/lib/admin/yaml-service';
|
||||
import { listJournalBackups, restoreJournalBackup } from '@/lib/admin/journal-service';
|
||||
import { invalidateConfigCache } from '@/lib/config';
|
||||
import { immich } from '@/lib/immich';
|
||||
|
||||
export type BackupTarget = 'gallery' | 'settings' | 'about' | 'journal';
|
||||
|
||||
export interface BackupItem {
|
||||
filename: string;
|
||||
target: 'gallery' | 'settings';
|
||||
target: BackupTarget;
|
||||
timestamp: string | null;
|
||||
isPreRestore: boolean;
|
||||
/** Journal backups only: the entry the backup belongs to. */
|
||||
slug?: string;
|
||||
/** Journal backups only: the snapshot taken when the entry was deleted. */
|
||||
isDeleted?: boolean;
|
||||
}
|
||||
|
||||
function parseBackupInfo(filename: string): BackupItem {
|
||||
const target = filename.startsWith('gallery.yaml') ? 'gallery' : 'settings';
|
||||
function parseBackupInfo(filename: string, target: BackupTarget): BackupItem {
|
||||
const isPreRestore = filename.includes('pre-restore');
|
||||
|
||||
// Extract timestamp from filename like filename.2026-05-31T17-30-00-000Z.bak
|
||||
@@ -37,7 +43,7 @@ function parseBackupInfo(filename: string): BackupItem {
|
||||
};
|
||||
}
|
||||
|
||||
/** GET: List all available backups for gallery and settings. */
|
||||
/** GET: List all available backups, grouped by the file they restore. */
|
||||
export async function GET() {
|
||||
if (!isAdminEnabled()) {
|
||||
return NextResponse.json({ error: 'Admin not enabled' }, { status: 403 });
|
||||
@@ -47,16 +53,26 @@ export async function GET() {
|
||||
}
|
||||
|
||||
try {
|
||||
const galleryRaw = await listBackups('gallery.yaml');
|
||||
const settingsRaw = await listBackups('settings.yaml');
|
||||
|
||||
const gallery = galleryRaw.map(parseBackupInfo);
|
||||
const settings = settingsRaw.map(parseBackupInfo);
|
||||
const gallery = (await listBackups('gallery.yaml')).map((f) => parseBackupInfo(f, 'gallery'));
|
||||
const settings = (await listBackups('settings.yaml')).map((f) =>
|
||||
parseBackupInfo(f, 'settings'),
|
||||
);
|
||||
const about = (await listBackups('about.md')).map((f) => parseBackupInfo(f, 'about'));
|
||||
// Newest first across all entries, so a just-deleted entry sits on top.
|
||||
const journal = (await listJournalBackups())
|
||||
.map((b) => ({
|
||||
...parseBackupInfo(b.filename, 'journal'),
|
||||
slug: b.slug,
|
||||
isDeleted: b.kind === 'deleted',
|
||||
}))
|
||||
.sort((a, b) => (b.timestamp ?? '').localeCompare(a.timestamp ?? ''));
|
||||
|
||||
return NextResponse.json({
|
||||
backups: {
|
||||
gallery,
|
||||
settings,
|
||||
about,
|
||||
journal,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
@@ -76,7 +92,7 @@ export async function POST(req: Request) {
|
||||
|
||||
try {
|
||||
const body = await req.json();
|
||||
const { backupFilename } = body || {};
|
||||
const { backupFilename, target } = body || {};
|
||||
|
||||
if (!backupFilename || typeof backupFilename !== 'string') {
|
||||
return NextResponse.json({ error: 'backupFilename is required' }, { status: 400 });
|
||||
@@ -95,7 +111,13 @@ export async function POST(req: Request) {
|
||||
return NextResponse.json({ error: 'Invalid backup file extension' }, { status: 400 });
|
||||
}
|
||||
|
||||
await restoreBackup(backupFilename);
|
||||
// Journal backups live in their own directory, and `<slug>.md.<ts>.bak`
|
||||
// cannot be told apart from an about.md backup by name alone.
|
||||
if (target === 'journal') {
|
||||
await restoreJournalBackup(backupFilename);
|
||||
} else {
|
||||
await restoreBackup(backupFilename);
|
||||
}
|
||||
|
||||
// Invalidate caches & revalidate pages
|
||||
invalidateConfigCache();
|
||||
|
||||
Reference in New Issue
Block a user