Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev committed Jul 16, 2024
1 parent a878f5f commit 10c321c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
41 changes: 23 additions & 18 deletions apps/backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,27 +235,32 @@ const routes: FastifyPluginCallback = (instance, _opts, done) => {
}
});

instance.post("/diffs", async (request, reply) => {
const body = parseDiffCreationBody(request.body);
instance.post<{ Reply: ApiResponse<{ id: string; iv: string }> }>(
"/diffs",
async (request, reply) => {
const body = parseDiffCreationBody(request.body);

const iv = randomBytes(16);
const key = Buffer.from(environment.ENCRYPTION_KEY, "base64url");
const iv = randomBytes(16);
const key = Buffer.from(environment.ENCRYPTION_KEY, "base64url");

const codeDiff = await prisma.codeDiff.create({
data: {
name: body.name,
source: body.source,
diffs: encryptWithIv(
"aes-256-cbc",
{ key, iv },
Buffer.from(JSON.stringify(body.diffs)),
).toString("base64url"),
},
});
const codeDiff = await prisma.codeDiff.create({
data: {
name: body.name,
source: body.source,
diffs: encryptWithIv(
"aes-256-cbc",
{ key, iv },
Buffer.from(JSON.stringify(body.diffs)),
).toString("base64url"),
},
});

reply.type("application/json").code(200);
return { id: codeDiff.id, iv: iv.toString("base64url") };
});
return reply
.type("application/json")
.code(200)
.send({ id: codeDiff.id, iv: iv.toString("base64url") });
},
);

instance.post<{
Reply: { html_url: string };
Expand Down
26 changes: 13 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 10c321c

Please sign in to comment.