diff options
author | HampusM <hampus@hampusmat.com> | 2021-06-22 13:31:43 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-06-22 13:31:43 +0200 |
commit | 43faf0bfd5544f9338e1442ab5b1fcb3210867ac (patch) | |
tree | 98ef97249f6a927b1cfba41b8a3587fd211a68e1 /packages/server/src/api/util.ts | |
parent | e59d40c2b662a570f679c133a7fe26d1b47edd89 (diff) |
Refactored the backend yet again & got eslint too work with typescript
Diffstat (limited to 'packages/server/src/api/util.ts')
-rw-r--r-- | packages/server/src/api/util.ts | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/packages/server/src/api/util.ts b/packages/server/src/api/util.ts index 1cc135f..b05ebb7 100644 --- a/packages/server/src/api/util.ts +++ b/packages/server/src/api/util.ts @@ -1,15 +1,16 @@ -import { GitAPI, RequestInfo } from "./git"; +import { GitAPI } from "./git"; +import { RequestInfo } from "./git_types"; import { readdir } from "fs"; type VerificationResultType = "SUCCESS" | "NOT_FOUND" | "INVALID" | "ACCESS_DENIED"; export class VerificationResult { constructor(result: VerificationResultType, subject?: string) { - this.success = result === "SUCCESS" ? true : false; + this.success = result === "SUCCESS"; if(result !== "SUCCESS") { const verification_error_types = { - NOT_FOUND: { code: 404, message: `${ String(subject?.substr(0, 1).toUpperCase()) + subject?.substr(1)} not found!` }, + NOT_FOUND: { code: 404, message: `${String(subject?.substr(0, 1).toUpperCase()) + subject?.substr(1)} not found!` }, INVALID: { code: 403, message: `Invalid ${subject}` }, ACCESS_DENIED: { code: 403, message: "Access denied!" } }; @@ -24,7 +25,7 @@ export class VerificationResult { message: string | null = null; } -export function verifyRepoName(base_dir: string, repo_name: string) { +export function verifyRepoName(base_dir: string, repo_name: string): Promise<VerificationResult> { return new Promise<VerificationResult>(resolve => { console.log(repo_name); const is_valid_repo_name = (/^[a-zA-Z0-9.\-_]+$/u).test(repo_name); @@ -50,7 +51,7 @@ export function verifyRepoName(base_dir: string, repo_name: string) { }); } -export async function verifySHA(git: GitAPI, repo_name: string, sha: string) { +export async function verifySHA(git: GitAPI, repo_name: string, sha: string): Promise<VerificationResult> { if(!(/^[a-fA-F0-9]+$/u).test(sha)) { return new VerificationResult("INVALID", "sha"); } @@ -64,7 +65,7 @@ export async function verifySHA(git: GitAPI, repo_name: string, sha: string) { return new VerificationResult("SUCCESS"); } -export function verifyGitRequest(request_info: RequestInfo) { +export function verifyGitRequest(request_info: RequestInfo): VerificationResult { if((/\.\/|\.\./u).test(request_info.parsed_url.pathname)) { return new VerificationResult("INVALID", "path"); } |