🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Import status endpoint
Edward Cui0aad3a348590
diff --git a/server/src/api/import/getImportStatus.ts b/server/src/api/import/getImportStatus.tsnew file mode 100644index 000000000..9c7e764f8--- /dev/null+++ b/server/src/api/import/getImportStatus.ts@@ -0,0 +1,67 @@+import { FastifyReply, FastifyRequest } from "fastify";+import { getUserHasAccessToSite } from "../../lib/auth-utils.js";+import { ImportStatusManager } from "../../lib/importStatus.js";+import { z } from "zod";++const getImportStatusRequestSchema = z.object({+ params: z.object({+ organization: z.string(),+ site: z.string().min(1),+ }),+ body: z.object({+ importId: z.string(),+ }),+}).strict();++type GetImportStatusRequest = {+ Params: z.infer<typeof getImportStatusRequestSchema.shape.params>;+ Body: z.infer<typeof getImportStatusRequestSchema.shape.body>;+};++export async function getImportStatus(+ request: FastifyRequest<GetImportStatusRequest>,+ reply: FastifyReply,+) {+ try {+ const { organization, site } = request.params;+ const { importId } = request.body;++ const userHasAccess = await getUserHasAccessToSite(request, site);+ if (!userHasAccess) {+ return reply.status(403).send({ error: "Forbidden" });+ }++ const importStatus = await ImportStatusManager.getImportStatus(importId);+ if (!importStatus) {+ return reply.status(404).send({ error: "Import not found" });+ }++ // if (importStatus.createdBy !== request.user?.id) {+ // return reply.status(403).send({ error: "Forbidden" });+ // }++ return reply.send({+ importId: importStatus.importId,+ status: importStatus.status,+ progress: {+ totalRows: importStatus.totalRows,+ processedRows: importStatus.processedRows,+ chunksCompleted: importStatus.chunksCompleted,+ totalChunks: importStatus.totalChunks,+ percentage: importStatus.totalRows+ ? Math.round((importStatus.processedRows / importStatus.totalRows) * 100)+ : 0,+ },+ timestamps: {+ startedAt: importStatus.startedAt,+ completedAt: importStatus.completedAt,+ },+ error: importStatus.errorMessage,+ source: importStatus.source,+ fileName: importStatus.fileName,+ });+ } catch (error) {+ console.error("Error fetching import status:", error);+ return reply.status(500).send({ error: "Internal server error" });+ }+}diff --git a/server/src/index.ts b/server/src/index.tsindex 0ddbbcadb..a19393998 100644--- a/server/src/index.ts+++ b/server/src/index.ts@@ -69,10 +69,11 @@ import { IS_CLOUD } from "./lib/const.js";import { siteConfig } from "./lib/siteConfig.js";import { trackEvent } from "./tracker/trackEvent.js";import { extractSiteId, isSitePublic } from "./utils.js";-import { importData } from "./api/importData.js";+import { importData } from "./api/import/importData.js";import boss from "./lib/boss.js";import { registerCsvParseWorker } from "./workers/csvParseWorker.js";import { registerDataInsertWorker } from "./workers/dataInsertWorker.js";+import { getImportStatus } from "./api/import/getImportStatus.js";const __filename = fileURLToPath(import.meta.url);const __dirname = dirname(__filename);@@ -286,6 +287,7 @@ server.get("/api/session-replay/:sessionId/:site", getSessionReplayEvents);// Importsserver.post("/api/import/:organization/:site", importData);+server.post("/api/import-status/:organization/:site", getImportStatus);// Administrativeserver.get("/api/config", getConfig);