fix: deduplicate share target triggers across client and server

This commit is contained in:
chrisf committed 2026-10-22 21:02:43 -06:00
1 parent a99e05c53c
commit efb3ecf1ae
3 files changed
+74

No files matched your search

+32
View File
@@ -86,6 +86,22 @@ export async function GET(req: NextRequest) {
}
}
if (url) {
const recentDup = await prisma.note.findFirst({
where: {
userId,
sourceUrl: url,
createdAt: {
gte: new Date(Date.now() - 5 * 60 * 1000),
},
},
orderBy: { createdAt: 'desc' },
});
if (recentDup) {
return NextResponse.redirect(getRedirectUrl(req, recentDup.id), 303);
}
}
let noteId: string;
if (url && !text) {
// Direct web clip
@@ -205,6 +221,22 @@ export async function POST(req: NextRequest) {
}
}
if (url) {
const recentDup = await prisma.note.findFirst({
where: {
userId,
sourceUrl: url,
createdAt: {
gte: new Date(Date.now() - 5 * 60 * 1000),
},
},
orderBy: { createdAt: 'desc' },
});
if (recentDup) {
return NextResponse.redirect(getRedirectUrl(req, recentDup.id), 303);
}
}
const wantsJson =
contentType.includes('application/json') ||
Boolean(req.headers.get('accept')?.includes('application/json'));