-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from Sid-80/feat/462
Feat/462
- Loading branch information
Showing
8 changed files
with
132 additions
and
99 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { mongoDB } from "@/lib/MongoDB"; | ||
import { AuthMiddleware } from "@/Middleware/AuthMiddleware"; | ||
import FileModel from "@/models/file"; | ||
import { ApiUser } from "@/types/types"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function PUT( | ||
request: Request | ||
) { | ||
|
||
const result = await AuthMiddleware(request); | ||
|
||
if (result instanceof NextResponse) { | ||
|
||
try { | ||
await mongoDB(); | ||
|
||
const {fileName, filePrivate, fileId, archive} = await request.json() | ||
console.log(fileName, filePrivate, fileId, archive) | ||
|
||
if(!fileName || filePrivate === undefined || archive === undefined || !fileId){ | ||
return NextResponse.json(`Access Denied!!`, {status:404}); | ||
} | ||
|
||
const user: ApiUser = JSON.parse(request.headers.get("user") || "{}"); | ||
|
||
const file = await FileModel.findById({_id:fileId}); | ||
|
||
if(file.createdBy !== user._id && !file.writtenBy.includes(user._id)){ | ||
return NextResponse.json(`Access Denied!!`, {status:401}); | ||
} | ||
|
||
await FileModel.updateOne({_id:fileId},{ | ||
fileName, | ||
filePrivate, | ||
archive | ||
}) | ||
|
||
return NextResponse.json('',{status:200}); | ||
} catch (err) { | ||
return NextResponse.json(`Err : ${err}`, {status:500}); | ||
} | ||
} else { | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.