Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Has been cancelled
47 lines
1.9 KiB
JavaScript
47 lines
1.9 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 globalBeautyFix() {
|
|
console.log('✨ Starte globale CMS-Verschönerung...');
|
|
await api('items/languages', 'POST', { code: 'de-DE', name: 'German' }).catch(() => {});
|
|
await api('items/languages', 'POST', { code: 'en-US', name: 'English' }).catch(() => {});
|
|
|
|
const collections = ['projects', 'book_reviews', 'hobbies', 'tech_stack_categories', 'messages'];
|
|
for (const coll of collections) {
|
|
console.log('📦 Optimiere ' + coll);
|
|
await api('collections/' + coll + '_translations', 'PATCH', { meta: { hidden: true } });
|
|
await api('fields/' + coll + '/translations', 'PATCH', {
|
|
meta: {
|
|
interface: 'translations',
|
|
display: 'translations',
|
|
width: 'full',
|
|
options: { languageField: 'languages_code', defaultLanguage: 'de-DE', userLanguage: true }
|
|
}
|
|
});
|
|
await api('relations', 'POST', {
|
|
collection: coll + '_translations',
|
|
field: 'languages_code',
|
|
related_collection: 'languages',
|
|
meta: { interface: 'select-dropdown' }
|
|
}).catch(() => {});
|
|
}
|
|
await api('fields/projects/tags', 'PATCH', { meta: { interface: 'tags' } });
|
|
await api('fields/projects/technologies', 'PATCH', { meta: { interface: 'tags' } });
|
|
console.log('✅ CMS ist jetzt aufgeräumt! Bitte Directus neu laden.');
|
|
}
|
|
globalBeautyFix().catch(console.error);
|