forked from AuroraTeam/AuroraLauncher
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
212 additions
and
184 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,17 @@ | ||
import { IncomingMessage, ServerResponse } from "http" | ||
|
||
import { JsonHelper } from "../../../helpers/JsonHelper" | ||
|
||
export abstract class AbstractRequest { | ||
abstract readonly url: RegExp | ||
abstract readonly method: string | ||
|
||
abstract emit(req: IncomingMessage, res: ServerResponse): PromiseOr<void> | ||
|
||
protected parseQuery(url: string): URLSearchParams { | ||
return new URLSearchParams(url.split("?")[1]) | ||
} | ||
|
||
protected isEmptyQuery(query: URLSearchParams): boolean { | ||
return query.toString().length === 0 | ||
} | ||
|
||
public returnError(error: string, errorMessage?: string): string { | ||
return JsonHelper.toJSON({ error, errorMessage }) | ||
} | ||
// КХЪ Похоже что нужно рефакторить некоторе говно | ||
public static returnError(error: string, errorMessage?: string): string { | ||
return JsonHelper.toJSON({ error, errorMessage }) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
protected isInvalidValue(param: any): boolean { | ||
return typeof param !== "string" || param.trim().length === 0 | ||
} | ||
|
||
protected getPostData(req: IncomingMessage): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
let data = "" | ||
req.on("data", (chunk) => { | ||
data += chunk | ||
}) | ||
req.on("end", () => { | ||
resolve(data) | ||
}) | ||
req.on("error", (error) => { | ||
reject(error) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.