refactor: update development scripts and improve code formatting
- Replaced nodemon with tsx for development script in package.json - Updated devDependencies to include tsx and removed nodemon - Reformatted code in worker.ts for better readability - Improved handling of API calls and logging in worker.ts
This commit is contained in:
27
worker.ts
27
worker.ts
@@ -13,7 +13,8 @@ export interface DeployJobData {
|
||||
}
|
||||
|
||||
// Configuration
|
||||
const GITEA_API_URL = process.env.GITEA_API_URL || "https://git.mworld.cloud/api/v1";
|
||||
const GITEA_API_URL =
|
||||
process.env.GITEA_API_URL || "https://git.mworld.cloud/api/v1";
|
||||
const GITEA_TOKEN = process.env.GITEA_TOKEN;
|
||||
const GITEA_USERNAME = process.env.GITEA_USERNAME;
|
||||
|
||||
@@ -62,12 +63,17 @@ const worker = new Worker<DeployJobData>(
|
||||
await job.updateProgress(10);
|
||||
|
||||
let repoDetails: any;
|
||||
|
||||
const checkRepo = await callGitea("GET", `/repos/${GITEA_USERNAME}/${sanitizedRepoName}`);
|
||||
|
||||
const checkRepo = await callGitea(
|
||||
"GET",
|
||||
`/repos/${GITEA_USERNAME}/${sanitizedRepoName}`
|
||||
);
|
||||
|
||||
if (checkRepo.status === 404) {
|
||||
console.log(`[Job ${job.id}] Repo not found, creating new repo: ${sanitizedRepoName}`);
|
||||
|
||||
console.log(
|
||||
`[Job ${job.id}] Repo not found, creating new repo: ${sanitizedRepoName}`
|
||||
);
|
||||
|
||||
// Create Repo
|
||||
const createRes = await callGitea("POST", "/user/repos", {
|
||||
name: sanitizedRepoName,
|
||||
@@ -77,7 +83,7 @@ const worker = new Worker<DeployJobData>(
|
||||
});
|
||||
|
||||
if (!createRes.ok) throw new Error("Failed to create repository");
|
||||
|
||||
|
||||
repoDetails = await createRes.json();
|
||||
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
@@ -91,7 +97,7 @@ const worker = new Worker<DeployJobData>(
|
||||
|
||||
// 3. Prepare Batch File Operations
|
||||
const fileOperations = Object.entries(files).map(([path, content]) => ({
|
||||
operation: "upload",
|
||||
operation: "upload",
|
||||
path: path,
|
||||
content: Buffer.from(content as string).toString("base64"),
|
||||
}));
|
||||
@@ -119,7 +125,10 @@ const worker = new Worker<DeployJobData>(
|
||||
|
||||
await job.updateProgress(100);
|
||||
|
||||
const repoUrl = `${GITEA_API_URL.replace("/api/v1", "")}/${GITEA_USERNAME}/${sanitizedRepoName}`;
|
||||
const repoUrl = `${GITEA_API_URL.replace(
|
||||
"/api/v1",
|
||||
""
|
||||
)}/${GITEA_USERNAME}/${sanitizedRepoName}`;
|
||||
console.log(`[Job ${job.id}] Deployment Complete! 🚀 URL: ${repoUrl}`);
|
||||
|
||||
return { success: true, url: repoUrl };
|
||||
@@ -141,4 +150,4 @@ const worker = new Worker<DeployJobData>(
|
||||
// Listener for errors
|
||||
worker.on("failed", (job, err) => {
|
||||
console.error(`[Job ${job?.id}] Failed with error ${err.message}`);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user