mirror of
https://github.com/outbackdingo/pangolin.git
synced 2026-01-27 18:20:04 +00:00
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
/*
|
|
* This file is part of a proprietary work.
|
|
*
|
|
* Copyright (c) 2025 Fossorial, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This file is licensed under the Fossorial Commercial License.
|
|
* You may not use this file except in compliance with the License.
|
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
|
*
|
|
* This file is not licensed under the AGPLv3.
|
|
*/
|
|
|
|
import { Request, Response, NextFunction } from "express";
|
|
import response from "@server/lib/response";
|
|
import HttpCode from "@server/types/HttpCode";
|
|
import createHttpError from "http-errors";
|
|
import logger from "@server/logger";
|
|
import { generateId } from "@server/auth/sessions/app";
|
|
import { fromError } from "zod-validation-error";
|
|
import { z } from "zod";
|
|
import { PickRemoteExitNodeDefaultsResponse } from "@server/routers/remoteExitNode/types";
|
|
|
|
const paramsSchema = z
|
|
.object({
|
|
orgId: z.string()
|
|
})
|
|
.strict();
|
|
|
|
export async function pickRemoteExitNodeDefaults(
|
|
req: Request,
|
|
res: Response,
|
|
next: NextFunction
|
|
): Promise<any> {
|
|
try {
|
|
const parsedParams = paramsSchema.safeParse(req.params);
|
|
if (!parsedParams.success) {
|
|
return next(
|
|
createHttpError(
|
|
HttpCode.BAD_REQUEST,
|
|
fromError(parsedParams.error).toString()
|
|
)
|
|
);
|
|
}
|
|
|
|
const { orgId } = parsedParams.data;
|
|
|
|
const remoteExitNodeId = generateId(15);
|
|
const secret = generateId(48);
|
|
|
|
return response<PickRemoteExitNodeDefaultsResponse>(res, {
|
|
data: {
|
|
remoteExitNodeId,
|
|
secret
|
|
},
|
|
success: true,
|
|
error: false,
|
|
message: "Organization retrieved successfully",
|
|
status: HttpCode.OK
|
|
});
|
|
} catch (error) {
|
|
logger.error(error);
|
|
return next(
|
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
|
);
|
|
}
|
|
}
|