fix: add missing readBooks translations
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Has been cancelled
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Has been cancelled
This commit is contained in:
63
scripts/force-translations-plus.js
Normal file
63
scripts/force-translations-plus.js
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/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 forceTranslationsPlusButton() {
|
||||
console.log('🔨 Erzwinge "Plus"-Button für Übersetzungen...');
|
||||
|
||||
const coll = 'book_reviews';
|
||||
const transColl = 'book_reviews_translations';
|
||||
|
||||
// 1. Das alte Alias-Feld löschen (falls es klemmt)
|
||||
await api(`fields/${coll}/translations`, 'DELETE').catch(() => {});
|
||||
|
||||
// 2. Das Feld komplett neu anlegen als technisches Alias für die Relation
|
||||
await api(`fields/${coll}`, 'POST', {
|
||||
field: 'translations',
|
||||
type: 'alias',
|
||||
meta: {
|
||||
interface: 'translations',
|
||||
display: 'translations',
|
||||
special: ['translations'],
|
||||
options: {
|
||||
languageField: 'languages_code',
|
||||
userLanguage: true
|
||||
},
|
||||
width: 'full'
|
||||
}
|
||||
});
|
||||
|
||||
// 3. Die Relation explizit als One-to-Many (O2M) registrieren
|
||||
// Das ist der wichtigste Schritt für den Plus-Button!
|
||||
await api('relations', 'POST', {
|
||||
collection: transColl,
|
||||
field: 'book_reviews_id',
|
||||
related_collection: coll,
|
||||
meta: {
|
||||
one_field: 'translations',
|
||||
junction_field: null,
|
||||
one_deselect_action: 'delete'
|
||||
},
|
||||
schema: {
|
||||
on_delete: 'CASCADE'
|
||||
}
|
||||
}).catch(err => console.log('Relation existiert evtl. schon, überspringe...'));
|
||||
|
||||
console.log('✅ Fertig! Bitte lade Directus neu.');
|
||||
console.log('Gehe in ein Buch -> Jetzt MUSS unten bei "Translations" ein Plus-Button oder "Create New" stehen.');
|
||||
}
|
||||
|
||||
forceTranslationsPlusButton().catch(console.error);
|
||||
Reference in New Issue
Block a user