From bd40c5f988e6959980d8f4d258ebce1d311b517f Mon Sep 17 00:00:00 2001 From: Soham Sen Date: Fri, 9 Jun 2023 01:15:28 +0530 Subject: [PATCH] Increment read count & remove authorIp --- .../20230608194458_remove_author_ip_paste/migration.sql | 8 ++++++++ src/lib/server/prisma/schema.prisma | 1 - src/routes/[key]/+page.server.ts | 5 +++++ src/routes/api/create/+server.ts | 1 - 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/lib/server/prisma/migrations/20230608194458_remove_author_ip_paste/migration.sql diff --git a/src/lib/server/prisma/migrations/20230608194458_remove_author_ip_paste/migration.sql b/src/lib/server/prisma/migrations/20230608194458_remove_author_ip_paste/migration.sql new file mode 100644 index 0000000..0381cbc --- /dev/null +++ b/src/lib/server/prisma/migrations/20230608194458_remove_author_ip_paste/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - You are about to drop the column `authorIp` on the `Paste` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "Paste" DROP COLUMN "authorIp"; diff --git a/src/lib/server/prisma/schema.prisma b/src/lib/server/prisma/schema.prisma index 2dd4bd6..ec3ba54 100644 --- a/src/lib/server/prisma/schema.prisma +++ b/src/lib/server/prisma/schema.prisma @@ -14,7 +14,6 @@ model Paste { id BigInt @id @default(autoincrement()) createdAt DateTime @default(now()) key String @unique - authorIp String content String encrypted Boolean @default(false) language String @default("plaintext") diff --git a/src/routes/[key]/+page.server.ts b/src/routes/[key]/+page.server.ts index 781fd07..c17555b 100644 --- a/src/routes/[key]/+page.server.ts +++ b/src/routes/[key]/+page.server.ts @@ -15,6 +15,11 @@ export async function load({ params }) { if (!data) throw error(404, 'Not found'); + await prisma.paste.update({ + where: { key }, + data: { readCount: { increment: 1 } } + }); + let { content, language, encrypted } = data; let contentHtml: string; diff --git a/src/routes/api/create/+server.ts b/src/routes/api/create/+server.ts index 9823c83..e86323e 100644 --- a/src/routes/api/create/+server.ts +++ b/src/routes/api/create/+server.ts @@ -21,7 +21,6 @@ export async function POST({ request, getClientAddress }) { await prisma.paste.create({ data: { key, - authorIp: getClientAddress(), content, language: config.language, encrypted: config.encrypted