Revert "refactor: stash"

This reverts commit d256998677.
This commit is contained in:
Mauricio Siu
2024-10-02 22:37:14 -06:00
parent d256998677
commit f13e5d449c
32 changed files with 293 additions and 4023 deletions

View File

@@ -6,10 +6,14 @@ import {
type apiUpdateSshKey,
sshKeys,
} from "@/server/db/schema";
import { removeSSHKey, saveSSHKey } from "@/server/utils/filesystem/ssh";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
export const createSshKey = async (input: typeof apiCreateSshKey._type) => {
export const createSshKey = async ({
privateKey,
...input
}: typeof apiCreateSshKey._type) => {
await db.transaction(async (tx) => {
const sshKey = await tx
.insert(sshKeys)
@@ -18,6 +22,10 @@ export const createSshKey = async (input: typeof apiCreateSshKey._type) => {
.then((response) => response[0])
.catch((e) => console.error(e));
if (sshKey) {
saveSSHKey(sshKey.sshKeyId, sshKey.publicKey, privateKey);
}
if (!sshKey) {
throw new TRPCError({
code: "BAD_REQUEST",
@@ -36,6 +44,8 @@ export const removeSSHKeyById = async (
.where(eq(sshKeys.sshKeyId, sshKeyId))
.returning();
removeSSHKey(sshKeyId);
return result[0];
};