refactor: polish analytics and gallery chrome
This commit is contained in:
parent
0861a0d87e
commit
180ee864d9
@ -1445,6 +1445,8 @@ type RuntimeModelCandidate = RuntimeModelMeta & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const analyticsNumberFormatter = new Intl.NumberFormat("zh-CN");
|
const analyticsNumberFormatter = new Intl.NumberFormat("zh-CN");
|
||||||
|
const UUID_LIKE_REGEX =
|
||||||
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||||
|
|
||||||
function scoreRuntimeModelCandidate(candidate: RuntimeModelCandidate) {
|
function scoreRuntimeModelCandidate(candidate: RuntimeModelCandidate) {
|
||||||
return (
|
return (
|
||||||
@ -1511,6 +1513,17 @@ function formatAnalyticsMonthLabel(value: string) {
|
|||||||
return `${year} 年 ${month} 月`;
|
return `${year} 年 ${month} 月`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatAnalyticsModelLabel(
|
||||||
|
meta: RuntimeModelMeta | null | undefined,
|
||||||
|
modelId: string | null | undefined
|
||||||
|
) {
|
||||||
|
if (meta?.modelName) return meta.modelName;
|
||||||
|
const normalizedModelId = String(modelId || "").trim();
|
||||||
|
if (!normalizedModelId) return "未知模型";
|
||||||
|
if (UUID_LIKE_REGEX.test(normalizedModelId)) return "未映射模型";
|
||||||
|
return normalizedModelId;
|
||||||
|
}
|
||||||
|
|
||||||
const AVAILABLE_TOOLS = [
|
const AVAILABLE_TOOLS = [
|
||||||
{ name: "getWeather", description: "获取天气信息" },
|
{ name: "getWeather", description: "获取天气信息" },
|
||||||
{ name: "createDocument", description: "创建文档" },
|
{ name: "createDocument", description: "创建文档" },
|
||||||
@ -1851,7 +1864,7 @@ export function AdminSettingsClient() {
|
|||||||
|
|
||||||
(modelsData?.models || []).forEach((model) => {
|
(modelsData?.models || []).forEach((model) => {
|
||||||
const providerMeta = providerMetaById.get(model.providerId);
|
const providerMeta = providerMetaById.get(model.providerId);
|
||||||
candidates.push({
|
const sharedMeta = {
|
||||||
modelId: model.modelId,
|
modelId: model.modelId,
|
||||||
modelName: model.displayName,
|
modelName: model.displayName,
|
||||||
providerName: providerMeta?.providerName || null,
|
providerName: providerMeta?.providerName || null,
|
||||||
@ -1861,6 +1874,11 @@ export function AdminSettingsClient() {
|
|||||||
isDefault: model.isDefault,
|
isDefault: model.isDefault,
|
||||||
isSubModel: model.isSubModel,
|
isSubModel: model.isSubModel,
|
||||||
sortOrder: model.sortOrder,
|
sortOrder: model.sortOrder,
|
||||||
|
};
|
||||||
|
candidates.push(sharedMeta);
|
||||||
|
candidates.push({
|
||||||
|
...sharedMeta,
|
||||||
|
modelId: model.id,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -8821,12 +8839,13 @@ export function AdminSettingsClient() {
|
|||||||
<div>
|
<div>
|
||||||
<Label className="text-muted-foreground">模型</Label>
|
<Label className="text-muted-foreground">模型</Label>
|
||||||
<p>
|
<p>
|
||||||
{resolveRuntimeModelMeta(
|
{formatAnalyticsModelLabel(
|
||||||
|
resolveRuntimeModelMeta(
|
||||||
runtimeModelMetaById,
|
runtimeModelMetaById,
|
||||||
selectedImage.modelId
|
selectedImage.modelId
|
||||||
).modelName ||
|
),
|
||||||
selectedImage.modelId ||
|
selectedImage.modelId
|
||||||
"未知"}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{selectedImage.recordType !== "video" ? (
|
{selectedImage.recordType !== "video" ? (
|
||||||
@ -8967,7 +8986,6 @@ export function AdminSettingsClient() {
|
|||||||
|
|
||||||
{/* 🆕 数据分析 */}
|
{/* 🆕 数据分析 */}
|
||||||
<TabsContent className="mt-6 space-y-4" value="analytics">
|
<TabsContent className="mt-6 space-y-4" value="analytics">
|
||||||
<div className="grid gap-4 xl:grid-cols-[1.35fr_0.65fr]">
|
|
||||||
<Card className="overflow-hidden border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.28)]">
|
<Card className="overflow-hidden border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.28)]">
|
||||||
<CardHeader className="border-b border-zinc-200/70 bg-gradient-to-r from-zinc-50 via-white to-lime-50/40">
|
<CardHeader className="border-b border-zinc-200/70 bg-gradient-to-r from-zinc-50 via-white to-lime-50/40">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
@ -8980,10 +8998,7 @@ export function AdminSettingsClient() {
|
|||||||
生成与运营总览
|
生成与运营总览
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
当前面板聚合最近 30 天趋势、当日峰值时段和模型使用分布。
|
统一展示生成规模、活跃用户、趋势波动、模型分布和分辨率结构。
|
||||||
{selectedDate
|
|
||||||
? ` 当前已锁定 ${selectedDate} 的小时分布。`
|
|
||||||
: " 点击趋势柱可联动查看某一天的小时明细。"}
|
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
<div className="inline-flex items-center gap-2 rounded-full border border-zinc-200 bg-white/85 px-3 py-1.5 text-xs text-zinc-600 shadow-sm">
|
<div className="inline-flex items-center gap-2 rounded-full border border-zinc-200 bg-white/85 px-3 py-1.5 text-xs text-zinc-600 shadow-sm">
|
||||||
@ -9038,12 +9053,13 @@ export function AdminSettingsClient() {
|
|||||||
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
||||||
filters & pulse
|
filters & pulse
|
||||||
</div>
|
</div>
|
||||||
<CardTitle className="text-lg">时间筛选与月度脉冲</CardTitle>
|
<CardTitle className="text-lg">统计筛选与核心信号</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
用月份控制本月指标卡,并通过日期联动小时分布。
|
保留月份筛选,同时把高峰时段、领先模型和最近月度走势铺满在同一块工作区里。
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-4">
|
<CardContent className="space-y-4">
|
||||||
|
<div className="grid gap-3 md:grid-cols-2 xl:grid-cols-4">
|
||||||
<div className="rounded-2xl border border-zinc-200/70 bg-zinc-50/80 p-4">
|
<div className="rounded-2xl border border-zinc-200/70 bg-zinc-50/80 p-4">
|
||||||
<Label className="text-[11px] uppercase tracking-[0.18em] text-muted-foreground">
|
<Label className="text-[11px] uppercase tracking-[0.18em] text-muted-foreground">
|
||||||
统计月份
|
统计月份
|
||||||
@ -9054,9 +9070,18 @@ export function AdminSettingsClient() {
|
|||||||
type="month"
|
type="month"
|
||||||
value={selectedMonth}
|
value={selectedMonth}
|
||||||
/>
|
/>
|
||||||
|
{selectedDate ? (
|
||||||
|
<Button
|
||||||
|
className="mt-3 h-8 rounded-full px-3 text-xs"
|
||||||
|
onClick={() => setSelectedDate(null)}
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
清除日期筛选
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-1">
|
|
||||||
<div className="rounded-2xl border border-zinc-200/70 bg-white p-4">
|
<div className="rounded-2xl border border-zinc-200/70 bg-white p-4">
|
||||||
<div className="flex items-center gap-2 text-zinc-900 text-sm">
|
<div className="flex items-center gap-2 text-zinc-900 text-sm">
|
||||||
<Clock className="h-4 w-4" />
|
<Clock className="h-4 w-4" />
|
||||||
@ -9080,12 +9105,13 @@ export function AdminSettingsClient() {
|
|||||||
领先模型
|
领先模型
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2 max-w-full truncate font-semibold text-xl">
|
<div className="mt-2 max-w-full truncate font-semibold text-xl">
|
||||||
{resolveRuntimeModelMeta(
|
{formatAnalyticsModelLabel(
|
||||||
|
resolveRuntimeModelMeta(
|
||||||
runtimeModelMetaById,
|
runtimeModelMetaById,
|
||||||
analyticsData?.modelDetailStats?.[0]?.modelId || null
|
analyticsData?.modelDetailStats?.[0]?.modelId || null
|
||||||
).modelName ||
|
),
|
||||||
analyticsData?.modelDetailStats?.[0]?.modelId ||
|
analyticsData?.modelDetailStats?.[0]?.modelId || null
|
||||||
"暂无"}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-1 text-xs text-zinc-400">
|
<div className="mt-1 text-xs text-zinc-400">
|
||||||
{analyticsData?.modelDetailStats?.[0]
|
{analyticsData?.modelDetailStats?.[0]
|
||||||
@ -9095,59 +9121,42 @@ export function AdminSettingsClient() {
|
|||||||
: "还没有模型统计结果"}
|
: "还没有模型统计结果"}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="rounded-2xl border border-zinc-200/70 bg-white p-4">
|
||||||
<div className="text-[11px] uppercase tracking-[0.18em] text-muted-foreground">
|
<div className="text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
|
||||||
recent months
|
recent months
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-2 gap-2">
|
<div className="mt-3 grid grid-cols-3 gap-2 text-center">
|
||||||
{analyticsRecentMonths.map((stat) => (
|
{analyticsRecentMonths.slice(-3).map((stat) => (
|
||||||
<div
|
<div
|
||||||
className="rounded-2xl border border-zinc-200/70 bg-white px-3 py-2"
|
className="rounded-xl border border-zinc-200/70 bg-zinc-50/80 px-2 py-2"
|
||||||
key={stat.month}
|
key={stat.month}
|
||||||
>
|
>
|
||||||
<div className="text-[11px] text-muted-foreground">
|
<div className="text-[11px] text-muted-foreground">
|
||||||
{stat.month}
|
{stat.month.slice(5)}
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-1 font-semibold text-base text-zinc-950">
|
<div className="mt-1 font-semibold text-sm text-zinc-950">
|
||||||
{formatAnalyticsNumber(stat.count)}
|
{formatAnalyticsNumber(stat.count)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid gap-4 xl:grid-cols-[1.3fr_0.7fr]">
|
|
||||||
<Card className="border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.24)]">
|
<Card className="border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.24)]">
|
||||||
<CardHeader className="flex flex-col gap-3 border-b border-zinc-200/70 pb-4 md:flex-row md:items-center md:justify-between">
|
<CardHeader className="pb-4">
|
||||||
<div>
|
|
||||||
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
||||||
throughput
|
throughput
|
||||||
</div>
|
</div>
|
||||||
<CardTitle className="mt-1 text-lg">生成节奏</CardTitle>
|
<CardTitle className="text-lg">近 30 天生成趋势</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
左侧看最近 30 天总量,右侧看
|
点击柱体可联动下方小时分布,所有趋势模块都按全宽铺排展示。
|
||||||
{selectedDate ? ` ${selectedDate} ` : "当前选择日期 "}
|
|
||||||
的小时分布。
|
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</div>
|
|
||||||
{selectedDate ? (
|
|
||||||
<Button
|
|
||||||
className="h-8 rounded-full px-3 text-xs"
|
|
||||||
onClick={() => setSelectedDate(null)}
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
>
|
|
||||||
清除日期筛选
|
|
||||||
</Button>
|
|
||||||
) : null}
|
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="grid gap-6 pt-6 md:grid-cols-[1.3fr_0.85fr]">
|
<CardContent className="space-y-3">
|
||||||
<div className="space-y-3">
|
|
||||||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
||||||
<span>近 30 天生成量</span>
|
<span>近 30 天生成量</span>
|
||||||
<span>点击柱体联动小时分布</span>
|
<span>点击柱体联动小时分布</span>
|
||||||
@ -9202,11 +9211,24 @@ export function AdminSettingsClient() {
|
|||||||
<span>{analyticsData?.dailyStats?.[0]?.date || "--"}</span>
|
<span>{analyticsData?.dailyStats?.[0]?.date || "--"}</span>
|
||||||
<span>{analyticsData?.dailyStats?.at(-1)?.date || "--"}</span>
|
<span>{analyticsData?.dailyStats?.at(-1)?.date || "--"}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
<div className="space-y-3">
|
<Card className="border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.24)]">
|
||||||
|
<CardHeader className="pb-4">
|
||||||
|
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
||||||
|
hourly load
|
||||||
|
</div>
|
||||||
|
<CardTitle className="text-lg">24 小时分布</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
{selectedDate
|
||||||
|
? `${selectedDate} 的生成高峰已锁定展示。`
|
||||||
|
: "默认展示最近样本的小时分布。"}
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-3">
|
||||||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
||||||
<span>24 小时分布</span>
|
<span>小时分布</span>
|
||||||
<span>{selectedDate || "默认最近样本"}</span>
|
<span>{selectedDate || "默认最近样本"}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex h-[240px] items-end gap-1 rounded-2xl border border-zinc-200/70 bg-white px-3 py-4">
|
<div className="flex h-[240px] items-end gap-1 rounded-2xl border border-zinc-200/70 bg-white px-3 py-4">
|
||||||
@ -9216,9 +9238,7 @@ export function AdminSettingsClient() {
|
|||||||
);
|
);
|
||||||
const count = stat?.count || 0;
|
const count = stat?.count || 0;
|
||||||
const maxCount = Math.max(
|
const maxCount = Math.max(
|
||||||
...(analyticsData?.hourlyStats?.map((s) => s.count) || [
|
...(analyticsData?.hourlyStats?.map((s) => s.count) || [1]),
|
||||||
1,
|
|
||||||
]),
|
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
const height = (count / maxCount) * 100;
|
const height = (count / maxCount) * 100;
|
||||||
@ -9264,27 +9284,25 @@ export function AdminSettingsClient() {
|
|||||||
<span>12:00</span>
|
<span>12:00</span>
|
||||||
<span>23:00</span>
|
<span>23:00</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<div className="grid gap-4">
|
|
||||||
<Card className="border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.24)]">
|
<Card className="border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.24)]">
|
||||||
<CardHeader className="pb-4">
|
<CardHeader className="pb-4">
|
||||||
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
||||||
top users
|
top users
|
||||||
</div>
|
</div>
|
||||||
<CardTitle className="text-lg">高活跃用户</CardTitle>
|
<CardTitle className="text-lg">高活跃用户</CardTitle>
|
||||||
<CardDescription>按生成次数排序,便于识别主要使用群体。</CardDescription>
|
<CardDescription>按生成次数排序,整块全宽展示主要使用群体。</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{analyticsData?.userStats?.slice(0, 8).map((user, index) => (
|
{analyticsData?.userStats?.slice(0, 10).map((user, index) => (
|
||||||
<div
|
<div
|
||||||
className="flex items-center justify-between rounded-2xl border border-zinc-200/70 bg-zinc-50/80 px-3 py-3"
|
className="flex items-center justify-between rounded-2xl border border-zinc-200/70 bg-zinc-50/80 px-4 py-3"
|
||||||
key={user.userId}
|
key={user.userId}
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex min-w-0 items-center gap-3">
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-8 w-8 items-center justify-center rounded-full text-xs font-semibold",
|
"flex h-8 w-8 items-center justify-center rounded-full text-xs font-semibold",
|
||||||
@ -9316,8 +9334,7 @@ export function AdminSettingsClient() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{(!analyticsData?.userStats ||
|
{(!analyticsData?.userStats || analyticsData.userStats.length === 0) && (
|
||||||
analyticsData.userStats.length === 0) && (
|
|
||||||
<div className="rounded-2xl border border-dashed border-zinc-200 py-10 text-center text-muted-foreground text-sm">
|
<div className="rounded-2xl border border-dashed border-zinc-200 py-10 text-center text-muted-foreground text-sm">
|
||||||
暂无用户排行数据
|
暂无用户排行数据
|
||||||
</div>
|
</div>
|
||||||
@ -9331,10 +9348,13 @@ export function AdminSettingsClient() {
|
|||||||
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
||||||
output sizes
|
output sizes
|
||||||
</div>
|
</div>
|
||||||
<CardTitle className="text-lg">尺寸分布</CardTitle>
|
<CardTitle className="text-lg">分辨率分布</CardTitle>
|
||||||
<CardDescription>观察用户输出尺寸的偏好与占比。</CardDescription>
|
<CardDescription>
|
||||||
|
统一按 4K、3K、2K、1K 四档归并统计,不再展示零散原始尺寸。
|
||||||
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-3">
|
<CardContent>
|
||||||
|
<div className="grid gap-3 md:grid-cols-2 xl:grid-cols-4">
|
||||||
{analyticsData?.sizeStats?.map((stat) => {
|
{analyticsData?.sizeStats?.map((stat) => {
|
||||||
const percentage = formatAnalyticsRatio(
|
const percentage = formatAnalyticsRatio(
|
||||||
stat.count,
|
stat.count,
|
||||||
@ -9342,18 +9362,19 @@ export function AdminSettingsClient() {
|
|||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="rounded-2xl border border-zinc-200/70 bg-white p-3"
|
className="rounded-2xl border border-zinc-200/70 bg-white p-4"
|
||||||
key={stat.imageSize || "unknown"}
|
key={stat.imageSize || "unknown"}
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-between text-sm">
|
<div className="text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
|
||||||
<span className="font-medium text-zinc-950">
|
{stat.imageSize}
|
||||||
{stat.imageSize || "未知"}
|
|
||||||
</span>
|
|
||||||
<span className="text-muted-foreground">
|
|
||||||
{formatAnalyticsNumber(stat.count)} · {percentage}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2 h-2 overflow-hidden rounded-full bg-zinc-100">
|
<div className="mt-3 font-semibold text-3xl tracking-tight text-zinc-950">
|
||||||
|
{formatAnalyticsNumber(stat.count)}
|
||||||
|
</div>
|
||||||
|
<div className="mt-1 text-muted-foreground text-xs">
|
||||||
|
占比 {percentage}
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 h-2 overflow-hidden rounded-full bg-zinc-100">
|
||||||
<div
|
<div
|
||||||
className="h-full rounded-full bg-gradient-to-r from-zinc-950 to-lime-400"
|
className="h-full rounded-full bg-gradient-to-r from-zinc-950 to-lime-400"
|
||||||
style={{ width: percentage }}
|
style={{ width: percentage }}
|
||||||
@ -9362,12 +9383,10 @@ export function AdminSettingsClient() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid gap-4 xl:grid-cols-[1.18fr_0.82fr]">
|
|
||||||
<Card className="border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.24)]">
|
<Card className="border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.24)]">
|
||||||
<CardHeader className="border-b border-zinc-200/70 pb-4">
|
<CardHeader className="border-b border-zinc-200/70 pb-4">
|
||||||
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
||||||
@ -9375,40 +9394,45 @@ export function AdminSettingsClient() {
|
|||||||
</div>
|
</div>
|
||||||
<CardTitle className="text-lg">模型使用概览</CardTitle>
|
<CardTitle className="text-lg">模型使用概览</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
修正为按 runtime modelId 聚合后再解析名称,避免跨 provider 串名。
|
兼容历史 UUID 与 runtime modelId,并按统一模型归并后展示后台配置名称。
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="grid gap-6 pt-6 lg:grid-cols-[1.12fr_0.88fr]">
|
<CardContent className="space-y-3 pt-6">
|
||||||
<div className="space-y-3">
|
{(analyticsData?.modelDetailStats || []).slice(0, 8).map((stat, index) => {
|
||||||
{(analyticsData?.modelDetailStats || []).slice(0, 6).map((stat, index) => {
|
|
||||||
const resolved = resolveRuntimeModelMeta(
|
const resolved = resolveRuntimeModelMeta(
|
||||||
runtimeModelMetaById,
|
runtimeModelMetaById,
|
||||||
stat.modelId
|
stat.modelId
|
||||||
);
|
);
|
||||||
|
const modelLabel = formatAnalyticsModelLabel(
|
||||||
|
resolved,
|
||||||
|
stat.modelId
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="rounded-2xl border border-zinc-200/70 bg-zinc-50/80 p-4"
|
className="rounded-2xl border border-zinc-200/70 bg-zinc-50/80 p-4"
|
||||||
key={`${stat.modelId || "unknown"}-${index}`}
|
key={`${stat.modelId || "unknown"}-${index}`}
|
||||||
>
|
>
|
||||||
<div className="flex items-start justify-between gap-3">
|
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||||
<div className="min-w-0">
|
<div className="min-w-0 flex-1">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-3">
|
||||||
<span className="flex h-6 w-6 items-center justify-center rounded-full bg-zinc-950 text-white text-xs font-semibold">
|
<span className="flex h-8 w-8 items-center justify-center rounded-full bg-zinc-950 text-white text-sm font-semibold">
|
||||||
{index + 1}
|
{index + 1}
|
||||||
</span>
|
</span>
|
||||||
<div className="truncate font-medium text-sm text-zinc-950">
|
<div className="min-w-0">
|
||||||
{resolved.modelName || stat.modelId || "未知模型"}
|
<div className="truncate font-medium text-base text-zinc-950">
|
||||||
|
{modelLabel}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div className="mt-1 flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
|
||||||
<div className="mt-2 flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
|
|
||||||
<span className="rounded-full bg-white px-2 py-1">
|
<span className="rounded-full bg-white px-2 py-1">
|
||||||
{resolved.providerName || "未知提供商"}
|
{resolved.providerName || "未知提供商"}
|
||||||
</span>
|
</span>
|
||||||
<span>{formatAnalyticsNumber(stat.userCount)} 位用户</span>
|
<span>{formatAnalyticsNumber(stat.userCount)} 位用户</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div className="text-right">
|
<div className="text-right">
|
||||||
<div className="font-semibold text-lg text-zinc-950">
|
<div className="font-semibold text-3xl tracking-tight text-zinc-950">
|
||||||
{formatAnalyticsNumber(stat.count)}
|
{formatAnalyticsNumber(stat.count)}
|
||||||
</div>
|
</div>
|
||||||
<div className="text-[11px] text-muted-foreground">
|
<div className="text-[11px] text-muted-foreground">
|
||||||
@ -9416,7 +9440,7 @@ export function AdminSettingsClient() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-3 h-2 overflow-hidden rounded-full bg-white">
|
<div className="mt-4 h-2 overflow-hidden rounded-full bg-white">
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"h-full rounded-full",
|
"h-full rounded-full",
|
||||||
@ -9445,22 +9469,18 @@ export function AdminSettingsClient() {
|
|||||||
暂无模型使用数据
|
暂无模型使用数据
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
<div className="space-y-3">
|
<Card className="border-zinc-200/80 shadow-[0_18px_40px_-28px_rgba(15,23,42,0.24)]">
|
||||||
<div className="rounded-2xl border border-zinc-200/70 bg-zinc-950 p-4 text-white">
|
<CardHeader className="pb-4">
|
||||||
<div className="text-[11px] uppercase tracking-[0.2em] text-zinc-400">
|
<div className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">
|
||||||
model traffic
|
provider distribution
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2 font-semibold text-3xl tracking-tight">
|
<CardTitle className="text-lg">提供商分布</CardTitle>
|
||||||
{formatAnalyticsNumber(analyticsModelTotal)}
|
<CardDescription>按 provider 汇总模型调用量,使用整行进度条展示占比。</CardDescription>
|
||||||
</div>
|
</CardHeader>
|
||||||
<div className="mt-1 text-zinc-400 text-xs">
|
<CardContent className="space-y-3">
|
||||||
当前榜单内模型累计调用次数
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-3">
|
|
||||||
{(analyticsData?.providerTypeStats || []).map((stat, index) => {
|
{(analyticsData?.providerTypeStats || []).map((stat, index) => {
|
||||||
const total =
|
const total =
|
||||||
analyticsData?.providerTypeStats?.reduce(
|
analyticsData?.providerTypeStats?.reduce(
|
||||||
@ -9470,7 +9490,7 @@ export function AdminSettingsClient() {
|
|||||||
const width = formatAnalyticsRatio(stat.count, total);
|
const width = formatAnalyticsRatio(stat.count, total);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="rounded-2xl border border-zinc-200/70 bg-white p-3"
|
className="rounded-2xl border border-zinc-200/70 bg-white p-4"
|
||||||
key={`${stat.providerType || "unknown"}-${index}`}
|
key={`${stat.providerType || "unknown"}-${index}`}
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-between gap-3 text-sm">
|
<div className="flex items-center justify-between gap-3 text-sm">
|
||||||
@ -9481,7 +9501,7 @@ export function AdminSettingsClient() {
|
|||||||
{formatAnalyticsNumber(stat.count)} · {width}
|
{formatAnalyticsNumber(stat.count)} · {width}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2 h-2 overflow-hidden rounded-full bg-zinc-100">
|
<div className="mt-3 h-2 overflow-hidden rounded-full bg-zinc-100">
|
||||||
<div
|
<div
|
||||||
className="h-full rounded-full bg-gradient-to-r from-zinc-950 to-lime-400"
|
className="h-full rounded-full bg-gradient-to-r from-zinc-950 to-lime-400"
|
||||||
style={{ width }}
|
style={{ width }}
|
||||||
@ -9490,8 +9510,6 @@ export function AdminSettingsClient() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
@ -9501,7 +9519,7 @@ export function AdminSettingsClient() {
|
|||||||
recent 7 days
|
recent 7 days
|
||||||
</div>
|
</div>
|
||||||
<CardTitle className="text-lg">模型日趋势</CardTitle>
|
<CardTitle className="text-lg">模型日趋势</CardTitle>
|
||||||
<CardDescription>每天显示总量,并直接列出当日最活跃的模型。</CardDescription>
|
<CardDescription>每天显示总量,并列出当日最活跃的模型名称。</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-3">
|
<CardContent className="space-y-3">
|
||||||
{analyticsTrendDays.map((day) => {
|
{analyticsTrendDays.map((day) => {
|
||||||
@ -9530,8 +9548,15 @@ export function AdminSettingsClient() {
|
|||||||
className="inline-flex items-center gap-2 rounded-full border border-zinc-200 bg-white px-3 py-1.5 text-xs"
|
className="inline-flex items-center gap-2 rounded-full border border-zinc-200 bg-white px-3 py-1.5 text-xs"
|
||||||
key={`${day.date}-${stat.modelId || stat.modelName}`}
|
key={`${day.date}-${stat.modelId || stat.modelName}`}
|
||||||
>
|
>
|
||||||
<span className="max-w-[140px] truncate text-zinc-900">
|
<span className="max-w-[180px] truncate text-zinc-900">
|
||||||
{stat.modelName || stat.modelId || "未知模型"}
|
{formatAnalyticsModelLabel(
|
||||||
|
{
|
||||||
|
modelName: stat.modelName,
|
||||||
|
providerName: stat.providerName,
|
||||||
|
providerType: stat.providerType,
|
||||||
|
},
|
||||||
|
stat.modelId
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-muted-foreground">
|
<span className="text-muted-foreground">
|
||||||
{formatAnalyticsNumber(stat.count)}
|
{formatAnalyticsNumber(stat.count)}
|
||||||
@ -9549,7 +9574,6 @@ export function AdminSettingsClient() {
|
|||||||
) : null}
|
) : null}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|
||||||
{/* 网站设置 */}
|
{/* 网站设置 */}
|
||||||
|
|||||||
@ -538,13 +538,17 @@ export default function GalleryPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-4 border-t bg-background">
|
<div className="border-t bg-background p-4">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<p className="font-medium">{selectedImage.alt}</p>
|
<div className="flex flex-wrap items-center gap-3 text-sm">
|
||||||
<p className="text-sm text-muted-foreground mt-1">
|
<span className="font-medium text-foreground">
|
||||||
|
模型 ID: {selectedImage.modelId || "未知模型"}
|
||||||
|
</span>
|
||||||
|
<span className="text-muted-foreground">
|
||||||
{formatBeijingTime(selectedImage.createdAt)}
|
{formatBeijingTime(selectedImage.createdAt)}
|
||||||
</p>
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleDownload(selectedImage.url, selectedImage.alt)}
|
onClick={() => handleDownload(selectedImage.url, selectedImage.alt)}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { eq, sql, desc, and, gte, lt } from "drizzle-orm";
|
|||||||
import { auth } from "@/app/(auth)/auth";
|
import { auth } from "@/app/(auth)/auth";
|
||||||
|
|
||||||
type RuntimeModelRegistryRow = {
|
type RuntimeModelRegistryRow = {
|
||||||
|
id: string;
|
||||||
modelId: string;
|
modelId: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
providerName: string | null;
|
providerName: string | null;
|
||||||
@ -19,11 +20,57 @@ type RuntimeModelRegistryRow = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type RuntimeModelMeta = {
|
type RuntimeModelMeta = {
|
||||||
|
canonicalModelId: string | null;
|
||||||
modelName: string | null;
|
modelName: string | null;
|
||||||
providerName: string | null;
|
providerName: string | null;
|
||||||
providerType: string | null;
|
providerType: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ANALYTICS_SIZE_BUCKETS = ["4K", "3K", "2K", "1K"] as const;
|
||||||
|
|
||||||
|
function normalizeAnalyticsImageSizeBucket(value: string | null | undefined) {
|
||||||
|
const normalized = String(value || "")
|
||||||
|
.trim()
|
||||||
|
.toUpperCase();
|
||||||
|
|
||||||
|
if (!normalized) return "2K";
|
||||||
|
if (normalized.includes("4K")) return "4K";
|
||||||
|
if (normalized.includes("3K")) return "3K";
|
||||||
|
if (normalized.includes("2K")) return "2K";
|
||||||
|
if (normalized.includes("1K")) return "1K";
|
||||||
|
|
||||||
|
const sizeMatch = normalized.match(/(\d+(?:\.\d+)?)\s*K/);
|
||||||
|
if (sizeMatch) {
|
||||||
|
const sizeValue = Number(sizeMatch[1]);
|
||||||
|
if (sizeValue >= 3.5) return "4K";
|
||||||
|
if (sizeValue >= 2.5) return "3K";
|
||||||
|
if (sizeValue >= 1.5) return "2K";
|
||||||
|
return "1K";
|
||||||
|
}
|
||||||
|
|
||||||
|
const dimensionMatch = normalized.match(/(\d{3,5})\s*[X×*]\s*(\d{3,5})/);
|
||||||
|
if (dimensionMatch) {
|
||||||
|
const maxEdge = Math.max(
|
||||||
|
Number(dimensionMatch[1]),
|
||||||
|
Number(dimensionMatch[2])
|
||||||
|
);
|
||||||
|
if (maxEdge >= 3500) return "4K";
|
||||||
|
if (maxEdge >= 2500) return "3K";
|
||||||
|
if (maxEdge >= 1500) return "2K";
|
||||||
|
return "1K";
|
||||||
|
}
|
||||||
|
|
||||||
|
const numericMatch = normalized.match(/(\d{3,5})/);
|
||||||
|
if (numericMatch) {
|
||||||
|
const numericValue = Number(numericMatch[1]);
|
||||||
|
if (numericValue >= 3500) return "4K";
|
||||||
|
if (numericValue >= 2500) return "3K";
|
||||||
|
if (numericValue >= 1500) return "2K";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "1K";
|
||||||
|
}
|
||||||
|
|
||||||
function scoreRuntimeModelCandidate(row: RuntimeModelRegistryRow) {
|
function scoreRuntimeModelCandidate(row: RuntimeModelRegistryRow) {
|
||||||
return (
|
return (
|
||||||
(row.isEnabled ? 100 : 0) +
|
(row.isEnabled ? 100 : 0) +
|
||||||
@ -40,14 +87,19 @@ function buildRuntimeModelRegistry(rows: RuntimeModelRegistryRow[]) {
|
|||||||
|
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
const score = scoreRuntimeModelCandidate(row);
|
const score = scoreRuntimeModelCandidate(row);
|
||||||
const current = registry.get(row.modelId);
|
const meta = {
|
||||||
if (current && current.score >= score) continue;
|
|
||||||
registry.set(row.modelId, {
|
|
||||||
score,
|
score,
|
||||||
|
canonicalModelId: row.modelId,
|
||||||
modelName: row.displayName || null,
|
modelName: row.displayName || null,
|
||||||
providerName: row.providerName || null,
|
providerName: row.providerName || null,
|
||||||
providerType: row.providerType || null,
|
providerType: row.providerType || null,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
for (const key of [row.id, row.modelId]) {
|
||||||
|
const current = registry.get(key);
|
||||||
|
if (current && current.score >= score) continue;
|
||||||
|
registry.set(key, meta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return registry;
|
return registry;
|
||||||
@ -59,6 +111,7 @@ function resolveRuntimeModelMeta(
|
|||||||
): RuntimeModelMeta {
|
): RuntimeModelMeta {
|
||||||
if (!modelId) {
|
if (!modelId) {
|
||||||
return {
|
return {
|
||||||
|
canonicalModelId: null,
|
||||||
modelName: null,
|
modelName: null,
|
||||||
providerName: null,
|
providerName: null,
|
||||||
providerType: null,
|
providerType: null,
|
||||||
@ -67,12 +120,110 @@ function resolveRuntimeModelMeta(
|
|||||||
|
|
||||||
const resolved = registry.get(modelId);
|
const resolved = registry.get(modelId);
|
||||||
return {
|
return {
|
||||||
|
canonicalModelId: resolved?.canonicalModelId || null,
|
||||||
modelName: resolved?.modelName || null,
|
modelName: resolved?.modelName || null,
|
||||||
providerName: resolved?.providerName || null,
|
providerName: resolved?.providerName || null,
|
||||||
providerType: resolved?.providerType || null,
|
providerType: resolved?.providerType || null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildCanonicalModelUsage(
|
||||||
|
rows: Array<{ modelId: string | null; userId: string; count: number }>,
|
||||||
|
registry: Map<string, RuntimeModelMeta & { score: number }>
|
||||||
|
) {
|
||||||
|
const usageMap = new Map<
|
||||||
|
string,
|
||||||
|
RuntimeModelMeta & {
|
||||||
|
modelId: string | null;
|
||||||
|
count: number;
|
||||||
|
userIds: Set<string>;
|
||||||
|
}
|
||||||
|
>();
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
const meta = resolveRuntimeModelMeta(registry, row.modelId);
|
||||||
|
const canonicalModelId = meta.canonicalModelId || row.modelId;
|
||||||
|
const key = canonicalModelId || row.modelId || "__unknown__";
|
||||||
|
const current = usageMap.get(key) || {
|
||||||
|
modelId: canonicalModelId,
|
||||||
|
canonicalModelId,
|
||||||
|
modelName: meta.modelName,
|
||||||
|
providerName: meta.providerName,
|
||||||
|
providerType: meta.providerType,
|
||||||
|
count: 0,
|
||||||
|
userIds: new Set<string>(),
|
||||||
|
};
|
||||||
|
|
||||||
|
current.count += row.count;
|
||||||
|
current.userIds.add(row.userId);
|
||||||
|
if (!current.modelName && meta.modelName) current.modelName = meta.modelName;
|
||||||
|
if (!current.providerName && meta.providerName) {
|
||||||
|
current.providerName = meta.providerName;
|
||||||
|
}
|
||||||
|
if (!current.providerType && meta.providerType) {
|
||||||
|
current.providerType = meta.providerType;
|
||||||
|
}
|
||||||
|
usageMap.set(key, current);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(usageMap.values())
|
||||||
|
.map(({ userIds, canonicalModelId, ...item }) => ({
|
||||||
|
...item,
|
||||||
|
modelId: item.modelId || canonicalModelId,
|
||||||
|
userCount: userIds.size,
|
||||||
|
}))
|
||||||
|
.sort((left, right) => right.count - left.count);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildCanonicalModelTrend(
|
||||||
|
rows: Array<{ date: string; modelId: string | null; count: number }>,
|
||||||
|
registry: Map<string, RuntimeModelMeta & { score: number }>
|
||||||
|
) {
|
||||||
|
const trendMap = new Map<
|
||||||
|
string,
|
||||||
|
RuntimeModelMeta & {
|
||||||
|
date: string;
|
||||||
|
modelId: string | null;
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
>();
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
const meta = resolveRuntimeModelMeta(registry, row.modelId);
|
||||||
|
const canonicalModelId = meta.canonicalModelId || row.modelId;
|
||||||
|
const key = `${row.date}::${canonicalModelId || row.modelId || "__unknown__"}`;
|
||||||
|
const current = trendMap.get(key) || {
|
||||||
|
date: row.date,
|
||||||
|
modelId: canonicalModelId,
|
||||||
|
canonicalModelId,
|
||||||
|
modelName: meta.modelName,
|
||||||
|
providerName: meta.providerName,
|
||||||
|
providerType: meta.providerType,
|
||||||
|
count: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
current.count += row.count;
|
||||||
|
if (!current.modelName && meta.modelName) current.modelName = meta.modelName;
|
||||||
|
if (!current.providerName && meta.providerName) {
|
||||||
|
current.providerName = meta.providerName;
|
||||||
|
}
|
||||||
|
if (!current.providerType && meta.providerType) {
|
||||||
|
current.providerType = meta.providerType;
|
||||||
|
}
|
||||||
|
trendMap.set(key, current);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(trendMap.values())
|
||||||
|
.map(({ canonicalModelId, ...item }) => ({
|
||||||
|
...item,
|
||||||
|
modelId: item.modelId || canonicalModelId,
|
||||||
|
}))
|
||||||
|
.sort(
|
||||||
|
(left, right) =>
|
||||||
|
left.date.localeCompare(right.date) || right.count - left.count
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
@ -129,7 +280,7 @@ export async function GET(request: NextRequest) {
|
|||||||
.orderBy(sql`date(${generatedImage.createdAt})`);
|
.orderBy(sql`date(${generatedImage.createdAt})`);
|
||||||
|
|
||||||
// 4. 按图片尺寸统计
|
// 4. 按图片尺寸统计
|
||||||
const sizeStats = await db
|
const rawSizeStats = await db
|
||||||
.select({
|
.select({
|
||||||
imageSize: generatedImage.imageSize,
|
imageSize: generatedImage.imageSize,
|
||||||
count: sql<number>`count(*)::int`,
|
count: sql<number>`count(*)::int`,
|
||||||
@ -137,9 +288,19 @@ export async function GET(request: NextRequest) {
|
|||||||
.from(generatedImage)
|
.from(generatedImage)
|
||||||
.groupBy(generatedImage.imageSize)
|
.groupBy(generatedImage.imageSize)
|
||||||
.orderBy(desc(sql`count(*)`));
|
.orderBy(desc(sql`count(*)`));
|
||||||
|
const sizeBucketMap = new Map<string, number>();
|
||||||
|
for (const stat of rawSizeStats) {
|
||||||
|
const bucket = normalizeAnalyticsImageSizeBucket(stat.imageSize);
|
||||||
|
sizeBucketMap.set(bucket, (sizeBucketMap.get(bucket) || 0) + stat.count);
|
||||||
|
}
|
||||||
|
const sizeStats = ANALYTICS_SIZE_BUCKETS.map((bucket) => ({
|
||||||
|
imageSize: bucket,
|
||||||
|
count: sizeBucketMap.get(bucket) || 0,
|
||||||
|
}));
|
||||||
|
|
||||||
const runtimeModelRows = await db
|
const runtimeModelRows = await db
|
||||||
.select({
|
.select({
|
||||||
|
id: aiModel.id,
|
||||||
modelId: aiModel.modelId,
|
modelId: aiModel.modelId,
|
||||||
displayName: aiModel.displayName,
|
displayName: aiModel.displayName,
|
||||||
providerName: aiProvider.name,
|
providerName: aiProvider.name,
|
||||||
@ -158,26 +319,32 @@ export async function GET(request: NextRequest) {
|
|||||||
const runtimeModelRegistry = buildRuntimeModelRegistry(runtimeModelRows);
|
const runtimeModelRegistry = buildRuntimeModelRegistry(runtimeModelRows);
|
||||||
|
|
||||||
// 5. 按模型统计
|
// 5. 按模型统计
|
||||||
const aggregatedModelStats = await db
|
const rawModelUsageRows = await db
|
||||||
.select({
|
.select({
|
||||||
modelId: generatedImage.modelId,
|
modelId: generatedImage.modelId,
|
||||||
|
userId: generatedImage.userId,
|
||||||
count: sql<number>`count(*)::int`,
|
count: sql<number>`count(*)::int`,
|
||||||
userCount: sql<number>`count(distinct ${generatedImage.userId})::int`,
|
|
||||||
})
|
})
|
||||||
.from(generatedImage)
|
.from(generatedImage)
|
||||||
.groupBy(generatedImage.modelId)
|
.groupBy(generatedImage.modelId, generatedImage.userId);
|
||||||
.orderBy(desc(sql`count(*)`));
|
|
||||||
|
|
||||||
const modelStats = aggregatedModelStats.slice(0, 10).map((stat) => ({
|
const canonicalModelStats = buildCanonicalModelUsage(
|
||||||
|
rawModelUsageRows,
|
||||||
|
runtimeModelRegistry
|
||||||
|
);
|
||||||
|
|
||||||
|
const modelStats = canonicalModelStats.slice(0, 10).map((stat) => ({
|
||||||
modelId: stat.modelId,
|
modelId: stat.modelId,
|
||||||
count: stat.count,
|
count: stat.count,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const modelDetailStats = aggregatedModelStats.slice(0, 20).map((stat) => ({
|
const modelDetailStats = canonicalModelStats.slice(0, 20).map((stat) => ({
|
||||||
modelId: stat.modelId,
|
modelId: stat.modelId,
|
||||||
count: stat.count,
|
count: stat.count,
|
||||||
userCount: stat.userCount,
|
userCount: stat.userCount,
|
||||||
...resolveRuntimeModelMeta(runtimeModelRegistry, stat.modelId),
|
modelName: stat.modelName,
|
||||||
|
providerName: stat.providerName,
|
||||||
|
providerType: stat.providerType,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 5.2 按提供商类型统计
|
// 5.2 按提供商类型统计
|
||||||
@ -189,12 +356,11 @@ export async function GET(request: NextRequest) {
|
|||||||
count: number;
|
count: number;
|
||||||
}
|
}
|
||||||
>();
|
>();
|
||||||
for (const stat of aggregatedModelStats) {
|
for (const stat of canonicalModelStats) {
|
||||||
const meta = resolveRuntimeModelMeta(runtimeModelRegistry, stat.modelId);
|
const key = `${stat.providerType || "unknown"}::${stat.providerName || "unknown"}`;
|
||||||
const key = `${meta.providerType || "unknown"}::${meta.providerName || "unknown"}`;
|
|
||||||
const current = providerTypeStatsMap.get(key) || {
|
const current = providerTypeStatsMap.get(key) || {
|
||||||
providerType: meta.providerType,
|
providerType: stat.providerType,
|
||||||
providerName: meta.providerName,
|
providerName: stat.providerName,
|
||||||
count: 0,
|
count: 0,
|
||||||
};
|
};
|
||||||
current.count += stat.count;
|
current.count += stat.count;
|
||||||
@ -215,12 +381,10 @@ export async function GET(request: NextRequest) {
|
|||||||
.where(sql`${generatedImage.createdAt} >= now() - interval '7 days'`)
|
.where(sql`${generatedImage.createdAt} >= now() - interval '7 days'`)
|
||||||
.groupBy(sql`date(${generatedImage.createdAt})`, generatedImage.modelId)
|
.groupBy(sql`date(${generatedImage.createdAt})`, generatedImage.modelId)
|
||||||
.orderBy(sql`date(${generatedImage.createdAt})`);
|
.orderBy(sql`date(${generatedImage.createdAt})`);
|
||||||
const modelTrendStats = rawModelTrendStats.map((stat) => ({
|
const modelTrendStats = buildCanonicalModelTrend(
|
||||||
date: stat.date,
|
rawModelTrendStats,
|
||||||
modelId: stat.modelId,
|
runtimeModelRegistry
|
||||||
count: stat.count,
|
);
|
||||||
...resolveRuntimeModelMeta(runtimeModelRegistry, stat.modelId),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// 6. 按月份统计
|
// 6. 按月份统计
|
||||||
const monthlyStats = await db
|
const monthlyStats = await db
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { User } from "next-auth";
|
import type { User } from "next-auth";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
import { TopNavbar } from "@/components/top-navbar";
|
import { TopNavbar } from "@/components/top-navbar";
|
||||||
|
|
||||||
type CustomLink = {
|
type CustomLink = {
|
||||||
@ -61,8 +62,13 @@ export function ChatShellChrome({
|
|||||||
agentEnabled,
|
agentEnabled,
|
||||||
videoCanvasEnabled,
|
videoCanvasEnabled,
|
||||||
}: ChatShellChromeProps) {
|
}: ChatShellChromeProps) {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const hideSidebarChrome =
|
||||||
|
pathname === "/gallery" || pathname.startsWith("/gallery/");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{hideSidebarChrome ? null : (
|
||||||
<TopNavbar
|
<TopNavbar
|
||||||
agentEnabled={agentEnabled}
|
agentEnabled={agentEnabled}
|
||||||
customLinks={customLinks}
|
customLinks={customLinks}
|
||||||
@ -81,7 +87,14 @@ export function ChatShellChrome({
|
|||||||
tutorialVideos={tutorialVideos}
|
tutorialVideos={tutorialVideos}
|
||||||
videoCanvasEnabled={videoCanvasEnabled}
|
videoCanvasEnabled={videoCanvasEnabled}
|
||||||
/>
|
/>
|
||||||
<div className="flex h-svh w-full overflow-hidden pl-16 [--sidebar-offset:4rem]">
|
)}
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
hideSidebarChrome
|
||||||
|
? "flex h-svh w-full overflow-hidden"
|
||||||
|
: "flex h-svh w-full overflow-hidden pl-16 [--sidebar-offset:4rem]"
|
||||||
|
}
|
||||||
|
>
|
||||||
<main className="h-full min-w-0 flex-1">{children}</main>
|
<main className="h-full min-w-0 flex-1">{children}</main>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -1529,9 +1529,8 @@ export function LovartHome({
|
|||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => setUpgradeDialogOpen(true)}
|
onClick={() => setUpgradeDialogOpen(true)}
|
||||||
className="h-8 rounded-[14px] bg-[#1c1c1e] px-2.5 text-[14px] text-white hover:bg-black hover:text-white"
|
className="h-8 rounded-[14px] bg-[#1c1c1e] px-2 text-[14px] text-white hover:bg-black hover:text-white"
|
||||||
>
|
>
|
||||||
<span className="mr-1.5">升级</span>
|
|
||||||
<div className="inline-flex items-center gap-1 rounded-[9px] bg-white/10 px-1.5 py-0.5 text-xs text-white">
|
<div className="inline-flex items-center gap-1 rounded-[9px] bg-white/10 px-1.5 py-0.5 text-xs text-white">
|
||||||
<Zap className="h-3 w-3 text-amber-300" />
|
<Zap className="h-3 w-3 text-amber-300" />
|
||||||
{membershipData?.summary?.currentCredits ?? 0}
|
{membershipData?.summary?.currentCredits ?? 0}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user