Possibly fix deletion logic

This commit is contained in:
Christopher Cookman 2025-09-15 06:29:55 -06:00
parent c569c2cc86
commit e52c93da5d

View file

@ -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]);