-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloneRepoController.ts
More file actions
61 lines (61 loc) · 2.25 KB
/
cloneRepoController.ts
File metadata and controls
61 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Context } from "elysia";
import { StatusCode } from "../types/types";
import simpleGit from "simple-git";
import generateId from "../utils/generateId";
import checkUrl from "../utils/checkUrl";
import checkSize from "../utils/checkSize";
const cloneRepoController = async ({ body, set }: Context) => {
const req = body as { repoUrl: string,packageInstallerCommand?:string,buildCommand?:string,startCommand?:string,outputDir?:string,projectType?:string };
try {
if (!req.repoUrl) {
set.status = StatusCode.FORBIDDEN
return {
message: "Repository URL is required"
}
}
const isValidRepo = await checkUrl(req.repoUrl);
if (!isValidRepo) {
set.status = StatusCode.BAD_REQUEST
return {
message: "Invalid repository URL"
}
}
const isSizeValid = await checkSize(req.repoUrl);
if (!isSizeValid) {
set.status = StatusCode.BAD_REQUEST
return {
message: "Repository size exceeds the limit of 100MB"
}
}
const id = generateId();
await simpleGit().clone(req.repoUrl, `./cloned-repo/${id}`)
if(req.projectType==="PlainHTML"){
return {
message: "Repository cloned successfully",
repoId: id,
buildCommand: "",
startCommand: "",
outputDir: "",
projectType: req.projectType || "PlainHTML",
packageInstallerCommand: ""
}
}
return {
message: "Repository cloned successfully",
repoId: id,
buildCommand: req.buildCommand || "npm run build",
startCommand: req.startCommand || "npm start",
outputDir: req.outputDir || "dist",
projectType: req.projectType || "React",
packageInstallerCommand: req.packageInstallerCommand || "npm install"
}
} catch (error) {
console.error("Error in cloneRepoController:", error);
set.status = StatusCode.INTERNAL_SERVER_ERROR
return {
message: "Error working with repository",
error
}
}
}
export default cloneRepoController;