Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { SESSION_COOKIE } from "@/const";
- import { db, noteAttachmentBucket, noteCollection } from "@/models/name";
- import { createSessionClient } from "@/models/server/config";
- import { NextRequest, NextResponse } from "next/server";
- export async function GET(req: NextRequest) {
- try {
- const note_id = req.nextUrl.searchParams.get("note_id")
- if (!note_id) {
- return NextResponse.json({
- success: false,
- error: "Note ID is required"
- }, { status: 400 })
- }
- const session = req.cookies.get(SESSION_COOKIE)
- if (!session || !session.value) {
- return NextResponse.json({
- success: false,
- error: "Unauthorized"
- }, { status: 401 })
- }
- const { databases, storage } = await createSessionClient(session)
- const note = await databases.getDocument(db, noteCollection, note_id)
- if (!note) {
- return NextResponse.json({
- success: false,
- error: "Note not found"
- }, { status: 404 })
- }
- const viewFile = await storage.getFileView(noteAttachmentBucket, note.file_id)
- return NextResponse.json({
- success: true,
- noteData: {
- title: note.title,
- description: note.description,
- subject: note.subject,
- tags: note.tags,
- }
- })
- }
- catch (err) {
- return NextResponse.json({
- success: false,
- error: "Internal server error"
- }, { status: 500 })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement