feature: Adds eslint rules.
This commit is contained in:
parent
09f7987e75
commit
3c95c23369
26 changed files with 124 additions and 95 deletions
|
@ -2,9 +2,18 @@ import globals from "globals";
|
|||
import pluginJs from "@eslint/js";
|
||||
import tseslint from "typescript-eslint";
|
||||
|
||||
|
||||
export default [
|
||||
{languageOptions: { globals: globals.node }},
|
||||
pluginJs.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
|
||||
{
|
||||
languageOptions: {
|
||||
globals: globals.node
|
||||
},
|
||||
|
||||
rules: {
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "off"
|
||||
}
|
||||
},
|
||||
];
|
|
@ -55,7 +55,7 @@ function parseBackendProviderString(data: string): BackendParsedProviderString {
|
|||
|
||||
if (typeof jsonData.ip != "string")
|
||||
throw new Error("IP field is not a string");
|
||||
|
||||
|
||||
if (typeof jsonData.port != "number") throw new Error("Port is not a number");
|
||||
|
||||
if (
|
||||
|
@ -63,7 +63,7 @@ function parseBackendProviderString(data: string): BackendParsedProviderString {
|
|||
typeof jsonData.publicPort != "number"
|
||||
)
|
||||
throw new Error("(optional field) Proxied port is not a number");
|
||||
|
||||
|
||||
if (
|
||||
typeof jsonData.isProxied != "undefined" &&
|
||||
typeof jsonData.isProxied != "boolean"
|
||||
|
@ -216,7 +216,7 @@ export class PassyFireBackendProvider implements BackendBaseClass {
|
|||
static checkParametersBackendInstance(data: string): ParameterReturnedValue {
|
||||
try {
|
||||
parseBackendProviderString(data);
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: We write the function, and we know we're returning an error
|
||||
} catch (e: Error) {
|
||||
return {
|
||||
success: false,
|
||||
|
|
|
@ -69,7 +69,7 @@ export function route(instance: PassyFireBackendProvider) {
|
|||
},
|
||||
},
|
||||
(req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
username: string;
|
||||
password: string;
|
||||
|
@ -115,7 +115,7 @@ export function route(instance: PassyFireBackendProvider) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
} = req.body;
|
||||
|
@ -132,8 +132,7 @@ export function route(instance: PassyFireBackendProvider) {
|
|||
req.hostname.indexOf(":") + 1,
|
||||
);
|
||||
|
||||
// @ts-expect-error
|
||||
// parseInt(...) can take a number just fine, at least in Node.JS
|
||||
// @ts-expect-error: parseInt(...) can take a number just fine, at least in Node.JS
|
||||
const port = parseInt(unparsedPort == "" ? proxiedPort : unparsedPort);
|
||||
|
||||
// This protocol is so confusing. I'm sorry.
|
||||
|
|
|
@ -14,7 +14,7 @@ function authenticateSocket(
|
|||
ws: WebSocket,
|
||||
message: string,
|
||||
state: ConnectedClientExt,
|
||||
): Boolean {
|
||||
): boolean {
|
||||
if (!message.startsWith("Accept: ")) {
|
||||
ws.send("400 Bad Request");
|
||||
return false;
|
||||
|
@ -57,8 +57,8 @@ export function requestHandler(
|
|||
let state: "authentication" | "data" = "authentication";
|
||||
let socket: dgram.Socket | net.Socket | undefined;
|
||||
|
||||
// @ts-expect-error
|
||||
let connectedClient: ConnectedClientExt = {};
|
||||
// @ts-expect-error: FIXME because this is a mess
|
||||
const connectedClient: ConnectedClientExt = {};
|
||||
|
||||
ws.on("close", () => {
|
||||
instance.clients.splice(
|
||||
|
|
|
@ -92,7 +92,7 @@ export class SSHBackendProvider implements BackendBaseClass {
|
|||
this.logs.push(`Failed to start SSHBackendProvider! Error: '${e}'`);
|
||||
this.state = "stopped";
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: We know that stuff will be initialized in order, so this will be safe
|
||||
this.sshInstance = null;
|
||||
|
||||
return false;
|
||||
|
@ -112,7 +112,7 @@ export class SSHBackendProvider implements BackendBaseClass {
|
|||
|
||||
this.sshInstance.dispose();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: We know that stuff will be initialized in order, so this will be safe
|
||||
this.sshInstance = null;
|
||||
|
||||
this.logs.push("Successfully stopped SSHBackendProvider.");
|
||||
|
@ -255,7 +255,7 @@ export class SSHBackendProvider implements BackendBaseClass {
|
|||
static checkParametersBackendInstance(data: string): ParameterReturnedValue {
|
||||
try {
|
||||
parseBackendProviderString(data);
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: We write the function, and we know we're returning an error
|
||||
} catch (e: Error) {
|
||||
return {
|
||||
success: false,
|
||||
|
|
|
@ -35,12 +35,12 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
connectionDetails: any;
|
||||
connectionDetails: unknown;
|
||||
backend: string;
|
||||
} = req.body;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
id?: number;
|
||||
|
@ -69,7 +69,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
success: true,
|
||||
data: prismaBackends.map(i => ({
|
||||
id: i.id,
|
||||
|
||||
|
||||
name: i.name,
|
||||
description: i.description,
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
id: number;
|
||||
|
|
|
@ -27,7 +27,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
id: number;
|
||||
|
@ -59,8 +59,12 @@ export function route(routeOptions: RouteOptions) {
|
|||
|
||||
return {
|
||||
success: true,
|
||||
data: backends[forward.destProviderID].getAllConnections().filter((i) => {
|
||||
return i.connectionDetails.sourceIP == forward.sourceIP && i.connectionDetails.sourcePort == forward.sourcePort && i.connectionDetails.destPort == forward.destPort;
|
||||
data: backends[forward.destProviderID].getAllConnections().filter(i => {
|
||||
return (
|
||||
i.connectionDetails.sourceIP == forward.sourceIP &&
|
||||
i.connectionDetails.sourcePort == forward.sourcePort &&
|
||||
i.connectionDetails.destPort == forward.destPort
|
||||
);
|
||||
}),
|
||||
};
|
||||
},
|
||||
|
|
|
@ -50,7 +50,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
id: number;
|
||||
|
|
|
@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
id: number;
|
||||
|
@ -58,8 +58,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
error: "Backend not found",
|
||||
});
|
||||
|
||||
// Other restrictions in place make it so that it MUST be either TCP or UDP
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Other restrictions in place make it so that it MUST be either TCP or UDP
|
||||
const protocol: "tcp" | "udp" = forward.protocol;
|
||||
|
||||
backends[forward.destProviderID].addConnection(
|
||||
|
|
|
@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
id: number;
|
||||
|
@ -58,8 +58,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
error: "Backend not found",
|
||||
});
|
||||
|
||||
// Other restrictions in place make it so that it MUST be either TCP or UDP
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Other restrictions in place make it so that it MUST be either TCP or UDP
|
||||
const protocol: "tcp" | "udp" = forward.protocol;
|
||||
|
||||
backends[forward.destProviderID].removeConnection(
|
||||
|
|
|
@ -22,7 +22,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
} = req.body;
|
||||
|
|
|
@ -29,7 +29,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
name: string;
|
||||
email: string;
|
||||
|
@ -87,9 +87,9 @@ export function route(routeOptions: RouteOptions) {
|
|||
}
|
||||
|
||||
if (options.allowUnsafeGlobalTokens) {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Setting this correctly is a goddamn mess, but this is safe to an extent. It won't crash at least
|
||||
userData.rootToken = generateRandomData();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Read above.
|
||||
userData.isRootServiceAccount = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,27 +20,28 @@ export function route(routeOptions: RouteOptions) {
|
|||
properties: {
|
||||
email: { type: "string" },
|
||||
username: { type: "string" },
|
||||
password: { type: "string" }
|
||||
password: { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
email?: string;
|
||||
username?: string;
|
||||
password: string;
|
||||
} = req.body;
|
||||
|
||||
if (!body.email && !body.username) return res.status(400).send({
|
||||
error: "missing both email and username. please supply at least one."
|
||||
});
|
||||
if (!body.email && !body.username)
|
||||
return res.status(400).send({
|
||||
error: "missing both email and username. please supply at least one.",
|
||||
});
|
||||
|
||||
const userSearch = await prisma.user.findFirst({
|
||||
where: {
|
||||
email: body.email,
|
||||
username: body.username
|
||||
username: body.username,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
id?: number;
|
||||
|
@ -64,7 +64,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
name: i.name,
|
||||
email: i.email,
|
||||
isServiceAccount: i.isRootServiceAccount,
|
||||
username: i.username
|
||||
username: i.username,
|
||||
})),
|
||||
};
|
||||
},
|
||||
|
|
|
@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
|
||||
const body: {
|
||||
token: string;
|
||||
uid: number;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue