feat: 添加更新功能控制台日志 (console.log/error),标记每步执行与错误输出
This commit is contained in:
@@ -1,15 +1,31 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { checkForUpdate } from "@/lib/update";
|
||||
|
||||
function apiLog(msg: string) {
|
||||
const t = new Date().toISOString().slice(0, 19).replace("T", " ");
|
||||
console.log(`[${t}] [更新检查] ${msg}`);
|
||||
}
|
||||
|
||||
function apiErr(msg: string) {
|
||||
const t = new Date().toISOString().slice(0, 19).replace("T", " ");
|
||||
console.error(`[${t}] [更新检查] ${msg}`);
|
||||
}
|
||||
|
||||
// GET /api/update/check - 检查是否有可用更新
|
||||
export async function GET() {
|
||||
apiLog("收到版本检查请求");
|
||||
try {
|
||||
const versionInfo = await checkForUpdate();
|
||||
const hasUpdate = versionInfo.hasUpdate;
|
||||
const latestVer = versionInfo.latest?.version || "无";
|
||||
apiLog(`检查完成: ${hasUpdate ? "有新版本 " + latestVer : "已是最新"}`);
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: versionInfo,
|
||||
});
|
||||
} catch (error) {
|
||||
const msg = error instanceof Error ? error.message : "未知错误";
|
||||
apiErr(`检查异常: ${msg}`);
|
||||
return NextResponse.json(
|
||||
{ success: false, error: "检查更新失败" },
|
||||
{ status: 500 }
|
||||
|
||||
Reference in New Issue
Block a user