feat: add support for mirroring wiki pages in configuration

This commit is contained in:
Arunavo Ray
2025-06-11 19:48:24 +05:30
parent 108408be81
commit 0f671a4088
12 changed files with 329 additions and 108 deletions

View File

@@ -9,7 +9,6 @@ import {
} from "@/lib/gitea";
import { createGitHubClient } from "@/lib/github";
import { processWithResilience } from "@/lib/utils/concurrency";
import { v4 as uuidv4 } from "uuid";
export const POST: APIRoute = async ({ request }) => {
try {
@@ -77,9 +76,6 @@ export const POST: APIRoute = async ({ request }) => {
// Define the concurrency limit - adjust based on API rate limits
const CONCURRENCY_LIMIT = 3;
// Generate a batch ID to group related repositories
const batchId = uuidv4();
// Process repositories in parallel with resilience to container restarts
await processWithResilience(
repos,
@@ -120,7 +116,6 @@ export const POST: APIRoute = async ({ request }) => {
{
userId: config.userId || "",
jobType: "mirror",
batchId,
getItemId: (repo) => repo.id,
getItemName: (repo) => repo.name,
concurrencyLimit: CONCURRENCY_LIMIT,
@@ -129,15 +124,19 @@ export const POST: APIRoute = async ({ request }) => {
checkpointInterval: 5, // Checkpoint every 5 repositories to reduce event frequency
onProgress: (completed, total, result) => {
const percentComplete = Math.round((completed / total) * 100);
console.log(`Mirroring progress: ${percentComplete}% (${completed}/${total})`);
console.log(
`Mirroring progress: ${percentComplete}% (${completed}/${total})`
);
if (result) {
console.log(`Successfully mirrored repository: ${result.name}`);
}
},
onRetry: (repo, error, attempt) => {
console.log(`Retrying repository ${repo.name} (attempt ${attempt}): ${error.message}`);
}
console.log(
`Retrying repository ${repo.name} (attempt ${attempt}): ${error.message}`
);
},
}
);
@@ -168,7 +167,10 @@ export const POST: APIRoute = async ({ request }) => {
// Enhanced error logging for better debugging
console.error("=== ERROR MIRRORING REPOSITORIES ===");
console.error("Error type:", error?.constructor?.name);
console.error("Error message:", error instanceof Error ? error.message : String(error));
console.error(
"Error message:",
error instanceof Error ? error.message : String(error)
);
if (error instanceof Error) {
console.error("Error stack:", error.stack);
@@ -181,9 +183,11 @@ export const POST: APIRoute = async ({ request }) => {
console.error("- Headers:", Object.fromEntries(request.headers.entries()));
// If it's a JSON parsing error, provide more context
if (error instanceof SyntaxError && error.message.includes('JSON')) {
if (error instanceof SyntaxError && error.message.includes("JSON")) {
console.error("🚨 JSON PARSING ERROR DETECTED:");
console.error("This suggests the response from Gitea API is not valid JSON");
console.error(
"This suggests the response from Gitea API is not valid JSON"
);
console.error("Common causes:");
console.error("- Gitea server returned HTML error page instead of JSON");
console.error("- Network connection interrupted");
@@ -196,14 +200,16 @@ export const POST: APIRoute = async ({ request }) => {
return new Response(
JSON.stringify({
error: error instanceof Error ? error.message : "An unknown error occurred",
error:
error instanceof Error ? error.message : "An unknown error occurred",
errorType: error?.constructor?.name || "Unknown",
timestamp: new Date().toISOString(),
troubleshooting: error instanceof SyntaxError && error.message.includes('JSON')
? "JSON parsing error detected. Check Gitea server status and logs. Ensure Gitea is returning valid JSON responses."
: "Check application logs for more details"
troubleshooting:
error instanceof SyntaxError && error.message.includes("JSON")
? "JSON parsing error detected. Check Gitea server status and logs. Ensure Gitea is returning valid JSON responses."
: "Check application logs for more details",
}),
{ status: 500, headers: { "Content-Type": "application/json" } }
);
}
};
};