Updates
This commit is contained in:
@@ -1,23 +1,16 @@
|
||||
import loginUser from "@/src/functions/auth/login-user";
|
||||
import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types";
|
||||
import userAuth from "@/src/utils/user-auth";
|
||||
import NSQLite from "@moduletrace/nsqlite";
|
||||
import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/types";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { APIReqObject } from "@/src/types";
|
||||
import { createReadStream, existsSync } from "fs";
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<APIResponseObject>,
|
||||
) {
|
||||
try {
|
||||
if (req.method !== "POST") {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Method",
|
||||
});
|
||||
}
|
||||
|
||||
const { singleRes: user } = await userAuth({ req });
|
||||
|
||||
if (!user?.id || !user.super_admin) {
|
||||
@@ -37,9 +30,19 @@ export default async function handler(
|
||||
|
||||
const target_user = target_user_res.singleRes;
|
||||
|
||||
const updated = await loginUser({ res, user_id: user.id });
|
||||
if (!target_user?.username) {
|
||||
throw new Error(`Couldn't grab user`);
|
||||
}
|
||||
|
||||
return res.json(updated);
|
||||
const file_path = `/home/${target_user.username}/.ssh/${target_user.username}`;
|
||||
|
||||
if (!existsSync(file_path)) {
|
||||
throw new Error(`No Private SSH key file found`);
|
||||
}
|
||||
|
||||
const read_stream = createReadStream(file_path);
|
||||
|
||||
read_stream.pipe(res);
|
||||
} catch (error: any) {
|
||||
return res.json({ success: false, msg: error.message });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user