csv text
This commit is contained in:
@@ -2,8 +2,8 @@ import { NextRequest, NextResponse } from 'next/server';
|
|||||||
import { getEvents } from '@/lib/analytics';
|
import { getEvents } from '@/lib/analytics';
|
||||||
import { ApiResponse } from '@/lib/types';
|
import { ApiResponse } from '@/lib/types';
|
||||||
|
|
||||||
// 扩展Event类型以包含所需字段
|
// Extended Event type with required fields
|
||||||
interface EventWithFullPath extends Record<string, any> {
|
interface EventWithFullPath {
|
||||||
event_id?: string;
|
event_id?: string;
|
||||||
event_time?: string;
|
event_time?: string;
|
||||||
event_type?: string;
|
event_type?: string;
|
||||||
@@ -11,7 +11,18 @@ interface EventWithFullPath extends Record<string, any> {
|
|||||||
ip_address?: string;
|
ip_address?: string;
|
||||||
req_full_path?: string;
|
req_full_path?: string;
|
||||||
referrer?: string;
|
referrer?: string;
|
||||||
// 其他可能的字段
|
event_attributes?: string | Record<string, unknown>;
|
||||||
|
link_tags?: string | string[];
|
||||||
|
link_id?: string;
|
||||||
|
link_slug?: string;
|
||||||
|
link_original_url?: string;
|
||||||
|
link_label?: string;
|
||||||
|
device_type?: string;
|
||||||
|
browser?: string;
|
||||||
|
os?: string;
|
||||||
|
country?: string;
|
||||||
|
city?: string;
|
||||||
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
@@ -89,7 +100,7 @@ export async function GET(request: NextRequest) {
|
|||||||
// If utm_campaign is not found or URL parsing fails, use regex as fallback
|
// If utm_campaign is not found or URL parsing fails, use regex as fallback
|
||||||
const campaignMatch = url.match(/[?&]utm_campaign=([^&]+)/i);
|
const campaignMatch = url.match(/[?&]utm_campaign=([^&]+)/i);
|
||||||
if (campaignMatch && campaignMatch[1]) return campaignMatch[1];
|
if (campaignMatch && campaignMatch[1]) return campaignMatch[1];
|
||||||
} catch (_) {
|
} catch {
|
||||||
// If URL parsing fails, try regex directly
|
// If URL parsing fails, try regex directly
|
||||||
const campaignMatch = url.match(/[?&]utm_campaign=([^&]+)/i);
|
const campaignMatch = url.match(/[?&]utm_campaign=([^&]+)/i);
|
||||||
if (campaignMatch && campaignMatch[1]) return campaignMatch[1];
|
if (campaignMatch && campaignMatch[1]) return campaignMatch[1];
|
||||||
@@ -128,16 +139,12 @@ export async function GET(request: NextRequest) {
|
|||||||
csvContent += `${time},${activity},${campaign},${clientId},${originPath}\n`;
|
csvContent += `${time},${activity},${campaign},${clientId},${originPath}\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Generate filename based on available parameters
|
// No need to generate filename since we're not using Content-Disposition header
|
||||||
const filename = slug
|
|
||||||
? `activities-${slug}.csv`
|
|
||||||
: `activities-${new Date().toISOString().slice(0,10)}.csv`;
|
|
||||||
|
|
||||||
// Return CSV response
|
// Return CSV response without forcing download
|
||||||
return new NextResponse(csvContent, {
|
return new NextResponse(csvContent, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/csv',
|
'Content-Type': 'text/plain'
|
||||||
'Content-Disposition': `attachment; filename="${filename}"`
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user