From 4330bdcc4c38eef690ca441b828d1ac42c085dc0 Mon Sep 17 00:00:00 2001 From: diced Date: Fri, 12 Jul 2024 12:22:01 -0700 Subject: [PATCH] fix: increment views on view/code routes (#572) --- src/pages/code/[id].tsx | 11 +++++++++++ src/pages/view/[id].tsx | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/pages/code/[id].tsx b/src/pages/code/[id].tsx index e4cbc99ea..b3ac08c04 100644 --- a/src/pages/code/[id].tsx +++ b/src/pages/code/[id].tsx @@ -115,6 +115,17 @@ export const getServerSideProps: GetServerSideProps = async (context) => { renderType = null; } + await prisma.file.update({ + where: { + id: file.id, + }, + data: { + views: { + increment: 1, + }, + }, + }); + return { props: { code: await streamToString(data), diff --git a/src/pages/view/[id].tsx b/src/pages/view/[id].tsx index a5de26dae..78ee7d2ea 100644 --- a/src/pages/view/[id].tsx +++ b/src/pages/view/[id].tsx @@ -276,6 +276,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { delete user.password; delete user.totpSecret; delete user.token; + delete user.ratelimit; // @ts-ignore workaround because next wont allow date file.createdAt = file.createdAt.toString(); @@ -324,6 +325,17 @@ export const getServerSideProps: GetServerSideProps = async (context) => { // @ts-ignore if (file.password) file.password = true; + await prisma.file.update({ + where: { + id: file.id, + }, + data: { + views: { + increment: 1, + }, + }, + }); + return { props: { file,