mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 14:45:01 -05:00
They were the last files the Import page read itself and sent whole. A chosen Jira file is now uploaded like the other sources: the people of its map-members step are read from it by the server (the Jira mapper is shared, models/lib/jiraMembersMapper.js), and the estimate mapping goes with the import call. A CSV / TSV file's header, sample rows and guessed mapping come from the server (csvUploadPreview), its people from the columns chosen (csvUploadPeople), and the import parses it there. Both methods read only the sender's own upload, signed in and while import is enabled, and leave it for the import that follows. Thanks to xet7 !
21 lines
936 B
JavaScript
21 lines
936 B
JavaScript
// Server-only: the rows of a CSV/TSV file uploaded to the local disk
|
|
// (server/lib/importUpload.js), parsed as the page parses a pasted text
|
|
// (client/components/import/csvMapping.js parseCsvImportText): a first line
|
|
// with a tab means tab-separated.
|
|
import { csvSeparatorOf } from '/models/lib/csvImportMapping';
|
|
|
|
const MAX_TEXT_BYTES = 256 * 1024 * 1024;
|
|
|
|
export async function readCsvUploadRows(file) {
|
|
const fs = require('fs');
|
|
const { size } = await fs.promises.stat(file);
|
|
if (size > MAX_TEXT_BYTES) {
|
|
const error = new Error(`A CSV file is read as one text, at most ${MAX_TEXT_BYTES} bytes`);
|
|
error.code = 'import-too-large';
|
|
throw error;
|
|
}
|
|
const text = (await fs.promises.readFile(file, 'utf8')).replace(/^\uFEFF/, '');
|
|
const result = require('papaparse').parse(text, { delimiter: csvSeparatorOf(text), skipEmptyLines: 'greedy' });
|
|
return result && Array.isArray(result.data) ? result.data : [];
|
|
}
|