53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
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 }
|
|
);
|
|
}
|
|
}
|