Add domain field to shortlink API responses and sync script
This commit is contained in:
@@ -49,6 +49,7 @@ interface ShortLink {
|
||||
expires_at?: string | null;
|
||||
click_count?: number;
|
||||
unique_visitors?: number;
|
||||
domain?: string;
|
||||
}
|
||||
|
||||
// Define ClickHouse shorturl type
|
||||
@@ -77,6 +78,7 @@ interface ClickHouseShortUrl {
|
||||
expires_at: string | null;
|
||||
click_count: number;
|
||||
unique_visitors: number;
|
||||
domain?: string; // 添加domain字段
|
||||
link_attributes?: string; // Optional JSON string containing link-specific attributes
|
||||
}
|
||||
|
||||
@@ -175,7 +177,7 @@ export default function LinksPage() {
|
||||
projects: projects,
|
||||
tags: tags,
|
||||
createdAt: link.created_at,
|
||||
domain: shortUrlValue ? new URL(shortUrlValue).hostname : 'shorturl.example.com'
|
||||
domain: link.domain || (shortUrlValue ? new URL(shortUrlValue).hostname : '')
|
||||
};
|
||||
|
||||
// 打印完整数据,确保 externalId 被包含
|
||||
@@ -197,19 +199,26 @@ export default function LinksPage() {
|
||||
: link.attributes || {};
|
||||
|
||||
// Parse attributes to get domain if available
|
||||
let domain = 'shorturl.example.com';
|
||||
let domain = '';
|
||||
try {
|
||||
// Extract domain from shortUrl in attributes if available
|
||||
const attributesObj = typeof link.attributes === 'string'
|
||||
? JSON.parse(link.attributes)
|
||||
: link.attributes || {};
|
||||
|
||||
if (attributesObj.shortUrl) {
|
||||
try {
|
||||
const urlObj = new URL(attributesObj.shortUrl);
|
||||
domain = urlObj.hostname;
|
||||
} catch (e) {
|
||||
console.error('Error parsing shortUrl:', e);
|
||||
// 首先尝试使用link.domain字段
|
||||
if (link.domain) {
|
||||
domain = link.domain;
|
||||
}
|
||||
// 如果没有domain字段,从shortUrl中提取
|
||||
else {
|
||||
// Extract domain from shortUrl in attributes if available
|
||||
const attributesObj = typeof link.attributes === 'string'
|
||||
? JSON.parse(link.attributes)
|
||||
: link.attributes || {};
|
||||
|
||||
if (attributesObj.shortUrl) {
|
||||
try {
|
||||
const urlObj = new URL(attributesObj.shortUrl);
|
||||
domain = urlObj.hostname;
|
||||
} catch (e) {
|
||||
console.error('Error parsing shortUrl:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user