Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Has been cancelled
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
#!/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 = 'PATCH', 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
|
|
});
|
|
const data = await res.json().catch(() => ({}));
|
|
return { ok: res.ok, data };
|
|
}
|
|
|
|
async function fixAutoId() {
|
|
console.log('🛠 Automatisierung der IDs für Übersetzungen...');
|
|
|
|
// 1. ID Feld in der Übersetzungstabelle konfigurieren
|
|
await api('fields/book_reviews_translations/id', 'PATCH', {
|
|
meta: {
|
|
hidden: true,
|
|
interface: 'input',
|
|
readonly: true,
|
|
special: null
|
|
}
|
|
});
|
|
|
|
// 2. Fremdschlüssel (book_reviews_id) verstecken, da Directus das intern regelt
|
|
await api('fields/book_reviews_translations/book_reviews_id', 'PATCH', {
|
|
meta: {
|
|
hidden: true,
|
|
interface: 'input',
|
|
readonly: true
|
|
}
|
|
});
|
|
|
|
// 3. Sprach-Code Feld konfigurieren
|
|
await api('fields/book_reviews_translations/languages_code', 'PATCH', {
|
|
meta: {
|
|
interface: 'select-dropdown',
|
|
width: 'half',
|
|
options: {
|
|
choices: [
|
|
{ text: 'Deutsch', value: 'de-DE' },
|
|
{ text: 'English', value: 'en-US' }
|
|
]
|
|
}
|
|
}
|
|
});
|
|
|
|
console.log('✅ Fertig! Die IDs werden nun automatisch im Hintergrund verwaltet.');
|
|
}
|
|
|
|
fixAutoId().catch(console.error);
|