Files
Emailsorter/server/cleanup.mjs
ANDJ abf761db07 Email Sorter Beta
Ich habe soweit automatisiert the Emails sortieren aber ich muss noch schauen was es fur bugs es gibt wenn die app online  ist deswegen wurde ich mit diesen Commit die website veroffentlichen obwohjl es sein konnte  das es noch nicht fertig ist und verkaufs bereit
2026-01-22 19:32:12 +01:00

49 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* EmailSorter - Database Cleanup Script
*
* ⚠️ WICHTIG: Liest Credentials aus Umgebungsvariablen (.env)
* Keine hardcoded API Keys mehr!
*/
import 'dotenv/config';
import { Client, Databases } from "node-appwrite";
// Prüfe erforderliche Umgebungsvariablen
const requiredEnv = [
"APPWRITE_ENDPOINT",
"APPWRITE_PROJECT_ID",
"APPWRITE_API_KEY",
"APPWRITE_DATABASE_ID"
];
for (const key of requiredEnv) {
if (!process.env[key]) {
console.error(`❌ Fehlende Umgebungsvariable: ${key}`);
console.error(`\nBitte setze diese Variable in server/.env`);
process.exit(1);
}
}
const client = new Client()
.setEndpoint(process.env.APPWRITE_ENDPOINT)
.setProject(process.env.APPWRITE_PROJECT_ID)
.setKey(process.env.APPWRITE_API_KEY);
const db = new Databases(client);
const databaseId = process.env.APPWRITE_DATABASE_ID;
console.log(`🗑️ Lösche Datenbank: ${databaseId}`);
console.log(`⚠️ WARNUNG: Diese Aktion kann nicht rückgängig gemacht werden!\n`);
try {
await db.delete(databaseId);
console.log(`✅ Datenbank erfolgreich gelöscht: ${databaseId}`);
} catch (e) {
if (e.code === 404) {
console.log(` Datenbank existiert nicht: ${databaseId}`);
} else {
console.error(`❌ Fehler beim Löschen der Datenbank:`, e.message);
process.exit(1);
}
}