Add dedupe

This commit is contained in:
Christopher Cookman 2024-12-22 17:16:53 -07:00
parent 606a1e57e4
commit 4b9b8b726c
2 changed files with 8 additions and 2 deletions

View file

@ -169,7 +169,7 @@ router.post('/import', authenticate, upload.single('fileInput'), async (req, res
const data = fs.readFileSync(filePath, 'utf-8'); const data = fs.readFileSync(filePath, 'utf-8');
const lines = data.split('\n'); const lines = data.split('\n');
const conn = await pool.getConnection(); const conn = await pool.getConnection();
uploads[uploadId] = { completed: false, total: lines.length, processed: 0 }; uploads[uploadId] = { completed: false, total: lines.length, processed: 0, skipped: 0 };
res.end(JSON.stringify({ success: true, message: 'Started upload, please wait!', id: uploadId })); res.end(JSON.stringify({ success: true, message: 'Started upload, please wait!', id: uploadId }));
for (const line of lines) { for (const line of lines) {
// This is a text file, split by "x/"", get [0], then split by / and get the last element, that will be an ID. All other values are static. // This is a text file, split by "x/"", get [0], then split by / and get the last element, that will be an ID. All other values are static.
@ -178,6 +178,12 @@ router.post('/import', authenticate, upload.single('fileInput'), async (req, res
const reasonShort = "Listed by MFD"; const reasonShort = "Listed by MFD";
const moderator = "MFD"; const moderator = "MFD";
const reasonsFlag = flags.addFlag(0, reasonFlags.CHILD_SAFETY) const reasonsFlag = flags.addFlag(0, reasonFlags.CHILD_SAFETY)
const existingBan = await conn.query('SELECT * FROM bans WHERE robloxId = ?', [robloxId]);
if (existingBan.length > 0) {
uploads[uploadId].processed++;
uploads[uploadId].skipped++
continue; // Skip this entry if robloxId already exists
}
await conn.query('INSERT INTO bans (robloxId, reasonShort, reasonLong, reasonsFlag, moderator) VALUES (?, ?, ?, ?, ?)', await conn.query('INSERT INTO bans (robloxId, reasonShort, reasonLong, reasonsFlag, moderator) VALUES (?, ?, ?, ?, ?)',
[robloxId, reasonShort, reasonLong, reasonsFlag, moderator]); [robloxId, reasonShort, reasonLong, reasonsFlag, moderator]);
uploads[uploadId].processed++; uploads[uploadId].processed++;

View file

@ -15,7 +15,7 @@
<h2 class="text-center mb-4">Mass Ban (Import)</h2> <h2 class="text-center mb-4">Mass Ban (Import)</h2>
<div class="alert" id="message" style="display: none;"></div> <div class="alert" id="message" style="display: none;"></div>
<div class="alert alert-warning"> <div class="alert alert-warning">
The import system does <strong>NOT</strong> have deduplication. Please be sure to remove duplicate entries from your list <strong>BEFORE</strong> uploading! The import system does <strong>NOT</strong> have deduplication for CSV files. Please be sure to remove duplicate entries from your list <strong>BEFORE</strong> uploading!
</div> </div>
<form id="banForm"> <form id="banForm">
<div class="mb-3"> <div class="mb-3">