Skip to content

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

Format

Edward Cuiafa44e162a30
diff --git a/server/src/api/import/plausible.ts b/server/src/api/import/plausible.ts
index 839910533..1ce67aee4 100644
--- a/server/src/api/import/plausible.ts
+++ b/server/src/api/import/plausible.ts
@@ -11,16 +11,16 @@ interface ImportPlausibleRequest {
const MAX_FILES = 10;
const MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
const ALLOWED_TABLES = [
- "visitors",
- "sources",
- "pages",
- "entry_pages",
- "exit_pages",
- "custom_events",
- "locations",
- "devices",
- "browsers",
- "operating_systems",
+ "visitors",
+ "sources",
+ "pages",
+ "entry_pages",
+ "exit_pages",
+ "custom_events",
+ "locations",
+ "devices",
+ "browsers",
+ "operating_systems",
];
export async function importPlausible(request: FastifyRequest<ImportPlausibleRequest>, reply: FastifyReply) {
@@ -36,19 +36,19 @@ export async function importPlausible(request: FastifyRequest<ImportPlausibleReq
for await (const part of parts) {
if (part.type === "file") {
- const chunks = [];
- let totalSize = 0;
- for await (const chunk of part.file) {
- totalSize += chunk.length;
- if (totalSize > MAX_FILE_SIZE) {
- return reply.status(400).send({ error: `File ${part.filename} is larger than the 100MB limit.` });
- }
- chunks.push(chunk);
+ const chunks = [];
+ let totalSize = 0;
+ for await (const chunk of part.file) {
+ totalSize += chunk.length;
+ if (totalSize > MAX_FILE_SIZE) {
+ return reply.status(400).send({ error: `File ${part.filename } is larger than the 100MB limit.`});
}
- const fileContent = Buffer.concat(chunks).toString("utf-8");
- files.push({ fileName: part.filename, fileContent });
+ chunks.push(chunk);
+ }
+ const fileContent = Buffer.concat(chunks).toString("utf-8");
+ files.push({ fileName: part.filename, fileContent });
} else {
- // Handle other form fields if necessary
+ // Handle other form fields if necessary
}
}
@@ -59,12 +59,12 @@ export async function importPlausible(request: FastifyRequest<ImportPlausibleReq
for (const file of files) {
const fileNameParts = file.fileName.split("_");
if (fileNameParts.length !== 4 || fileNameParts[0] !== "imported" || !fileNameParts[3].endsWith(".csv")) {
- return reply.status(400).send({ error: `Invalid file name format for ${file.fileName}.` });
+ return reply.status(400).send({ error: `Invalid file name format for ${file.fileName}.` });
}
const tableName = fileNameParts[1];
if (!ALLOWED_TABLES.includes(tableName)) {
- return reply.status(400).send({ error: `Invalid table name in file ${file.fileName}.` });
+ return reply.status(400).send({ error: `Invalid table name in file ${file.fileName}.` });
}
}