Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Has been cancelled
55 lines
1.8 KiB
JavaScript
55 lines
1.8 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 = 'GET', body = null) {
|
|
const url = `${DIRECTUS_URL}/${endpoint}`;
|
|
const options = {
|
|
method,
|
|
headers: { 'Authorization': `Bearer ${DIRECTUS_TOKEN}`, 'Content-Type': 'application/json' }
|
|
};
|
|
if (body) options.body = JSON.stringify(body);
|
|
const response = await fetch(url, options);
|
|
const data = await response.json().catch(() => ({}));
|
|
return { ok: response.ok, data };
|
|
}
|
|
|
|
async function fixTranslationInterface() {
|
|
console.log('🛠 Erdenke das Translations-Interface neu...');
|
|
|
|
const collections = ['projects', 'book_reviews', 'hobbies', 'tech_stack_categories', 'messages'];
|
|
|
|
for (const coll of collections) {
|
|
console.log(`🔧 Fixe Interface für ${coll}...`);
|
|
|
|
// Wir überschreiben die Metadaten des Feldes "translations"
|
|
// WICHTIG: Wir setzen interface auf 'translations' und mappen das languageField
|
|
await api(`fields/${coll}/translations`, 'PATCH', {
|
|
meta: {
|
|
interface: 'translations',
|
|
display: 'translations',
|
|
special: ['translations'],
|
|
options: {
|
|
languageField: 'languages_code',
|
|
userLanguage: true,
|
|
defaultLanguage: 'de-DE'
|
|
}
|
|
}
|
|
});
|
|
|
|
// Wir stellen sicher, dass in der Untertabelle das Feld languages_code
|
|
// als 'languages' Typ erkannt wird
|
|
await api(`fields/${coll}_translations/languages_code`, 'PATCH', {
|
|
meta: {
|
|
interface: 'select-dropdown',
|
|
special: null // Kein spezielles Feld hier, nur ein normaler FK
|
|
}
|
|
});
|
|
}
|
|
|
|
console.log('✅ Übersetzung-Tabs sollten jetzt erscheinen! Bitte Directus hart neu laden.');
|
|
}
|
|
|
|
fixTranslationInterface().catch(console.error);
|