diff --git a/messageHandlers/hub_settings.js b/messageHandlers/hub_settings.js index 7cfb385..ea54aa1 100644 --- a/messageHandlers/hub_settings.js +++ b/messageHandlers/hub_settings.js @@ -2,7 +2,7 @@ const client = global.discord_client const pool = global.db_pool; const crypto = require('crypto'); const fs = require('fs'); - +const path = require('path'); const { pipeline } = require('stream'); const { promisify } = require('util'); @@ -142,12 +142,20 @@ const execute = async (message) => { await pool.query('DELETE FROM fileAuth WHERE product IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); // Delete files message.channel.send("Deleting product files..."); - const files = await pool.query('SELECT filePath FROM products WHERE hubId = ?', [hubId]); - for (const file of files) { - if (fs.existsSync(file.filePath)) { - fs.unlinkSync(file.filePath); + // const safeFileId = path.basename(product.file); + // 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]); + for (const fileRow of files) { + const safeFileId = path.basename(fileRow.file); + const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route + if (fs.existsSync(filePath)) { + fs.unlinkSync(filePath); + message.channel.send(`Deleted file: ${safeFileId}`); + } else { + message.channel.send(`File not found, skipping: ${safeFileId}`); } } + // Delete purchases message.channel.send("Deleting purchases..."); await pool.query('DELETE FROM purchases WHERE productId IN (SELECT id FROM products WHERE hubId = ?)', [hubId]);