Skip to content

Commit

Permalink
fix: increment views on view/code routes (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
diced committed Jul 12, 2024
1 parent 7f9de82 commit 4330bdc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pages/code/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
12 changes: 12 additions & 0 deletions src/pages/view/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4330bdc

Please sign in to comment.