chore(repo): 将生产源码基线同步回 main #1

Merged
WuYongJie merged 265 commits from codex/production-48-20261030 into main 2026-10-30 16:39:58 +08:00
Showing only changes of commit 3d12c508d3 - Show all commits

View File

@ -1,12 +1,13 @@
import "server-only";
import { and, asc, eq, inArray, lte, sql } from "drizzle-orm";
import { and, asc, eq, inArray, lt, lte, sql } from "drizzle-orm";
import { db } from "@/lib/db";
import { imageArchiveTask, type ImageArchiveTask } from "@/lib/db/schema";
export type ImageArchiveTaskRecord = ImageArchiveTask;
const DEFAULT_DISPLAY_HOLD_HOURS = 1;
const MAX_IMAGE_ARCHIVE_ATTEMPTS = 12;
function getDisplayHoldHours() {
const raw = Number(
@ -95,7 +96,8 @@ export async function getImageArchiveTasksToStore(params: { limit: number }) {
.where(
and(
inArray(imageArchiveTask.status, ["pending", "failed"]),
lte(imageArchiveTask.archiveAfterAt, now)
lte(imageArchiveTask.archiveAfterAt, now),
lt(imageArchiveTask.attemptCount, MAX_IMAGE_ARCHIVE_ATTEMPTS)
)
)
.orderBy(asc(imageArchiveTask.createdAt), asc(imageArchiveTask.id))
@ -139,11 +141,18 @@ export async function markImageArchiveTaskFailed(params: {
const message = String(
params.error instanceof Error ? params.error.message : params.error || "Unknown error"
).slice(0, 2000);
const isPermanentSourceError = /\bHTTP (?:404|410)\b/i.test(message);
await db
.update(imageArchiveTask)
.set({
status: "failed",
status: isPermanentSourceError
? "abandoned"
: sql`case
when ${imageArchiveTask.attemptCount} >= ${MAX_IMAGE_ARCHIVE_ATTEMPTS}
then 'abandoned'
else 'failed'
end`,
lastError: message,
archiveAfterAt: new Date(Date.now() + 10 * 60 * 1000),
updatedAt: new Date(),