🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Simplify createSiteImport
Edward Cui2dc3d3eab9bb
diff --git a/server/src/api/sites/createSiteImport.ts b/server/src/api/sites/createSiteImport.tsindex adcef3c1a..1703aed3a 100644--- a/server/src/api/sites/createSiteImport.ts+++ b/server/src/api/sites/createSiteImport.ts@@ -62,9 +62,9 @@ export async function createSiteImport(request: FastifyRequest<CreateSiteImportRtry {const quotaTracker = await importQuotaManager.getTracker(organizationId);- const summary = quotaTracker.getSummary();+ const oldestAllowedMonth = quotaTracker.getOldestAllowedMonth();- const earliestAllowedDate = DateTime.fromFormat(summary.oldestAllowedMonth + "01", "yyyyMMdd", {+ const earliestAllowedDate = DateTime.fromFormat(oldestAllowedMonth + "01", "yyyyMMdd", {zone: "utc",}).toFormat("yyyy-MM-dd");const latestAllowedDate = DateTime.utc().toFormat("yyyy-MM-dd");@@ -86,7 +86,8 @@ export async function createSiteImport(request: FastifyRequest<CreateSiteImportR});} catch (error) {importQuotaManager.completeImport(organizationId);- throw error;+ console.error("Error creating import:", error);+ return reply.status(500).send({ error: "Internal server error" });}} catch (error) {console.error("Error creating import:", error);diff --git a/server/src/services/import/importQuotaManager.ts b/server/src/services/import/importQuotaManager.tsindex 49c4e4c7d..98d819822 100644--- a/server/src/services/import/importQuotaManager.ts+++ b/server/src/services/import/importQuotaManager.ts@@ -1,4 +1,4 @@-import { ImportQuotaTracker } from "./importQuotaChecker.js";+import { ImportQuotaTracker } from "./importQuotaTracker.js";import { IS_CLOUD } from "../../lib/const.js";interface CachedTracker {diff --git a/server/src/services/import/importQuotaChecker.ts b/server/src/services/import/importQuotaTracker.tssimilarity index 87%rename from server/src/services/import/importQuotaChecker.tsrename to server/src/services/import/importQuotaTracker.tsindex beada2d09..d80c06f0f 100644--- a/server/src/services/import/importQuotaChecker.ts+++ b/server/src/services/import/importQuotaTracker.ts@@ -192,34 +192,7 @@ export class ImportQuotaTracker {return true;}- getSummary(): {- totalMonthsInWindow: number;- monthsAtCapacity: number;- monthsWithSpace: number;- oldestAllowedMonth: string;- } {- if (this.monthlyLimit === Infinity) {- return {- totalMonthsInWindow: this.historicalWindowMonths,- monthsAtCapacity: 0,- monthsWithSpace: this.historicalWindowMonths,- oldestAllowedMonth: this.oldestAllowedMonth,- };- }-- // Calculate directly from stored data instead of regenerating all monthly quotas- let monthsAtCapacity = 0;- for (const usage of this.monthlyUsage.values()) {- if (usage >= this.monthlyLimit) {- monthsAtCapacity++;- }- }-- return {- totalMonthsInWindow: this.historicalWindowMonths,- monthsAtCapacity,- monthsWithSpace: this.historicalWindowMonths - monthsAtCapacity,- oldestAllowedMonth: this.oldestAllowedMonth,- };+ getOldestAllowedMonth(): string {+ return this.oldestAllowedMonth;}}