Possibly fix deletion logic
This commit is contained in:
parent
c569c2cc86
commit
e52c93da5d
|
@ -2,7 +2,7 @@ const client = global.discord_client
|
||||||
const pool = global.db_pool;
|
const pool = global.db_pool;
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const { pipeline } = require('stream');
|
const { pipeline } = require('stream');
|
||||||
const { promisify } = require('util');
|
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]);
|
await pool.query('DELETE FROM fileAuth WHERE product IN (SELECT id FROM products WHERE hubId = ?)', [hubId]);
|
||||||
// Delete files
|
// Delete files
|
||||||
message.channel.send("Deleting product files...");
|
message.channel.send("Deleting product files...");
|
||||||
const files = await pool.query('SELECT filePath FROM products WHERE hubId = ?', [hubId]);
|
// const safeFileId = path.basename(product.file);
|
||||||
for (const file of files) {
|
// const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route
|
||||||
if (fs.existsSync(file.filePath)) {
|
const files = await pool.query('SELECT file FROM products WHERE hubId = ?', [hubId]);
|
||||||
fs.unlinkSync(file.filePath);
|
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
|
// Delete purchases
|
||||||
message.channel.send("Deleting purchases...");
|
message.channel.send("Deleting purchases...");
|
||||||
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]);
|
||||||
|
|
Loading…
Reference in a new issue