feat: enhance CSV upload handling with chunked requests and token support; improve form input limits
This commit is contained in:
@@ -52,22 +52,28 @@ export async function getTableData() {
|
||||
}
|
||||
|
||||
export async function createEntry(data) {
|
||||
let { status } = { status: true };
|
||||
for (const item of data) {
|
||||
if (!Array.isArray(data) || data.length === 0) return true;
|
||||
|
||||
// Normalize values to strings and unique them to reduce duplicates
|
||||
const values = Array.from(
|
||||
new Set(data.map((v) => String(v).trim()).filter(Boolean))
|
||||
);
|
||||
|
||||
// Prepare bulk insert values [[v1],[v2],...]
|
||||
const rows = values.map((v) => [v]);
|
||||
|
||||
try {
|
||||
// Use INSERT IGNORE to skip duplicates on UNIQUE(losnummer)
|
||||
const [result] = await pool.query(
|
||||
"INSERT INTO lose (losnummer) VALUES (?)",
|
||||
[item]
|
||||
"INSERT IGNORE INTO lose (losnummer) VALUES ?",
|
||||
[rows]
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
status = true;
|
||||
} else {
|
||||
status = false;
|
||||
return status;
|
||||
}
|
||||
// result.affectedRows may be less than rows.length if duplicates existed
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error("Bulk insert failed", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
export async function removeEntries(losnummern) {
|
||||
|
Reference in New Issue
Block a user