Fix settings logic

This commit is contained in:
Christopher Cookman 2025-09-15 06:43:44 -06:00
parent 8d914e38d0
commit c9c0129eaa

View file

@ -150,13 +150,16 @@ const execute = async (message) => {
return; return;
} }
message.channel.send('Deletion Confirmed. Starting deletion process...').then(async msg => { message.channel.send('Deletion Confirmed. Starting deletion process...').then(async msg => {
curMsg = msg.content;
// Proceed with deletion // Proceed with deletion
const hubId = global.hubSettingsHandlers[message.author.id].hub; const hubId = global.hubSettingsHandlers[message.author.id].hub;
// Delete fileAuth // Delete fileAuth
msg.edit(msg.content + '\nDeleting file authorizations...'); curMsg = curMsg + '\nDeleting file authorizations...'
await msg.edit(curMsg);
await pool.query('DELETE FROM fileAuth WHERE product IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); await pool.query('DELETE FROM fileAuth WHERE product IN (SELECT id FROM products WHERE hubId = ?)', [hubId]);
// Delete files // Delete files
msg.edit(msg.content + '\nDeleting product files...'); curMsg = curMsg + '\nDeleting product files...'
await msg.edit(curMsg);
// const safeFileId = path.basename(product.file); // const safeFileId = path.basename(product.file);
// const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route // const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route
const files = await pool.query('SELECT file FROM products WHERE hubId = ?', [hubId]); const files = await pool.query('SELECT file FROM products WHERE hubId = ?', [hubId]);
@ -165,22 +168,28 @@ const execute = async (message) => {
const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route
if (fs.existsSync(filePath)) { if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath); fs.unlinkSync(filePath);
msg.edit(msg.content + `\nDeleted file: ${safeFileId}`); curMsg = curMsg + `\nDeleted file: ${safeFileId}`;
await msg.edit(curMsg);
} else { } else {
msg.edit(msg.content + `\nFile not found, skipping: ${safeFileId}`); curMsg = curMsg + `\nFile not found (skipping): ${safeFileId}`;
await msg.edit(curMsg);
} }
} }
// Delete purchases // Delete purchases
msg.edit(msg.content + '\nDeleting purchases...'); curMsg = curMsg + '\nDeleting purchases...';
await msg.edit(curMsg);
await pool.query('DELETE FROM purchases WHERE productId IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); await pool.query('DELETE FROM purchases WHERE productId IN (SELECT id FROM products WHERE hubId = ?)', [hubId]);
// Delete products // Delete products
msg.edit(msg.content + '\nDeleting products...'); curMsg = curMsg + '\nDeleting products...';
await msg.edit(curMsg);
await pool.query('DELETE FROM products WHERE hubId = ?', [hubId]); await pool.query('DELETE FROM products WHERE hubId = ?', [hubId]);
// Delete hub // Delete hub
msg.edit(msg.content + '\nDeleting hub...'); curMsg = curMsg + '\nDeleting hub...';
await msg.edit(curMsg);
await pool.query('DELETE FROM hubs WHERE id = ?', [hubId]); await pool.query('DELETE FROM hubs WHERE id = ?', [hubId]);
msg.edit(msg.content + '\nDeletion process complete.'); curMsg = curMsg + '\nHub and all associated data deleted successfully.';
await msg.edit(curMsg);
cancel(message.author); cancel(message.author);
}); });
break; break;