[feat] solution/frontend: 사이트관리 크롤러 통계 — 전체 통계 탭과 사이트별 페이지, recharts 지연 로드
- 사이트관리에 "목록 / 전체 통계" 탭(?tab=stats)과 각 행의 "통계" 버튼(/ops/sites/:placeId/stats) - 크롤링 화면: 요약 카드 → 일별 누적 막대(용도 4분류+기타) → 봇별 → (전체) 사이트 순위·robots/sitemap· 기타 UA, (사이트별) 많이 읽힌 페이지·최근 50건. 기간 7/30/90일 - recharts 는 CrawlerDailyChart 한 파일에만 두고 lazy() 로 부른다 — 빌드 확인: 그 청크에만 있고 사장님 화면의 첫 로딩 스크립트에는 없다 - OpsSitesPage 는 기존 목록 코드를 다시 들여쓰지 않으려고, stats 탭이면 앞에서 바로 return 하고 탭 UI 는 SitesTabs 로 분리했다(+29/-3) - orval 로 API 클라이언트 재생성 — 줄바꿈(LF/CRLF)만 바뀐 생성 파일 약 90개는 되돌리고 실제 변경분만 담았다 lint(typegen·tsc·eslint)·build 통과. 화면 레이아웃·차트는 브라우저로 직접 보지 못했다(확장 미연결) — nginx 경유 API 호출과 SPA 라우트 200 까지만 확인.
This commit is contained in:
1 parent
d9c9952230
commit
cae3de5586
33 files changed
+1470
-75
No files matched your search
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { CrawlerBotRowBot } from "./crawlerBotRowBot";
|
||||
import type { CrawlerBotRowVendor } from "./crawlerBotRowVendor";
|
||||
|
||||
export interface CrawlerBotRow {
|
||||
bot?: CrawlerBotRowBot;
|
||||
vendor?: CrawlerBotRowVendor;
|
||||
purpose: string;
|
||||
hits: number;
|
||||
last_at: string;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type CrawlerBotRowBot = string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type CrawlerBotRowVendor = string | null;
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export interface CrawlerDaily {
|
||||
day: string;
|
||||
purpose: string;
|
||||
hits: number;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { CrawlerHitRowBot } from "./crawlerHitRowBot";
|
||||
import type { CrawlerHitRowVendor } from "./crawlerHitRowVendor";
|
||||
|
||||
export interface CrawlerHitRow {
|
||||
created_at: string;
|
||||
kind: string;
|
||||
bot?: CrawlerHitRowBot;
|
||||
vendor?: CrawlerHitRowVendor;
|
||||
purpose: string;
|
||||
path: string;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type CrawlerHitRowBot = string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type CrawlerHitRowVendor = string | null;
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export interface CrawlerPathRow {
|
||||
path: string;
|
||||
hits: number;
|
||||
last_at: string;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { CrawlerRootRowBot } from "./crawlerRootRowBot";
|
||||
|
||||
export interface CrawlerRootRow {
|
||||
kind: string;
|
||||
bot?: CrawlerRootRowBot;
|
||||
purpose: string;
|
||||
hits: number;
|
||||
last_at: string;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type CrawlerRootRowBot = string | null;
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export interface CrawlerSiteRow {
|
||||
site_id: string;
|
||||
place_id: string;
|
||||
name: string;
|
||||
hits: number;
|
||||
ai_hits: number;
|
||||
last_at: string;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type CrawlerStatsParams = {
|
||||
/**
|
||||
* KST 날짜, 기본 to-6일
|
||||
*/
|
||||
from?: string | null;
|
||||
/**
|
||||
* KST 날짜, 기본 오늘
|
||||
*/
|
||||
to?: string | null;
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { CrawlerSummaryLastAt } from "./crawlerSummaryLastAt";
|
||||
|
||||
export interface CrawlerSummary {
|
||||
total?: number;
|
||||
ai?: number;
|
||||
bots?: number;
|
||||
last_at?: CrawlerSummaryLastAt;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type CrawlerSummaryLastAt = string | null;
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export interface CrawlerUaRow {
|
||||
user_agent: string;
|
||||
hits: number;
|
||||
last_at: string;
|
||||
}
|
||||
@@ -14,6 +14,21 @@ export * from "./buildStatus";
|
||||
export * from "./checkSlugParams";
|
||||
export * from "./confirm";
|
||||
export * from "./confirmArgs";
|
||||
export * from "./crawlerBotRow";
|
||||
export * from "./crawlerBotRowBot";
|
||||
export * from "./crawlerBotRowVendor";
|
||||
export * from "./crawlerDaily";
|
||||
export * from "./crawlerHitRow";
|
||||
export * from "./crawlerHitRowBot";
|
||||
export * from "./crawlerHitRowVendor";
|
||||
export * from "./crawlerPathRow";
|
||||
export * from "./crawlerRootRow";
|
||||
export * from "./crawlerRootRowBot";
|
||||
export * from "./crawlerSiteRow";
|
||||
export * from "./crawlerStatsParams";
|
||||
export * from "./crawlerSummary";
|
||||
export * from "./crawlerSummaryLastAt";
|
||||
export * from "./crawlerUaRow";
|
||||
export * from "./decision";
|
||||
export * from "./editRedirectParams";
|
||||
export * from "./errorInfo";
|
||||
@@ -258,6 +273,10 @@ export * from "./resCategorySchema";
|
||||
export * from "./resCategorySchemaCategory";
|
||||
export * from "./resCategorySchemaLabel";
|
||||
export * from "./resCategorySchemaMsg";
|
||||
export * from "./resCrawlerStats";
|
||||
export * from "./resCrawlerStatsDateFrom";
|
||||
export * from "./resCrawlerStatsDateTo";
|
||||
export * from "./resCrawlerStatsMsg";
|
||||
export * from "./resExtractFacts";
|
||||
export * from "./resExtractFactsMsg";
|
||||
export * from "./resExtractedFact";
|
||||
@@ -391,6 +410,7 @@ export * from "./searchPlacesPublicParams";
|
||||
export * from "./showcaseItem";
|
||||
export * from "./showcaseItemRegion";
|
||||
export * from "./showcaseItemThumbnailUrl";
|
||||
export * from "./siteCrawlerStatsParams";
|
||||
export * from "./siteData";
|
||||
export * from "./siteDataCurrentVersionId";
|
||||
export * from "./siteDataDomain";
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { ErrorInfo } from "./errorInfo";
|
||||
import type { ResCrawlerStatsMsg } from "./resCrawlerStatsMsg";
|
||||
import type { ResCrawlerStatsDateFrom } from "./resCrawlerStatsDateFrom";
|
||||
import type { ResCrawlerStatsDateTo } from "./resCrawlerStatsDateTo";
|
||||
import type { CrawlerSummary } from "./crawlerSummary";
|
||||
import type { CrawlerDaily } from "./crawlerDaily";
|
||||
import type { CrawlerBotRow } from "./crawlerBotRow";
|
||||
import type { CrawlerSiteRow } from "./crawlerSiteRow";
|
||||
import type { CrawlerRootRow } from "./crawlerRootRow";
|
||||
import type { CrawlerUaRow } from "./crawlerUaRow";
|
||||
import type { CrawlerPathRow } from "./crawlerPathRow";
|
||||
import type { CrawlerHitRow } from "./crawlerHitRow";
|
||||
|
||||
/**
|
||||
* 전체(sites·root_files·others)와 사이트별(pages·recent)이 같은 모델을 쓴다 — 해당 없는 칸은 비어 있다.
|
||||
*/
|
||||
export interface ResCrawlerStats {
|
||||
result?: ErrorInfo;
|
||||
msg?: ResCrawlerStatsMsg;
|
||||
date_from?: ResCrawlerStatsDateFrom;
|
||||
date_to?: ResCrawlerStatsDateTo;
|
||||
summary?: CrawlerSummary;
|
||||
daily?: CrawlerDaily[];
|
||||
bots?: CrawlerBotRow[];
|
||||
sites?: CrawlerSiteRow[];
|
||||
root_files?: CrawlerRootRow[];
|
||||
others?: CrawlerUaRow[];
|
||||
pages?: CrawlerPathRow[];
|
||||
recent?: CrawlerHitRow[];
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ResCrawlerStatsDateFrom = string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ResCrawlerStatsDateTo = string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ResCrawlerStatsMsg = string | null;
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type SiteCrawlerStatsParams = {
|
||||
/**
|
||||
* KST 날짜, 기본 to-6일
|
||||
*/
|
||||
from?: string | null;
|
||||
/**
|
||||
* KST 날짜, 기본 오늘
|
||||
*/
|
||||
to?: string | null;
|
||||
};
|
||||
@@ -18,11 +18,14 @@ import type {
|
||||
} from "@tanstack/react-query";
|
||||
|
||||
import type {
|
||||
CrawlerStatsParams,
|
||||
HTTPValidationError,
|
||||
ListSitesParams,
|
||||
ListUsersParams,
|
||||
ResCrawlerStats,
|
||||
ResOpsSites,
|
||||
ResOpsUsers,
|
||||
SiteCrawlerStatsParams,
|
||||
} from ".././model";
|
||||
|
||||
import { customFetch } from "../../mutator/custom-fetch";
|
||||
@@ -312,3 +315,334 @@ export function useListUsers<
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary 전체 크롤러 통계(개발자 전용)
|
||||
*/
|
||||
export const crawlerStats = (
|
||||
params?: CrawlerStatsParams,
|
||||
options?: SecondParameter<typeof customFetch>,
|
||||
signal?: AbortSignal,
|
||||
) => {
|
||||
return customFetch<ResCrawlerStats>(
|
||||
{ url: `/v1/ops/stats/crawlers`, method: "GET", params, signal },
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
export const getCrawlerStatsQueryKey = (params?: CrawlerStatsParams) => {
|
||||
return [`/v1/ops/stats/crawlers`, ...(params ? [params] : [])] as const;
|
||||
};
|
||||
|
||||
export const getCrawlerStatsQueryOptions = <
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params?: CrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
) => {
|
||||
const { query: queryOptions, request: requestOptions } = options ?? {};
|
||||
|
||||
const queryKey = queryOptions?.queryKey ?? getCrawlerStatsQueryKey(params);
|
||||
|
||||
const queryFn: QueryFunction<Awaited<ReturnType<typeof crawlerStats>>> = ({
|
||||
signal,
|
||||
}) => crawlerStats(params, requestOptions, signal);
|
||||
|
||||
return { queryKey, queryFn, ...queryOptions } as UseQueryOptions<
|
||||
Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
};
|
||||
|
||||
export type CrawlerStatsQueryResult = NonNullable<
|
||||
Awaited<ReturnType<typeof crawlerStats>>
|
||||
>;
|
||||
export type CrawlerStatsQueryError = HTTPValidationError;
|
||||
|
||||
export function useCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params: undefined | CrawlerStatsParams,
|
||||
options: {
|
||||
query: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
> &
|
||||
Pick<
|
||||
DefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof crawlerStats>>
|
||||
>,
|
||||
"initialData"
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): DefinedUseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
export function useCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params?: CrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
> &
|
||||
Pick<
|
||||
UndefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof crawlerStats>>
|
||||
>,
|
||||
"initialData"
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
export function useCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params?: CrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
/**
|
||||
* @summary 전체 크롤러 통계(개발자 전용)
|
||||
*/
|
||||
|
||||
export function useCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof crawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
params?: CrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<Awaited<ReturnType<typeof crawlerStats>>, TError, TData>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
} {
|
||||
const queryOptions = getCrawlerStatsQueryOptions(params, options);
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryResult<
|
||||
TData,
|
||||
TError
|
||||
> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
query.queryKey = queryOptions.queryKey;
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary 사이트별 크롤러 통계(개발자 전용)
|
||||
*/
|
||||
export const siteCrawlerStats = (
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: SecondParameter<typeof customFetch>,
|
||||
signal?: AbortSignal,
|
||||
) => {
|
||||
return customFetch<ResCrawlerStats>(
|
||||
{
|
||||
url: `/v1/ops/sites/${placeId}/stats/crawlers`,
|
||||
method: "GET",
|
||||
params,
|
||||
signal,
|
||||
},
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
export const getSiteCrawlerStatsQueryKey = (
|
||||
placeId?: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
) => {
|
||||
return [
|
||||
`/v1/ops/sites/${placeId}/stats/crawlers`,
|
||||
...(params ? [params] : []),
|
||||
] as const;
|
||||
};
|
||||
|
||||
export const getSiteCrawlerStatsQueryOptions = <
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
) => {
|
||||
const { query: queryOptions, request: requestOptions } = options ?? {};
|
||||
|
||||
const queryKey =
|
||||
queryOptions?.queryKey ?? getSiteCrawlerStatsQueryKey(placeId, params);
|
||||
|
||||
const queryFn: QueryFunction<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>
|
||||
> = ({ signal }) => siteCrawlerStats(placeId, params, requestOptions, signal);
|
||||
|
||||
return {
|
||||
queryKey,
|
||||
queryFn,
|
||||
enabled: !!placeId,
|
||||
...queryOptions,
|
||||
} as UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
};
|
||||
|
||||
export type SiteCrawlerStatsQueryResult = NonNullable<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>
|
||||
>;
|
||||
export type SiteCrawlerStatsQueryError = HTTPValidationError;
|
||||
|
||||
export function useSiteCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params: undefined | SiteCrawlerStatsParams,
|
||||
options: {
|
||||
query: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
> &
|
||||
Pick<
|
||||
DefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>
|
||||
>,
|
||||
"initialData"
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): DefinedUseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
export function useSiteCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
> &
|
||||
Pick<
|
||||
UndefinedInitialDataOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>
|
||||
>,
|
||||
"initialData"
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
export function useSiteCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
};
|
||||
/**
|
||||
* @summary 사이트별 크롤러 통계(개발자 전용)
|
||||
*/
|
||||
|
||||
export function useSiteCrawlerStats<
|
||||
TData = Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError = HTTPValidationError,
|
||||
>(
|
||||
placeId: string,
|
||||
params?: SiteCrawlerStatsParams,
|
||||
options?: {
|
||||
query?: Partial<
|
||||
UseQueryOptions<
|
||||
Awaited<ReturnType<typeof siteCrawlerStats>>,
|
||||
TError,
|
||||
TData
|
||||
>
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
},
|
||||
queryClient?: QueryClient,
|
||||
): UseQueryResult<TData, TError> & {
|
||||
queryKey: DataTag<QueryKey, TData, TError>;
|
||||
} {
|
||||
const queryOptions = getSiteCrawlerStatsQueryOptions(
|
||||
placeId,
|
||||
params,
|
||||
options,
|
||||
);
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryResult<
|
||||
TData,
|
||||
TError
|
||||
> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
query.queryKey = queryOptions.queryKey;
|
||||
|
||||
return query;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import {Bar, BarChart, CartesianGrid, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis} from 'recharts';
|
||||
import type {CrawlerDaily} from '@/api';
|
||||
import {PURPOSE_COLOR, PURPOSES, purposeLabel} from './labels';
|
||||
import {daysBetween} from './range';
|
||||
|
||||
// recharts 는 행 하나를 {day, search: n, training: n, …} 로 받는다.
|
||||
type Row = Record<string, string | number>;
|
||||
|
||||
function pivot(daily: CrawlerDaily[], from: string, to: string): Row[] {
|
||||
const rows = new Map<string, Row>(daysBetween(from, to).map((day) => [day, {day}]));
|
||||
for (const {day, purpose, hits} of daily) {
|
||||
const row = rows.get(day);
|
||||
if (row) row[purpose] = Number(row[purpose] ?? 0) + hits;
|
||||
}
|
||||
return [...rows.values()];
|
||||
}
|
||||
|
||||
/** recharts 를 이 파일에만 둔다 — CrawlerStatsPanel 이 lazy() 로 불러 사장님 화면 번들에 안 들어간다. */
|
||||
export default function CrawlerDailyChart({daily, from, to}: {daily: CrawlerDaily[]; from: string; to: string}) {
|
||||
return (
|
||||
<ResponsiveContainer width="100%" height={240}>
|
||||
<BarChart data={pivot(daily, from, to)} margin={{top: 8, right: 8, bottom: 0, left: 0}}>
|
||||
<CartesianGrid strokeDasharray="3 3" vertical={false} />
|
||||
<XAxis dataKey="day" tickFormatter={(day: string) => day.slice(5)} fontSize={11} />
|
||||
<YAxis allowDecimals={false} fontSize={11} width={32} />
|
||||
<Tooltip formatter={(value, name) => [value, purposeLabel(String(name))]} />
|
||||
<Legend formatter={(value) => purposeLabel(String(value))} wrapperStyle={{fontSize: 11}} />
|
||||
{PURPOSES.map((purpose) => (
|
||||
<Bar key={purpose} dataKey={purpose} stackId="hits" fill={PURPOSE_COLOR[purpose]} />
|
||||
))}
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
import {lazy, Suspense, type ReactNode} from 'react';
|
||||
import {Link} from 'react-router';
|
||||
import {Bot, Loader2} from 'lucide-react';
|
||||
import type {ResCrawlerStats} from '@/api';
|
||||
import {EmptyState} from '@/components/layout/AppShell';
|
||||
import {Badge} from '@/components/ui/badge';
|
||||
import {Card, CardContent, CardHeader, CardTitle} from '@/components/ui/card';
|
||||
import {cn} from '@/lib/utils';
|
||||
import {formatKst, purposeLabel} from './labels';
|
||||
import {RANGE_DAYS, type RangeDays} from './range';
|
||||
|
||||
const CrawlerDailyChart = lazy(() => import('./CrawlerDailyChart'));
|
||||
|
||||
export function RangeTabs({value, onChange}: {value: RangeDays; onChange: (days: RangeDays) => void}) {
|
||||
return (
|
||||
<div className="flex gap-1.5">
|
||||
{RANGE_DAYS.map((days) => (
|
||||
<button
|
||||
key={days}
|
||||
type="button"
|
||||
onClick={() => onChange(days)}
|
||||
className={cn(
|
||||
'h-8 cursor-pointer rounded-md border px-3 text-xs font-medium transition-colors',
|
||||
value === days ? 'border-foreground bg-foreground text-background' : 'border-border hover:bg-muted',
|
||||
)}
|
||||
>
|
||||
최근 {days}일
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Stat({label, value}: {label: string; value: ReactNode}) {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className="pt-4">
|
||||
<p className="text-xs text-muted-foreground">{label}</p>
|
||||
<p className="mt-1 text-xl font-semibold tabular-nums">{value}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function Section({title, children}: {title: string; children: ReactNode}) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{title}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>{children}</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function Table({head, rows}: {head: string[]; rows: ReactNode[][]}) {
|
||||
if (rows.length === 0) return <p className="text-xs text-muted-foreground">기록이 없습니다.</p>;
|
||||
return (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-xs">
|
||||
<thead>
|
||||
<tr className="border-b border-border text-left text-muted-foreground">
|
||||
{head.map((h) => (
|
||||
<th key={h} className="py-2 pr-3 font-medium">
|
||||
{h}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((cells, i) => (
|
||||
<tr key={i} className="border-b border-border last:border-0">
|
||||
{cells.map((cell, j) => (
|
||||
<td key={j} className="py-2 pr-3 align-top">
|
||||
{cell}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 크롤링 탭 본문. scope 에 따라 아래쪽 표가 갈린다 — 전체: 사이트 순위·공용 파일·기타 UA / 사이트: 페이지·최근 기록. */
|
||||
export function CrawlerStatsPanel({data, scope}: {data: ResCrawlerStats; scope: 'overall' | 'site'}) {
|
||||
const summary = data.summary;
|
||||
if (!summary?.total) {
|
||||
return <EmptyState icon={Bot} title="아직 크롤링 기록이 없습니다" description="선택한 기간에 들어온 봇 요청이 없습니다." />;
|
||||
}
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-3 md:grid-cols-4">
|
||||
<Stat label="총 요청" value={summary.total ?? 0} />
|
||||
<Stat label="AI 봇 요청" value={summary.ai ?? 0} />
|
||||
<Stat label="봇 종류" value={summary.bots ?? 0} />
|
||||
<Stat label="마지막 크롤링" value={<span className="text-base">{formatKst(summary.last_at)}</span>} />
|
||||
</div>
|
||||
|
||||
<Section title="일별 요청 (용도별)">
|
||||
{data.date_from && data.date_to && (
|
||||
<Suspense fallback={<Loader2 className="mx-auto size-5 animate-spin text-muted-foreground" />}>
|
||||
<CrawlerDailyChart daily={data.daily ?? []} from={data.date_from} to={data.date_to} />
|
||||
</Suspense>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title="봇별">
|
||||
<Table
|
||||
head={['봇', '회사', '용도', '요청', '마지막']}
|
||||
rows={(data.bots ?? []).map((b) => [
|
||||
b.bot,
|
||||
b.vendor ?? '—',
|
||||
<Badge key="p" variant="outline">
|
||||
{purposeLabel(b.purpose)}
|
||||
</Badge>,
|
||||
b.hits,
|
||||
formatKst(b.last_at),
|
||||
])}
|
||||
/>
|
||||
</Section>
|
||||
|
||||
{scope === 'overall' ? (
|
||||
<>
|
||||
<Section title="크롤링이 많은 사이트">
|
||||
<Table
|
||||
head={['사이트', '요청', 'AI 봇', '마지막']}
|
||||
rows={(data.sites ?? []).map((s) => [
|
||||
<Link key="n" to={`/ops/sites/${s.place_id}/stats`} className="font-medium hover:underline">
|
||||
{s.name}
|
||||
</Link>,
|
||||
s.hits,
|
||||
s.ai_hits,
|
||||
formatKst(s.last_at),
|
||||
])}
|
||||
/>
|
||||
</Section>
|
||||
<Section title="robots.txt · sitemap.xml">
|
||||
<Table
|
||||
head={['파일', '봇', '용도', '요청', '마지막']}
|
||||
rows={(data.root_files ?? []).map((r) => [
|
||||
r.kind === 'robots' ? 'robots.txt' : 'sitemap.xml',
|
||||
r.bot ?? '기타',
|
||||
purposeLabel(r.purpose),
|
||||
r.hits,
|
||||
formatKst(r.last_at),
|
||||
])}
|
||||
/>
|
||||
</Section>
|
||||
<Section title="목록 밖 봇 (기타) — 자주 보이면 목록에 올린다">
|
||||
<Table
|
||||
head={['User-Agent', '요청', '마지막']}
|
||||
rows={(data.others ?? []).map((o) => [
|
||||
<span key="ua" className="font-mono text-[11px] break-all">
|
||||
{o.user_agent}
|
||||
</span>,
|
||||
o.hits,
|
||||
formatKst(o.last_at),
|
||||
])}
|
||||
/>
|
||||
</Section>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Section title="많이 읽힌 페이지">
|
||||
<Table
|
||||
head={['경로', '요청', '마지막']}
|
||||
rows={(data.pages ?? []).map((p) => [
|
||||
<span key="p" className="break-all">
|
||||
{p.path}
|
||||
</span>,
|
||||
p.hits,
|
||||
formatKst(p.last_at),
|
||||
])}
|
||||
/>
|
||||
</Section>
|
||||
<Section title="최근 크롤링 50건">
|
||||
<Table
|
||||
head={['시각', '봇', '용도', '경로']}
|
||||
rows={(data.recent ?? []).map((r) => [
|
||||
formatKst(r.created_at),
|
||||
r.bot ?? '기타',
|
||||
purposeLabel(r.purpose),
|
||||
<span key="p" className="break-all">
|
||||
{r.path}
|
||||
</span>,
|
||||
])}
|
||||
/>
|
||||
</Section>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import {useState} from 'react';
|
||||
import {keepPreviousData} from '@tanstack/react-query';
|
||||
import {Loader2} from 'lucide-react';
|
||||
import {useCrawlerStats} from '@/api';
|
||||
import {EmptyState} from '@/components/layout/AppShell';
|
||||
import {CrawlerStatsPanel, RangeTabs} from './CrawlerStatsPanel';
|
||||
import {rangeParams, type RangeDays} from './range';
|
||||
|
||||
export function OverallCrawlerStats() {
|
||||
const [days, setDays] = useState<RangeDays>(7);
|
||||
const {data, isLoading, isError, error} = useCrawlerStats(rangeParams(days), {
|
||||
query: {placeholderData: keepPreviousData},
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-sm font-semibold">크롤링 (전체 사이트)</h2>
|
||||
<RangeTabs value={days} onChange={setDays} />
|
||||
</div>
|
||||
{isLoading && (
|
||||
<div className="flex justify-center py-20 text-muted-foreground">
|
||||
<Loader2 className="size-5 animate-spin" />
|
||||
</div>
|
||||
)}
|
||||
{(isError || data?.result?.success === false) && (
|
||||
<EmptyState
|
||||
title="통계를 불러오지 못했습니다"
|
||||
description={(error as Error)?.message ?? data?.result?.desc ?? '잠시 후 다시 시도해 주세요.'}
|
||||
/>
|
||||
)}
|
||||
{data?.result?.success && <CrawlerStatsPanel data={data} scope="overall" />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import {cn} from '@/lib/utils';
|
||||
|
||||
export type SitesTab = 'list' | 'stats';
|
||||
|
||||
const TABS: ReadonlyArray<readonly [SitesTab, string]> = [
|
||||
['list', '목록'],
|
||||
['stats', '전체 통계'],
|
||||
];
|
||||
|
||||
/** 사이트관리 상단 탭 — 현재 탭은 URL(?tab=)이 들고 있다. */
|
||||
export function SitesTabs({tab, onChange}: {tab: SitesTab; onChange: (tab: SitesTab) => void}) {
|
||||
return (
|
||||
<div className="mb-4 flex gap-4 border-b border-border text-sm">
|
||||
{TABS.map(([value, label]) => (
|
||||
<button
|
||||
key={value}
|
||||
type="button"
|
||||
onClick={() => onChange(value)}
|
||||
className={cn(
|
||||
'-mb-px cursor-pointer border-b-2 px-1 pb-2 font-medium transition-colors',
|
||||
tab === value
|
||||
? 'border-foreground text-foreground'
|
||||
: 'border-transparent text-muted-foreground hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/** 용도 순서 — 누적 막대의 아래→위, 표의 정렬 기준. AI 쪽을 아래에 깐다(이 화면이 보려는 것). */
|
||||
export const PURPOSES = ['search', 'user-fetch', 'training', 'search-engine', 'other'] as const;
|
||||
export type Purpose = (typeof PURPOSES)[number];
|
||||
|
||||
export const PURPOSE_LABEL: Record<Purpose, string> = {
|
||||
search: 'AI 검색 색인',
|
||||
'user-fetch': 'AI 실시간 조회',
|
||||
training: 'AI 학습',
|
||||
'search-engine': '검색엔진',
|
||||
other: '기타',
|
||||
};
|
||||
|
||||
export const PURPOSE_COLOR: Record<Purpose, string> = {
|
||||
search: '#2563eb',
|
||||
'user-fetch': '#7c3aed',
|
||||
training: '#0d9488',
|
||||
'search-engine': '#f59e0b',
|
||||
other: '#9ca3af',
|
||||
};
|
||||
|
||||
export function purposeLabel(value: string): string {
|
||||
return PURPOSE_LABEL[value as Purpose] ?? value;
|
||||
}
|
||||
|
||||
/** 서버 시각(UTC ISO)을 KST 로 읽는다 — 운영자가 한국에 있지 않아도 같은 숫자를 본다. */
|
||||
export function formatKst(iso?: string | null): string {
|
||||
if (!iso) return '—';
|
||||
return new Date(iso).toLocaleString('ko-KR', {
|
||||
timeZone: 'Asia/Seoul',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
export const RANGE_DAYS = [7, 30, 90] as const;
|
||||
export type RangeDays = (typeof RANGE_DAYS)[number];
|
||||
|
||||
const DAY_MS = 86_400_000;
|
||||
const KST_OFFSET_MS = 9 * 3_600_000;
|
||||
|
||||
/** 서버가 KST 날짜로 자르므로 KST 오늘을 기준으로 만든다(브라우저 시간대와 무관하게). */
|
||||
export function rangeParams(days: RangeDays): {from: string; to: string} {
|
||||
const kstNow = Date.now() + KST_OFFSET_MS;
|
||||
const to = new Date(kstNow).toISOString().slice(0, 10);
|
||||
const from = new Date(kstNow - (days - 1) * DAY_MS).toISOString().slice(0, 10);
|
||||
return {from, to};
|
||||
}
|
||||
|
||||
/** from~to 의 모든 날짜 — 요청이 없던 날도 막대 자리를 비워 둬야 추이가 왜곡되지 않는다. */
|
||||
export function daysBetween(from: string, to: string): string[] {
|
||||
const out: string[] = [];
|
||||
for (let t = Date.parse(`${from}T00:00:00Z`); t <= Date.parse(`${to}T00:00:00Z`); t += DAY_MS) {
|
||||
out.push(new Date(t).toISOString().slice(0, 10));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import {useState} from 'react';
|
||||
import {Link, Navigate, useParams} from 'react-router';
|
||||
import {keepPreviousData} from '@tanstack/react-query';
|
||||
import {ArrowLeft, Loader2} from 'lucide-react';
|
||||
import {UserRole, useSiteCrawlerStats} from '@/api';
|
||||
import {AppShell, EmptyState, PageContainer} from '@/components/layout/AppShell';
|
||||
import {CrawlerStatsPanel, RangeTabs} from '@/features/ops-stats/CrawlerStatsPanel';
|
||||
import {rangeParams, type RangeDays} from '@/features/ops-stats/range';
|
||||
import {useAuthStore} from '@/stores/auth';
|
||||
|
||||
/** 사이트별 통계 — 개발자(DEVELOPER) 전용. 2단계에서 "방문" 탭이 붙는다. */
|
||||
export function OpsSiteStatsPage() {
|
||||
const {placeId = ''} = useParams();
|
||||
const isRestoring = useAuthStore((s) => s.isRestoring);
|
||||
const role = useAuthStore((s) => s.user?.role);
|
||||
const [days, setDays] = useState<RangeDays>(7);
|
||||
// enabled: OpsSitesPage 와 같은 이유 — role 확정 전 요청이 403 토스트를 먼저 띄운다.
|
||||
const {data, isLoading, isError, error} = useSiteCrawlerStats(placeId, rangeParams(days), {
|
||||
query: {placeholderData: keepPreviousData, enabled: role === UserRole.DEVELOPER && !!placeId},
|
||||
});
|
||||
|
||||
if (isRestoring) return null;
|
||||
if (role !== UserRole.DEVELOPER) return <Navigate to="/sites" replace />;
|
||||
|
||||
return (
|
||||
<AppShell>
|
||||
<PageContainer
|
||||
title="사이트 통계"
|
||||
description="이 사이트에 들어온 봇 요청입니다. 자칭 크롤러(UA 기준)이며 IP 대역으로 진위를 확인하지 않습니다."
|
||||
actions={
|
||||
<Link
|
||||
to="/ops/sites"
|
||||
className="inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium transition-colors hover:bg-muted"
|
||||
>
|
||||
<ArrowLeft className="size-3.5" />
|
||||
사이트관리
|
||||
</Link>
|
||||
}
|
||||
>
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<h2 className="text-sm font-semibold">크롤링</h2>
|
||||
<RangeTabs value={days} onChange={setDays} />
|
||||
</div>
|
||||
{isLoading && (
|
||||
<div className="flex justify-center py-20 text-muted-foreground">
|
||||
<Loader2 className="size-5 animate-spin" />
|
||||
</div>
|
||||
)}
|
||||
{(isError || data?.result?.success === false) && (
|
||||
<EmptyState
|
||||
title="통계를 불러오지 못했습니다"
|
||||
description={(error as Error)?.message ?? data?.result?.desc ?? '잠시 후 다시 시도해 주세요.'}
|
||||
/>
|
||||
)}
|
||||
{data?.result?.success && <CrawlerStatsPanel data={data} scope="site" />}
|
||||
</PageContainer>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
// 라우트 모듈은 default export 를 요구한다(routes.ts 가 이 파일을 가리킨다).
|
||||
export default OpsSiteStatsPage;
|
||||
@@ -1,13 +1,15 @@
|
||||
import {useState} from 'react';
|
||||
import {Link, Navigate} from 'react-router';
|
||||
import {Link, Navigate, useSearchParams} from 'react-router';
|
||||
import {keepPreviousData} from '@tanstack/react-query';
|
||||
import {Building2, ChevronLeft, ChevronRight, ExternalLink, Loader2, Newspaper, Pencil, Search, Trash2, X} from 'lucide-react';
|
||||
import {BarChart3, Building2, ChevronLeft, ChevronRight, ExternalLink, Loader2, Newspaper, Pencil, Search, Trash2, X} from 'lucide-react';
|
||||
import {PlaceCategory, publishUrlString, SiteStatus} from '@o2o/shared';
|
||||
import {changeStatus, deletePlace, PublishAction, UserRole, useListSites, type OpsSiteData} from '@/api';
|
||||
import {AppShell, EmptyState, PageContainer} from '@/components/layout/AppShell';
|
||||
import {Badge} from '@/components/ui/badge';
|
||||
import {Button} from '@/components/ui/button';
|
||||
import {Input} from '@/components/ui/input';
|
||||
import {OverallCrawlerStats} from '@/features/ops-stats/OverallCrawlerStats';
|
||||
import {SitesTabs, type SitesTab} from '@/features/ops-stats/SitesTabs';
|
||||
import {notify, notifyApiError} from '@/lib/notify';
|
||||
import {PUBLISH_HOST} from '@/lib/site';
|
||||
import {cn} from '@/lib/utils';
|
||||
@@ -45,11 +47,15 @@ export function OpsSitesPage() {
|
||||
const [search, setSearch] = useState('');
|
||||
const [category, setCategory] = useState<number | null>(null);
|
||||
const [busyId, setBusyId] = useState<string | null>(null);
|
||||
// 탭을 URL 에 둔다 — 사이트별 통계에서 뒤로 오면 보던 탭으로 돌아온다.
|
||||
const [params, setParams] = useSearchParams();
|
||||
const tab: SitesTab = params.get('tab') === 'stats' ? 'stats' : 'list';
|
||||
const changeTab = (next: SitesTab) => setParams(next === 'list' ? {} : {tab: next});
|
||||
const size = 20;
|
||||
// enabled: role 이 확정되기 전엔 요청하지 않는다 — 어차피 백엔드가 403 으로 막지만, 사장님 화면에서 실패 토스트가 먼저 뜨는 것과 새로고침 때 잠깐의 오탐 리다이렉트를 막는다.
|
||||
const {data, isLoading, isError, error, refetch} = useListSites(
|
||||
{page, size, search: search || undefined, category: category ?? undefined},
|
||||
{query: {placeholderData: keepPreviousData, enabled: role === UserRole.DEVELOPER}},
|
||||
{query: {placeholderData: keepPreviousData, enabled: role === UserRole.DEVELOPER && tab === 'list'}},
|
||||
);
|
||||
|
||||
// RequireAuth 와 같은 이유 — 복구가 끝나기 전에 판단하면 새로고침마다 리다이렉트가 한 번 번쩍인다.
|
||||
@@ -85,6 +91,17 @@ export function OpsSitesPage() {
|
||||
if (isRestoring) return null;
|
||||
if (role !== UserRole.DEVELOPER) return <Navigate to="/sites" replace />;
|
||||
|
||||
if (tab === 'stats') {
|
||||
return (
|
||||
<AppShell>
|
||||
<PageContainer title="사이트관리" description="전 계정 사이트 발행 현황입니다. 회사 스코프 없이 전부 보입니다.">
|
||||
<SitesTabs tab={tab} onChange={changeTab} />
|
||||
<OverallCrawlerStats />
|
||||
</PageContainer>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
const rows = data?.sites ?? [];
|
||||
const total = data?.total ?? 0;
|
||||
const lastPage = Math.max(1, Math.ceil(total / size));
|
||||
@@ -121,6 +138,7 @@ export function OpsSitesPage() {
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<SitesTabs tab={tab} onChange={changeTab} />
|
||||
<div className="mb-3 flex flex-wrap gap-1.5">
|
||||
{[null, ...Object.keys(CATEGORY_LABEL).map(Number)].map((value) => (
|
||||
<button
|
||||
@@ -193,6 +211,13 @@ export function OpsSitesPage() {
|
||||
<Newspaper className="size-3.5" />
|
||||
미니블로그
|
||||
</Link>
|
||||
<Link
|
||||
to={`/ops/sites/${row.place_id}/stats`}
|
||||
className="inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium transition-colors hover:bg-muted"
|
||||
>
|
||||
<BarChart3 className="size-3.5" />
|
||||
통계
|
||||
</Link>
|
||||
{url ? (
|
||||
<a
|
||||
href={url}
|
||||
|
||||
@@ -23,6 +23,7 @@ export default [
|
||||
// "내 사이트" 카드의 관리 메뉴에서 온다(?placeId= 로 어느 사이트인지 받는다) — 사장님 여럿이 사이트 여럿을 가질 수 있어 전역 메뉴 하나로는 못 고른다.
|
||||
route('blog', 'pages/BlogPostsPage.tsx'),
|
||||
route('ops/sites', 'pages/OpsSitesPage.tsx'),
|
||||
route('ops/sites/:placeId/stats', 'pages/OpsSiteStatsPage.tsx'),
|
||||
route('ops/users', 'pages/OpsUsersPage.tsx'),
|
||||
]),
|
||||
|
||||
|
||||
Reference in new issue
Block a user