feat(import): lego-sets ueber die rebrickable-api uebernehmen

Auf "Neues Set" reicht die Setnummer von der Packung: Name, Jahr,
Teile, Minifiguren und Thema kommen aus der API, das Bild wird lokal
gespeichert und nicht nur verlinkt. Hersteller und Thema werden bei
Bedarf angelegt, ein Oberthema inklusive. Alle Aufrufe laufen
serverseitig; der Browser spricht nie mit rebrickable.com.

Ohne REBRICKABLE_API_KEY bleibt der Import sichtbar, aber abgeschaltet,
mit dem Hinweis, was zu tun ist - von Hand anlegen geht unveraendert.

Rebrickable liefert keine Anleitungsdateien. Statt das zu verschleiern,
legt der Import einen externen Link auf die LEGO-Serviceseite zur
Setnummer an.

Nebenbei: src/env.ts behandelt leere Werte jetzt wie nicht gesetzt - ein
"BASE_URL=" in der .env fuehrte sonst zum Start-Abbruch mit "Invalid
URL" statt zum Standardwert.

14 neue Unit-Tests decken Antwortverarbeitung, Setnummern-Varianten und
alle Fehlerfaelle der API ab (404, 401, 429, Netzwerk).

Refs Phase 2

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
unknown
2026-09-07 07:12:22 +02:00
co-authored by Claude Opus 5
parent 52d69e5654
commit 4e3cbb81ce
13 changed files with 813 additions and 6 deletions
+16 -1
View File
@@ -31,8 +31,23 @@ const schema = z.object({
REBRICKABLE_API_KEY: z.string().min(1).optional(),
});
/**
* An empty value counts as "not set".
*
* A line like `BASE_URL=` in a .env file is a common slip, and so is an empty
* variable injected by a container runtime. Falling back to the default beats
* failing to start with "Invalid URL".
*/
function withoutEmptyValues(source: NodeJS.ProcessEnv): Record<string, string> {
const result: Record<string, string> = {};
for (const [key, value] of Object.entries(source)) {
if (typeof value === 'string' && value.trim() !== '') result[key] = value;
}
return result;
}
function parseEnv() {
const parsed = schema.safeParse(process.env);
const parsed = schema.safeParse(withoutEmptyValues(process.env));
if (!parsed.success) {
const issues = parsed.error.issues
.map((issue) => ` - ${issue.path.join('.')}: ${issue.message}`)