fix(analytics): accept beacon download tracking payloads (v1.1.1)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+13
-1
@@ -36,10 +36,22 @@ function writeData(data) {
|
||||
|
||||
const DEFAULT_TRACK_DOWNLOAD_CORS_ORIGINS = [
|
||||
'https://ttrpgplayer.ru',
|
||||
'https://www.ttrpgplayer.ru',
|
||||
'http://localhost:5173',
|
||||
'http://127.0.0.1:5173',
|
||||
'http://localhost:5174',
|
||||
'http://127.0.0.1:5174',
|
||||
];
|
||||
|
||||
function parseTrackDownloadBody(raw) {
|
||||
if (typeof raw !== 'string' || !raw.trim()) return {};
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function parseCorsOrigins(value) {
|
||||
if (typeof value !== 'string' || !value.trim()) return null;
|
||||
const list = value.split(',').map((s) => s.trim()).filter(Boolean);
|
||||
@@ -142,7 +154,7 @@ export function createServer(options = {}) {
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const raw = await readBody(req);
|
||||
const body = JSON.parse(raw || '{}');
|
||||
const body = parseTrackDownloadBody(raw);
|
||||
const data = readData();
|
||||
const result = recordDownload(data, body.platform);
|
||||
if (!result.ok) return json(res, 400, { error: result.error }, corsHeaders);
|
||||
|
||||
Reference in New Issue
Block a user