🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Simplify
Edward Cui7c7a0a45e309
diff --git a/client/src/api/admin/import.ts b/client/src/api/admin/import.tsindex 790fa185f..838092f6c 100644--- a/client/src/api/admin/import.ts+++ b/client/src/api/admin/import.ts@@ -1,7 +1,6 @@import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { authedFetch } from "@/api/utils";import { APIResponse } from "@/api/types";-import type { AllowedDateRange } from "@/lib/import/types";interface GetSiteImportsResponse {importId: string;@@ -14,7 +13,10 @@ interface GetSiteImportsResponse {interface CreateSiteImportResponse {importId: string;- allowedDateRange: AllowedDateRange;+ allowedDateRange: {+ earliestAllowedDate: string;+ latestAllowedDate: string;+ };}interface DeleteImportResponse {diff --git a/client/src/components/SiteSettings/ImportManager.tsx b/client/src/components/SiteSettings/ImportManager.tsxindex ff85af510..2170b9246 100644--- a/client/src/components/SiteSettings/ImportManager.tsx+++ b/client/src/components/SiteSettings/ImportManager.tsx@@ -23,7 +23,7 @@ import { Upload, FileText, AlertCircle, CheckCircle2, Clock, Loader2, Trash2, Inimport { useGetSiteImports, useCreateSiteImport, useDeleteSiteImport } from "@/api/admin/import";import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";import { IS_CLOUD } from "@/lib/const";-import { CSVWorkerManager } from "@/lib/import/csv-worker-manager";+import { CsvParser } from "@/lib/import/csvParser";interface ImportManagerProps {siteId: number;@@ -66,7 +66,7 @@ export function ImportManager({ siteId, disabled }: ImportManagerProps) {const [selectedFile, setSelectedFile] = useState<File | null>(null);const [fileError, setFileError] = useState<string>("");const fileInputRef = useRef<HTMLInputElement>(null);- const workerManagerRef = useRef<CSVWorkerManager | null>(null);+ const workerManagerRef = useRef<CsvParser | null>(null);const { data, isLoading, error } = useGetSiteImports(siteId);const createImportMutation = useCreateSiteImport(siteId);@@ -103,7 +103,7 @@ export function ImportManager({ siteId, disabled }: ImportManagerProps) {onSuccess: response => {const { importId, allowedDateRange } = response.data;- workerManagerRef.current = new CSVWorkerManager();+ workerManagerRef.current = new CsvParser();workerManagerRef.current.startImport(file,diff --git a/client/src/lib/import/csv-worker-manager.ts b/client/src/lib/import/csvParser.tssimilarity index 88%rename from client/src/lib/import/csv-worker-manager.tsrename to client/src/lib/import/csvParser.tsindex 934cfc12c..a5ffd28ee 100644--- a/client/src/lib/import/csv-worker-manager.ts+++ b/client/src/lib/import/csvParser.ts@@ -1,9 +1,32 @@import Papa from "papaparse";import { DateTime } from "luxon";import { authedFetch } from "@/api/utils";-import type { UmamiEvent } from "./types";-export class CSVWorkerManager {+interface UmamiEvent {+ session_id: string;+ hostname: string;+ browser: string;+ os: string;+ device: string;+ screen: string;+ language: string;+ country: string;+ region: string;+ city: string;+ url_path: string;+ url_query: string;+ referrer_path: string;+ referrer_query: string;+ referrer_domain: string;+ page_title: string;+ event_type: string;+ event_name: string;+ distinct_id: string;+ created_at: string;+}+++export class CsvParser {private aborted = false;private quotaExceeded = false;private siteId: number = 0;@@ -30,12 +53,12 @@ export class CSVWorkerManager {this.latestAllowedDate = DateTime.fromFormat(latestAllowedDate, "yyyy-MM-dd", { zone: "utc" }).endOf("day");if (!this.earliestAllowedDate.isValid) {- this.handleError(`Invalid earliest allowed date: ${earliestAllowedDate}`);+ this.aborted = true;return;}if (!this.latestAllowedDate.isValid) {- this.handleError(`Invalid latest allowed date: ${latestAllowedDate}`);+ this.aborted = true;return;}@@ -67,9 +90,9 @@ export class CSVWorkerManager {this.parsingComplete = true;this.processQueue();},- error: error => {+ error: () => {if (this.aborted) return;- this.handleError(error.message);+ this.aborted = true;},});}@@ -145,10 +168,6 @@ export class CSVWorkerManager {return umamiEvent;}- private handleError(message: string): void {- this.terminate();- }-private async uploadChunk(events: UmamiEvent[], isLastBatch: boolean): Promise<void> {if (this.quotaExceeded) {return;@@ -177,13 +196,8 @@ export class CSVWorkerManager {return;}} catch (error) {- // Critical failure - network error, server error, etc.- this.terminate();+ this.aborted = true;return;}}-- terminate(): void {- this.aborted = true;- }}diff --git a/client/src/lib/import/types.ts b/client/src/lib/import/types.tsdeleted file mode 100644index 851841268..000000000--- a/client/src/lib/import/types.ts+++ /dev/null@@ -1,27 +0,0 @@-export interface AllowedDateRange {- earliestAllowedDate: string;- latestAllowedDate: string;-}--export interface UmamiEvent {- session_id: string;- hostname: string;- browser: string;- os: string;- device: string;- screen: string;- language: string;- country: string;- region: string;- city: string;- url_path: string;- url_query: string;- referrer_path: string;- referrer_query: string;- referrer_domain: string;- page_title: string;- event_type: string;- event_name: string;- distinct_id: string;- created_at: string;-}