From fa54e4173bab9f58c257687fa7d871d01bff9924 Mon Sep 17 00:00:00 2001 From: Shahab Dad Date: Thu, 20 Aug 2026 21:59:48 +0500 Subject: [PATCH] get method --- .../[...nextauth]/{router.ts => route.ts} | 0 app/api/auth/register/{router.ts => route.ts} | 0 app/api/imagekit-auth/route.ts | 25 +++++++++++++++++++ app/video/route.ts | 19 ++++++++++++++ package-lock.json | 23 ++++++++++++++--- package.json | 1 + 6 files changed, 65 insertions(+), 3 deletions(-) rename app/api/auth/[...nextauth]/{router.ts => route.ts} (100%) rename app/api/auth/register/{router.ts => route.ts} (100%) create mode 100644 app/api/imagekit-auth/route.ts create mode 100644 app/video/route.ts diff --git a/app/api/auth/[...nextauth]/router.ts b/app/api/auth/[...nextauth]/route.ts similarity index 100% rename from app/api/auth/[...nextauth]/router.ts rename to app/api/auth/[...nextauth]/route.ts diff --git a/app/api/auth/register/router.ts b/app/api/auth/register/route.ts similarity index 100% rename from app/api/auth/register/router.ts rename to app/api/auth/register/route.ts diff --git a/app/api/imagekit-auth/route.ts b/app/api/imagekit-auth/route.ts new file mode 100644 index 0000000..ee853ef --- /dev/null +++ b/app/api/imagekit-auth/route.ts @@ -0,0 +1,25 @@ + +import { getUploadAuthParams } from "@imagekit/next/server" + +export async function GET() { + + try { + const authenticationParameters = getUploadAuthParams({ + privateKey: process.env.IMAGEKIT_PRIVATE_KEY as string, + publicKey: process.env.NEXT_PUBLIC_IMAGEKIT_PUBLIC_KEY as string, + + }) + + return Response.json({ + authenticationParameters, + publicKey: process.env.NEXT_PUBLIC_IMAGEKIT_PUBLIC_KEY, + }) + } catch { + return Response.json( + { + error: "Authentication for Imagekit failed" + }, + { status: 500 } + ) + } +} \ No newline at end of file diff --git a/app/video/route.ts b/app/video/route.ts new file mode 100644 index 0000000..74e1a78 --- /dev/null +++ b/app/video/route.ts @@ -0,0 +1,19 @@ +import { connectToDatabase } from "@/lib/db"; +import Video from "@/models/Video"; +import { NextResponse } from "next/server"; + +export async function GET() { + try { + await connectToDatabase() + const videos = await Video.find({}).sort({createdAt:-1}).lean() + if(!videos || videos.length === 0) { + return NextResponse.json([], {status: 200}) + } + return NextResponse.json(videos) + + } catch (error) { + return NextResponse.json( + {error:"Failed to fetch videos"}, + {status:500}) + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d023e56..1edd0b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "nextjs-full-stack-video", "version": "0.1.0", "dependencies": { + "@imagekit/next": "^2.1.5", "bcryptjs": "^3.0.3", "mongoose": "^9.9.1", "next": "16.3.0", @@ -510,6 +511,24 @@ "url": "https://github.com/sponsors/nzakas" } }, + "node_modules/@imagekit/javascript": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/@imagekit/javascript/-/javascript-5.4.1.tgz", + "integrity": "sha512-x29Yklu12sGtLh7aihSpmi6z09M+FJ+iWFSPZkq1b5ALf6pqZFUq49Rip9Y5qqn/KAxRz7bzmbV7APNIn9vq3A==", + "license": "Apache-2.0" + }, + "node_modules/@imagekit/next": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@imagekit/next/-/next-2.1.5.tgz", + "integrity": "sha512-fvUEqAcq+krrMvn9Yb9fiq6q6ezbVuHvcvJJ606PzmaeBPFcsTU0FZAWW9TRr0cyj4i+4RfzurSy4GfK9RwjOg==", + "license": "MIT", + "dependencies": { + "@imagekit/javascript": "^5.1.0" + }, + "peerDependencies": { + "next": ">= 13" + } + }, "node_modules/@img/colour": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz", @@ -5369,6 +5388,7 @@ "resolved": "https://registry.npmjs.org/next/-/next-16.3.0.tgz", "integrity": "sha512-NEdGOzH+08eTXMUp9UYkA99Nhi5N6Thrhc1jgFOQgfgnGK/dA2hRwBpXep+exdFQrnwlRf/3Wixyp8lLBUpE2A==", "license": "MIT", + "peer": true, "dependencies": { "@next/env": "16.3.0", "@swc/helpers": "0.5.15", @@ -6984,7 +7004,6 @@ "punycode": "^2.1.0" } }, -<<<<<<< HEAD "node_modules/uuid": { "version": "11.1.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.1.tgz", @@ -6998,8 +7017,6 @@ "uuid": "dist/esm/bin/uuid" } }, -======= ->>>>>>> f5286cf (Initial commit: full-stack video app setup) "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/package.json b/package.json index 4bbd6c1..5d4aa5a 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "lint": "eslint" }, "dependencies": { + "@imagekit/next": "^2.1.5", "bcryptjs": "^3.0.3", "mongoose": "^9.9.1", "next": "16.3.0",