70f3904d0e
- Picdrop is a photo-proofing tool that expects handy JPGs; non-alpha results are now delivered as JPEG q92 (4:4:4) instead of 12-32 MB PNGs. Cutouts with alpha stay PNG. Fixes images not showing in POSTER LEA. - buildResultFilename strips doubled dates/UUIDs/hex to avoid messy names. - picdrop-ls gains action:cleanup_tmp; Admin 'Reste aufräumen' button removes leftover .tmp- files from the default gallery. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNQ8ghPfzAfsyVYd6HgFb6
44 lines
1.9 KiB
TypeScript
44 lines
1.9 KiB
TypeScript
import type { APIRoute } from 'astro';
|
|
import posixpath from 'node:path/posix';
|
|
import { loadConfig, cleanupTmp } from '../../../lib/picdrop';
|
|
|
|
export const prerender = false;
|
|
const json = (b: unknown, s = 200) =>
|
|
new Response(JSON.stringify(b), { status: s, headers: { 'Content-Type': 'application/json' } });
|
|
|
|
/** Diagnose: listet einen Picdrop-Ordner (Standard: Basisordner). Body { path? }
|
|
* Aufräumen: Body { action:'cleanup_tmp', gallery } entfernt liegengebliebene .tmp-Dateien. */
|
|
export const POST: APIRoute = async ({ request }) => {
|
|
const b = await request.json().catch(() => ({} as any));
|
|
const cfg = await loadConfig();
|
|
if (!cfg) return json({ error: 'Picdrop nicht konfiguriert.' }, 400);
|
|
if (b.action === 'cleanup_tmp') {
|
|
try {
|
|
const removed = await cleanupTmp(cfg, b.gallery || '');
|
|
return json({ cleaned: removed });
|
|
} catch (e: any) { return json({ error: e?.message || 'Aufräumen fehlgeschlagen.' }, 500); }
|
|
}
|
|
const path = b.path || cfg.basePath || '/';
|
|
try {
|
|
if (cfg.protocol === 'sftp') {
|
|
const SftpClient = (await import('ssh2-sftp-client')).default;
|
|
const c = new SftpClient();
|
|
await c.connect({ host: cfg.host, port: cfg.port, username: cfg.user, password: cfg.password, readyTimeout: 15000 });
|
|
try {
|
|
const list = await c.list(path);
|
|
return json({ path, entries: list.map((e: any) => ({ name: e.name, type: e.type, size: e.size })) });
|
|
} finally { await c.end(); }
|
|
} else {
|
|
const { Client } = await import('basic-ftp');
|
|
const c = new Client(15000);
|
|
await c.access({ host: cfg.host, port: cfg.port, user: cfg.user, password: cfg.password, secure: true });
|
|
try {
|
|
const list = await c.list(path);
|
|
return json({ path, entries: list.map((e: any) => ({ name: e.name, type: e.type, size: e.size })) });
|
|
} finally { c.close(); }
|
|
}
|
|
} catch (e: any) {
|
|
return json({ path, error: e?.message || 'Listing fehlgeschlagen.' });
|
|
}
|
|
};
|