This commit is contained in:
2025-04-07 21:48:24 +08:00
parent 1a9e28bd7e
commit 33dbf62665
7 changed files with 1100 additions and 235 deletions

View File

@@ -0,0 +1,53 @@
import { NextResponse } from 'next/server';
import { executeQuery } from '@/lib/clickhouse';
export async function GET() {
try {
// Query to fetch shorturl data from ClickHouse
const query = `
SELECT
id,
external_id,
type,
slug,
original_url,
title,
description,
attributes,
schema_version,
creator_id,
creator_email,
creator_name,
created_at,
updated_at,
deleted_at,
projects,
teams,
tags,
qr_codes AS qr_codes,
channels,
favorites,
expires_at,
click_count,
unique_visitors
FROM shorturl_analytics.shorturl
WHERE deleted_at IS NULL
ORDER BY created_at DESC
`;
// Execute the query using the shared client
const rows = await executeQuery(query);
// Return the data
return NextResponse.json({
links: rows,
total: rows.length
});
} catch (error) {
console.error('Error fetching shortlinks from ClickHouse:', error);
return NextResponse.json(
{ error: 'Failed to fetch shortlinks' },
{ status: 500 }
);
}
}