fix: add missing readBooks translations
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Has been cancelled

This commit is contained in:
2026-02-16 00:37:34 +01:00
parent 0a0895cf89
commit 931843a5c6
21 changed files with 945 additions and 16 deletions

View File

@@ -0,0 +1,66 @@
#!/usr/bin/env node
require('dotenv').config();
const DIRECTUS_URL = process.env.DIRECTUS_URL || 'https://cms.dk0.dev';
const DIRECTUS_TOKEN = process.env.DIRECTUS_STATIC_TOKEN;
async function api(endpoint, method = 'POST', body = null) {
const res = await fetch(`${DIRECTUS_URL}/${endpoint}`, {
method,
headers: { 'Authorization': `Bearer ${DIRECTUS_TOKEN}`, 'Content-Type': 'application/json' },
body: body ? JSON.stringify(body) : null
});
return res.ok ? await res.json() : { error: true, status: res.status };
}
async function atomicSetup() {
console.log('🚀 Starte atomares Setup...');
// 1. Die Haupt-Collection mit allen Feldern in EINEM Request
const setup = await api('collections', 'POST', {
collection: 'book_reviews',
schema: {},
meta: { icon: 'import_contacts', display_template: '{{book_title}}' },
fields: [
{ field: 'id', type: 'integer', schema: { is_primary_key: true, has_auto_increment: true } },
{ field: 'status', type: 'string', schema: { default_value: 'draft' }, meta: { interface: 'select-dropdown' } },
{ field: 'book_title', type: 'string', schema: {}, meta: { interface: 'input' } },
{ field: 'book_author', type: 'string', schema: {}, meta: { interface: 'input' } },
{ field: 'book_image', type: 'string', schema: {}, meta: { interface: 'input' } },
{ field: 'rating', type: 'integer', schema: {}, meta: { interface: 'rating' } },
{ field: 'hardcover_id', type: 'string', schema: { is_unique: true }, meta: { interface: 'input' } },
{ field: 'finished_at', type: 'date', schema: {}, meta: { interface: 'datetime' } }
]
});
if (setup.error) { console.error('Fehler bei Haupt-Collection:', setup); return; }
console.log('✅ Haupt-Collection steht.');
// 2. Die Übersetzungs-Collection
await api('collections', 'POST', {
collection: 'book_reviews_translations',
schema: {},
meta: { hidden: true },
fields: [
{ field: 'id', type: 'integer', schema: { is_primary_key: true, has_auto_increment: true } },
{ field: 'book_reviews_id', type: 'integer', schema: {} },
{ field: 'languages_code', type: 'string', schema: {} },
{ field: 'review', type: 'text', schema: {}, meta: { interface: 'input-rich-text-html' } }
]
});
console.log('✅ Übersetzungstabelle steht.');
// 3. Die Relationen (Der Kleber)
await api('relations', 'POST', { collection: 'book_reviews_translations', field: 'book_reviews_id', related_collection: 'book_reviews', meta: { one_field: 'translations' }, schema: { on_delete: 'CASCADE' } });
await api('relations', 'POST', { collection: 'book_reviews_translations', field: 'languages_code', related_collection: 'languages', schema: { on_delete: 'SET NULL' } });
// 4. Das Translations-Feld in der Haupt-Collection registrieren
await api('fields/book_reviews', 'POST', {
field: 'translations',
type: 'alias',
meta: { interface: 'translations', special: ['translations'], options: { languageField: 'languages_code' } }
});
console.log('✨ Alles fertig! Bitte lade Directus neu.');
}
atomicSetup().catch(console.error);