UNPKG

discord-media-server

Version:

Self-hosted Discord bot for scanning and serving information on local media files.

56 lines (48 loc) 1.66 kB
// reset-db.js (clears Movie_Info table without touching config) import fs from 'fs'; import path from 'path'; import dotenv from 'dotenv'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; import { DATA_DIR } from './setupConfig.js'; import { initDatabase, query, close, isSQLite } from './database.js'; dotenv.config(); const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); export async function resetMovieTable() { try { const DB_NAME = process.env.DB_NAME || 'media'; const cacheDir = DATA_DIR || path.resolve(__dirname, '../data'); const cachePath = path.resolve(cacheDir, `${DB_NAME}.json`); if (fs.existsSync(cachePath)) { fs.unlink(cachePath, (err) => { if (err) { console.log('Error deleting file:', err); return; } console.log('Cache file deleted successfully'); }); } else { console.log('No cache file found to delete.'); } //await initDatabase(); // delete database if (isSQLite) { await query('DELETE FROM Movie_Info'); await query('VACUUM'); // Clean up disk space } else { await query('TRUNCATE TABLE Movie_Info'); } console.log('Movie_Info table has been cleared.'); } catch (err) { console.error('Failed to reset Movie_Info:', err.message); //process.exit(1); } finally { await close(); //process.exit(0); } } // CLI entry point if (process.argv[1] === fileURLToPath(import.meta.url)) { resetMovieTable().then(() => process.exit(0)).catch(() => process.exit(1)); }