fix: Fixes various issues related to backends.
This fixes not providing the correct parameters on the backend to create correctly, as well as fixes crashes when the backend class fails to be instantiated. :3
This commit is contained in:
parent
3b55ce1207
commit
b9c05e6196
2 changed files with 18 additions and 9 deletions
|
@ -2,8 +2,8 @@ import { format } from "node:util";
|
||||||
|
|
||||||
import type { PrismaClient } from "@prisma/client";
|
import type { PrismaClient } from "@prisma/client";
|
||||||
|
|
||||||
import type { BackendBaseClass } from "../backendimpl/base.js";
|
|
||||||
import { backendProviders } from "../backendimpl/index.js";
|
import { backendProviders } from "../backendimpl/index.js";
|
||||||
|
import { BackendBaseClass } from "../backendimpl/base.js";
|
||||||
|
|
||||||
type Backend = {
|
type Backend = {
|
||||||
id: number;
|
id: number;
|
||||||
|
@ -30,6 +30,16 @@ export async function backendInit(
|
||||||
|
|
||||||
if (!ourProvider) {
|
if (!ourProvider) {
|
||||||
error(" - Error: Invalid backend recieved!");
|
error(" - Error: Invalid backend recieved!");
|
||||||
|
|
||||||
|
// Prevent crashes when we don't recieve a backend
|
||||||
|
backends[backend.id] = new BackendBaseClass("");
|
||||||
|
|
||||||
|
backends[backend.id].logs.push("** Failed To Create Backend **");
|
||||||
|
|
||||||
|
backends[backend.id].logs.push(
|
||||||
|
"Reason: Invalid backend recieved (couldn't find the backend to use!)",
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ export function route(routeOptions: RouteOptions) {
|
||||||
name: { type: "string" },
|
name: { type: "string" },
|
||||||
description: { type: "string" },
|
description: { type: "string" },
|
||||||
backend: { type: "string" },
|
backend: { type: "string" },
|
||||||
|
connectionDetails: { type: "string" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -43,7 +44,7 @@ export function route(routeOptions: RouteOptions) {
|
||||||
token: string;
|
token: string;
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
connectionDetails: unknown;
|
connectionDetails: string;
|
||||||
backend: string;
|
backend: string;
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
|
@ -55,15 +56,13 @@ export function route(routeOptions: RouteOptions) {
|
||||||
|
|
||||||
if (!backendProviders[body.backend]) {
|
if (!backendProviders[body.backend]) {
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
error: "Unknown/unsupported/deprecated backend!",
|
error: "Unsupported backend!",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectionDetails = JSON.stringify(body.connectionDetails);
|
const connectionDetailsValidityCheck = backendProviders[
|
||||||
const connectionDetailsValidityCheck =
|
body.backend
|
||||||
backendProviders[body.backend].checkParametersBackendInstance(
|
].checkParametersBackendInstance(body.connectionDetails);
|
||||||
connectionDetails,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!connectionDetailsValidityCheck.success) {
|
if (!connectionDetailsValidityCheck.success) {
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
|
@ -79,7 +78,7 @@ export function route(routeOptions: RouteOptions) {
|
||||||
description: body.description,
|
description: body.description,
|
||||||
|
|
||||||
backend: body.backend,
|
backend: body.backend,
|
||||||
connectionDetails: JSON.stringify(body.connectionDetails),
|
connectionDetails: body.connectionDetails,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue