af34cb9cc8
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNQ8ghPfzAfsyVYd6HgFb6
40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
import { one } from './db';
|
|
|
|
/** Baut eine begleitende Metadaten-Datei (Markdown) zu einer Position. */
|
|
export async function buildMetadataMd(itemId: string): Promise<string> {
|
|
const it = await one<any>(
|
|
`SELECT i.filename, i.output_px, i.has_alpha, i.model_used, i.prompt_used, i.cost,
|
|
i.created_at, i.delivery_status, i.color_tag, j.mode, j.recipe_snapshot
|
|
FROM items i JOIN jobs j ON j.id=i.job_id WHERE i.id=$1`, [itemId]);
|
|
if (!it) return '';
|
|
const r = it.recipe_snapshot || {};
|
|
const tasks = Array.isArray(r.tasks) ? r.tasks.join(', ') : '';
|
|
const TAG: Record<string, string> = { red: 'Rot', orange: 'Orange', green: 'Grün', final: 'Final' };
|
|
const lines = [
|
|
`# ${it.filename || itemId}`,
|
|
'',
|
|
`- **Erzeugt:** ${new Date(it.created_at).toISOString()}`,
|
|
`- **Modus:** ${it.mode || 'each'}`,
|
|
tasks ? `- **Aufgaben:** ${tasks}` : '',
|
|
r.output_format ? `- **Format:** ${r.output_format}${r.orientation ? ` (${r.orientation})` : ''}` : '',
|
|
it.output_px ? `- **Auflösung:** ${it.output_px} px${r.dpi ? ` @ ${r.dpi} dpi` : ''}` : '',
|
|
`- **Transparenz:** ${it.has_alpha ? 'ja' : 'nein'}`,
|
|
it.model_used ? `- **Modell:** ${it.model_used}` : '',
|
|
it.color_tag ? `- **Markierung:** ${TAG[it.color_tag] || it.color_tag}` : '',
|
|
it.cost != null ? `- **Kosten:** $${Number(it.cost).toFixed(4)}` : '',
|
|
'',
|
|
'## Prompt',
|
|
'',
|
|
'```',
|
|
(it.prompt_used || '(kein Prompt gespeichert)'),
|
|
'```',
|
|
].filter((l) => l !== '');
|
|
return lines.join('\n') + '\n';
|
|
}
|
|
|
|
/** Dateiname des Beilegers: <ergebnis>.md */
|
|
export function sidecarName(filename: string | null): string {
|
|
const base = (filename || 'klarbild').replace(/\.[^.]+$/, '');
|
|
return `${base}.md`;
|
|
}
|