Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Async

Edward Cui444a0e5883ed
diff --git a/server/src/services/import/workers/csvParseWorker.ts b/server/src/services/import/workers/csvParseWorker.ts
index 01ca23d84..97351dd85 100644
--- a/server/src/services/import/workers/csvParseWorker.ts
+++ b/server/src/services/import/workers/csvParseWorker.ts
@@ -1,14 +1,15 @@
-import fs from "fs";
-import { parse } from "@fast-csv/parse";
+import { access, constants } from "node:fs/promises";
+import { createReadStream } from "node:fs";
import { Readable } from "stream";
+import { parse } from "@fast-csv/parse";
+import { DateTime } from "luxon";
+import { Job } from "pg-boss";
import boss from "../../../db/postgres/boss.js";
+import { r2Storage } from "../../storage/r2StorageService.js";
import { CSV_PARSE_QUEUE, CsvParseJob, DATA_INSERT_QUEUE } from "./jobs.js";
-import { Job } from "pg-boss";
import { UmamiEvent, umamiHeaders } from "../mappings/umami.js";
import { ImportStatusManager } from "../importStatusManager.js";
import { ImportLimiter } from "../importLimiter.js";
-import { r2Storage } from "../../storage/r2StorageService.js";
-import { DateTime } from "luxon";
import { deleteImportFile } from "../utils.js";
const getImportDataHeaders = (source: string) => {
@@ -48,10 +49,8 @@ export async function registerCsvParseWorker() {
}));
} else {
console.log(`[CSV Parser] Reading from local disk: ${storageLocation}`);
- if (!fs.existsSync(storageLocation)) {
- throw new Error(`Import file not found at path: ${storageLocation}`);
- }
- stream = fs.createReadStream(storageLocation).pipe(parse({
+ await access(storageLocation, constants.F_OK | constants.R_OK);
+ stream = createReadStream(storageLocation).pipe(parse({
headers: getImportDataHeaders(source),
renameHeaders: true,
ignoreEmpty: true,