fix: deduplicate share target triggers across client and server
This commit is contained in:
1 parent
a99e05c53c
commit
efb3ecf1ae
3 files changed
+74
No files matched your search
@@ -164,6 +164,34 @@ export async function POST(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deduplication check: if a note with the exact same sourceUrl was created within the last 5 minutes, reuse it!
|
||||||
|
if (url) {
|
||||||
|
const recentDup = await prisma.note.findFirst({
|
||||||
|
where: {
|
||||||
|
userId,
|
||||||
|
sourceUrl: url,
|
||||||
|
createdAt: {
|
||||||
|
gte: new Date(Date.now() - 5 * 60 * 1000), // last 5 minutes
|
||||||
|
},
|
||||||
|
},
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
|
});
|
||||||
|
if (recentDup) {
|
||||||
|
const wantsJson =
|
||||||
|
contentType.includes('application/json') ||
|
||||||
|
Boolean(req.headers.get('accept')?.includes('application/json'));
|
||||||
|
|
||||||
|
if (isShareTarget && !wantsJson) {
|
||||||
|
return NextResponse.redirect(getRedirectUrl(req, recentDup.id), 303);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: true, noteId: recentDup.id, title: recentDup.title, mode: 'existing-recent' },
|
||||||
|
{ status: 200, headers: corsHeaders }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const notebookId = notebookName.trim()
|
const notebookId = notebookName.trim()
|
||||||
? await getOrCreateNotebookByName(notebookName.trim(), userId)
|
? await getOrCreateNotebookByName(notebookName.trim(), userId)
|
||||||
: (await ensureDefaultNotebook(userId)).id;
|
: (await ensureDefaultNotebook(userId)).id;
|
||||||
|
|||||||
@@ -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;
|
let noteId: string;
|
||||||
if (url && !text) {
|
if (url && !text) {
|
||||||
// Direct web clip
|
// 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 =
|
const wantsJson =
|
||||||
contentType.includes('application/json') ||
|
contentType.includes('application/json') ||
|
||||||
Boolean(req.headers.get('accept')?.includes('application/json'));
|
Boolean(req.headers.get('accept')?.includes('application/json'));
|
||||||
|
|||||||
@@ -516,6 +516,20 @@ export default function EvercloneWorkspace() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isWebClip = Boolean(extractedUrl && !cleanText);
|
const isWebClip = Boolean(extractedUrl && !cleanText);
|
||||||
|
|
||||||
|
const shareSig = `${extractedUrl || ''}#${cleanTitle || ''}#${cleanText || ''}`;
|
||||||
|
try {
|
||||||
|
const lastSig = localStorage.getItem('evc_last_share_sig');
|
||||||
|
const lastTime = Number(localStorage.getItem('evc_last_share_time') || 0);
|
||||||
|
if (lastSig === shareSig && Date.now() - lastTime < 180000) {
|
||||||
|
// Already processed this exact share recently (e.g. Android task restoration)
|
||||||
|
console.log('Skipping duplicate share target intent:', shareSig);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localStorage.setItem('evc_last_share_sig', shareSig);
|
||||||
|
localStorage.setItem('evc_last_share_time', String(Date.now()));
|
||||||
|
} catch {}
|
||||||
|
|
||||||
setShareToast(isWebClip ? 'Clipping web article to Everclone...' : 'Saving note to Everclone...');
|
setShareToast(isWebClip ? 'Clipping web article to Everclone...' : 'Saving note to Everclone...');
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user