mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-04 23:16:37 +08:00
fb5a4e5b59
OpenResty 日志输出 $upstream_cache_status;Agent/协议/ClickHouse 贯通入库。 明细列表与详情按 HIT/MISS 等推导命中、回源、未缓存三态标签。
98 lines
2.5 KiB
TypeScript
98 lines
2.5 KiB
TypeScript
export type AccessLogTab = 'overview' | 'list';
|
|
|
|
export type SearchDraft = {
|
|
nodeId: string;
|
|
remoteAddr: string;
|
|
host: string;
|
|
path: string;
|
|
};
|
|
|
|
export type OverviewRangeHours = 24 | 168 | 360 | 720;
|
|
|
|
export const PAGE_SIZE_OPTIONS = [20, 50, 100, 200];
|
|
|
|
export const OVERVIEW_RANGE_OPTIONS: {
|
|
value: OverviewRangeHours;
|
|
label: string;
|
|
}[] = [
|
|
{ value: 24, label: '24 小时' },
|
|
{ value: 168, label: '7 天' },
|
|
{ value: 360, label: '15 天' },
|
|
{ value: 720, label: '30 天' },
|
|
];
|
|
|
|
export const DETAIL_SORT_OPTIONS = [
|
|
{ value: 'logged_at:desc', label: '时间从新到旧' },
|
|
{ value: 'logged_at:asc', label: '时间从旧到新' },
|
|
{ value: 'status_code:desc', label: '状态码从高到低' },
|
|
{ value: 'status_code:asc', label: '状态码从低到高' },
|
|
{ value: 'remote_addr:asc', label: 'IP 正序' },
|
|
{ value: 'remote_addr:desc', label: 'IP 倒序' },
|
|
];
|
|
|
|
export function parseSortValue(value: string) {
|
|
const [sortBy = 'logged_at', sortOrder = 'desc'] = value.split(':');
|
|
return {
|
|
sortBy,
|
|
sortOrder: sortOrder === 'asc' ? ('asc' as const) : ('desc' as const),
|
|
};
|
|
}
|
|
|
|
export function formatCompactNumber(value: number) {
|
|
return new Intl.NumberFormat('zh-CN', {
|
|
notation: value >= 10000 ? 'compact' : 'standard',
|
|
maximumFractionDigits: 1,
|
|
}).format(value);
|
|
}
|
|
|
|
export function formatOverviewRangeHint(hours: number) {
|
|
if (hours <= 24) return '近 24 小时';
|
|
if (hours % 24 === 0) return `近 ${hours / 24} 天`;
|
|
return `近 ${hours} 小时`;
|
|
}
|
|
|
|
export function formatOverviewTrendLabel(value: string, hours: number) {
|
|
const date = new Date(value);
|
|
if (Number.isNaN(date.getTime())) {
|
|
return '—';
|
|
}
|
|
const month = `${date.getMonth() + 1}`.padStart(2, '0');
|
|
const day = `${date.getDate()}`.padStart(2, '0');
|
|
const hour = `${date.getHours()}`.padStart(2, '0');
|
|
if (hours <= 24) {
|
|
return `${hour}:00`;
|
|
}
|
|
return `${month}/${day} ${hour}:00`;
|
|
}
|
|
|
|
export type CacheOutcome = 'hit' | 'origin' | 'uncached';
|
|
|
|
export function resolveCacheOutcome(
|
|
cacheStatus: string | undefined | null,
|
|
): CacheOutcome {
|
|
const status = (cacheStatus ?? '').trim().toUpperCase();
|
|
if (
|
|
status === 'HIT' ||
|
|
status === 'STALE' ||
|
|
status === 'REVALIDATED' ||
|
|
status === 'UPDATING'
|
|
) {
|
|
return 'hit';
|
|
}
|
|
if (status === 'MISS' || status === 'EXPIRED') {
|
|
return 'origin';
|
|
}
|
|
return 'uncached';
|
|
}
|
|
|
|
export function cacheOutcomeLabel(outcome: CacheOutcome) {
|
|
switch (outcome) {
|
|
case 'hit':
|
|
return '命中';
|
|
case 'origin':
|
|
return '回源';
|
|
default:
|
|
return '未缓存';
|
|
}
|
|
}
|