fix: before/after works for compose (source fallback), hidden for text-only; add reuse result as new Studio input
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNQ8ghPfzAfsyVYd6HgFb6
This commit is contained in:
@@ -11,9 +11,10 @@ export const GET: APIRoute = async ({ params, url, locals }) => {
|
||||
const wantThumb = q.get('thumb') === '1';
|
||||
const wantSrc = q.get('src') === '1';
|
||||
const item = await one<any>(
|
||||
`SELECT source_path, result_path, thumb_path, filename, has_alpha FROM items WHERE id=$1`, [params.id]);
|
||||
// Vorschau: Thumbnail bevorzugen, sonst Ergebnis. Quelle nur explizit.
|
||||
const path = wantSrc ? item?.source_path
|
||||
`SELECT source_path, source_paths, result_path, thumb_path, filename, has_alpha FROM items WHERE id=$1`, [params.id]);
|
||||
// Quelle: Einzelquelle, sonst erste Kombinier-Quelle (für Vorher/Nachher).
|
||||
const firstSource = item?.source_path || (Array.isArray(item?.source_paths) ? item.source_paths[0] : null);
|
||||
const path = wantSrc ? firstSource
|
||||
: wantThumb ? (item?.thumb_path || item?.result_path)
|
||||
: item?.result_path;
|
||||
if (!path) return new Response('Nicht gefunden', { status: 404 });
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { one } from '../../../../lib/db';
|
||||
import { getObject, putObject, sourceKey } from '../../../../lib/storage';
|
||||
|
||||
export const prerender = false;
|
||||
const json = (b: unknown, s = 200) =>
|
||||
new Response(JSON.stringify(b), { status: s, headers: { 'Content-Type': 'application/json' } });
|
||||
|
||||
/** Kopiert das Ergebnis eines Items in eine neue Quelle, damit es im Studio
|
||||
* als Vorlage weiterbearbeitet werden kann. */
|
||||
export const POST: APIRoute = async ({ params, locals }) => {
|
||||
if (!locals.user) return new Response('Unauthorized', { status: 401 });
|
||||
const it = await one<{ result_path: string | null; filename: string | null }>(
|
||||
'SELECT result_path, filename FROM items WHERE id=$1', [params.id]);
|
||||
if (!it?.result_path) return json({ error: 'Kein Ergebnis vorhanden.' }, 404);
|
||||
try {
|
||||
const buf = await getObject(it.result_path);
|
||||
const key = sourceKey(randomUUID(), 'png');
|
||||
await putObject(key, buf, 'image/png');
|
||||
const name = (it.filename || 'bild').replace(/\.[^.]+$/, '') + '.png';
|
||||
return json({ source_path: key, filename: name });
|
||||
} catch (e: any) {
|
||||
return json({ error: e?.message || 'Konnte Ergebnis nicht laden.' }, 500);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user