first commit

This commit is contained in:
luoyangwei
2026-06-06 00:49:07 +08:00
commit 2b860d201e
134 changed files with 22773 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import { syncUnsplashWallpapersToGallery } from "@/server/admin/gallery-sync";
import { NextResponse, type NextRequest } from "next/server";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
function isAuthorized(request: NextRequest) {
const cronSecret = process.env.CRON_SECRET;
if (!cronSecret) {
return false;
}
return request.headers.get("authorization") === `Bearer ${cronSecret}`;
}
async function handleGalleryPhotosCron(request: NextRequest) {
if (!process.env.CRON_SECRET) {
return NextResponse.json(
{ ok: false, error: "CRON_SECRET is not configured." },
{ status: 500 },
);
}
if (!isAuthorized(request)) {
return NextResponse.json(
{ ok: false, error: "Unauthorized." },
{ status: 401 },
);
}
try {
const result = await syncUnsplashWallpapersToGallery();
return NextResponse.json({ ok: true, result });
} catch (error) {
const message =
error instanceof Error ? error.message : "Unknown cron error.";
return NextResponse.json(
{ ok: false, error: message },
{ status: 500 },
);
}
}
export async function GET(request: NextRequest) {
return handleGalleryPhotosCron(request);
}
export async function POST(request: NextRequest) {
return handleGalleryPhotosCron(request);
}