import type { ImageHistoryItem, PublicUser } from "@/lib/types";
interface HistoryGalleryProps {
currentUser: PublicUser;
items: ImageHistoryItem[];
}
const dateTimeFormatter = new Intl.DateTimeFormat("zh-CN", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
});
export default function HistoryGallery({
currentUser,
items,
}: HistoryGalleryProps) {
const totalUsers = new Set(items.map((item) => item.userId)).size;
const latestItem = items[0] ?? null;
return (
Archive
{currentUser.role === "admin" ? "全站生成历史" : "我的生成历史"}
{items.length} 张图片
图片总数
{items.length}
{currentUser.role === "admin" ? "涉及用户" : "当前身份"}
{currentUser.role === "admin" ? `${totalUsers} 位` : "普通用户"}
最近一张
{latestItem
? dateTimeFormatter.format(new Date(latestItem.createdAt))
: "暂无记录"}
{currentUser.role === "admin"
? "管理员可以查看所有用户的历史记录、原始提示词和生成参数,页面会额外标注每张图所属的账号。"
: "普通用户只能查看自己的历史记录和图片内容,接口会按当前登录账号做隔离。"}
Prompt 可回看
按账号隔离
原图可下载
{items.length === 0 ? (
还没有历史图片
生成成功后的图片会自动保存到服务器,这里会展示图片、提示词和模型参数。
) : (
{items.map((item) => (
{item.fileName}
{dateTimeFormatter.format(new Date(item.createdAt))}
{currentUser.role === "admin" ? (
{item.username}
) : null}
{item.model ?? "未知模型"}
{item.size ?? "未知尺寸"}
{item.quality ?? "未知质量"}
格式
{formatOutputFormatLabel(item)}
背景
{item.background ?? "auto"}
文件大小
{formatFileSize(item.fileSize)}
查看提示词
{item.prompt}
{item.revisedPrompt ? (
查看模型调整后的提示词
{item.revisedPrompt}
) : null}
))}
)}
);
}
function formatFileSize(fileSize: number): string {
if (fileSize < 1024) {
return `${fileSize} B`;
}
if (fileSize < 1024 * 1024) {
return `${(fileSize / 1024).toFixed(1)} KB`;
}
return `${(fileSize / (1024 * 1024)).toFixed(2)} MB`;
}
function formatOutputFormatLabel(item: ImageHistoryItem): string {
if (item.outputFormat) {
return item.outputFormat.toUpperCase();
}
return item.mimeType.replace(/^image\//, "").toUpperCase();
}