Add download stats, key deletion, batch creation, and newest-first listing.

Track landing downloads per platform/month, support admin delete and bulk key issue, and sort licenses by createdAtSec.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-07-02 00:21:21 +08:00
parent 4b568ceb56
commit 6d4b74d410
8 changed files with 349 additions and 32 deletions
+42
View File
@@ -0,0 +1,42 @@
export const DOWNLOAD_PLATFORMS = ['windows', 'macos', 'linux'];
export function monthKeyFromDate(date = new Date()) {
const y = date.getUTCFullYear();
const m = String(date.getUTCMonth() + 1).padStart(2, '0');
return `${y}-${m}`;
}
export function normalizeDownloadPlatform(platform) {
const p = String(platform ?? '').trim().toLowerCase();
if (DOWNLOAD_PLATFORMS.includes(p)) return p;
return null;
}
export function ensureDownloadStats(data) {
data.downloadStats ??= { byMonth: {} };
data.downloadStats.byMonth ??= {};
return data.downloadStats;
}
export function recordDownload(data, platform, date = new Date()) {
const normalized = normalizeDownloadPlatform(platform);
if (!normalized) return { ok: false, error: 'invalid_platform' };
const stats = ensureDownloadStats(data);
const month = monthKeyFromDate(date);
stats.byMonth[month] ??= { windows: 0, macos: 0, linux: 0 };
stats.byMonth[month][normalized] += 1;
return { ok: true, month, platform: normalized, count: stats.byMonth[month][normalized] };
}
export function getDownloadStatsForMonth(data, month) {
const stats = ensureDownloadStats(data);
const row = stats.byMonth[month] ?? { windows: 0, macos: 0, linux: 0 };
const total = row.windows + row.macos + row.linux;
return { month, windows: row.windows, macos: row.macos, linux: row.linux, total };
}
export function listDownloadMonths(data) {
const stats = ensureDownloadStats(data);
return Object.keys(stats.byMonth).sort((a, b) => b.localeCompare(a));
}