-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update link routes and add shared_access post api to get the user det…
…ails from shared linkl
- Loading branch information
1 parent
d050394
commit cb1feec
Showing
3 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import LinkService from '@/services/linkService'; | ||
import prisma from '@lib/prisma'; | ||
|
||
export async function POST(req: NextRequest): Promise<NextResponse> { | ||
try { | ||
const { linkId, first_name, last_name, email, password } = await req.json(); | ||
|
||
if (!linkId || !first_name || !last_name || !email || !password) { | ||
return createErrorResponse('Link ID, firstName, lastName, email and password are required.', 400); | ||
} | ||
|
||
const link = await prisma.link.findUnique({ | ||
where: { id: linkId }, | ||
}); | ||
|
||
if (!link) { | ||
return createErrorResponse('Link not found.', 404); | ||
} | ||
|
||
if (!link.hasSharingOptions) { | ||
return createErrorResponse('This link does not require sharing options.', 400); | ||
} | ||
|
||
if (password !== link.password) { | ||
return createErrorResponse('Password invalid.', 403); | ||
} | ||
|
||
const linkRecipient = await prisma.linkRecipients.create({ | ||
data: { | ||
linkId, | ||
first_name, | ||
last_name, | ||
} | ||
}); | ||
|
||
const signedUrl = await LinkService.getFileFromLink(linkId); | ||
return NextResponse.json({ message: 'Link URL generated', data: { signedUrl } }, { status: 200 }); | ||
} catch (error) { | ||
return createErrorResponse('Server error.', 500, error); | ||
} | ||
} | ||
|
||
function createErrorResponse(message: string, status: number, details?: any) { | ||
if (Array.isArray(details) && details.length === 2) { | ||
const [errorCode, errorMessage] = details; | ||
console.error(`[${new Date().toISOString()}] ${errorMessage}`, details); | ||
return NextResponse.json({ error: errorMessage, details }, { status: errorCode }); | ||
} else { | ||
console.error(`[${new Date().toISOString()}] ${message}`, details); | ||
return NextResponse.json({ error: message, details }, { status }); | ||
} | ||
} |
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