fix: extract URL and headline from Android share target, trigger article clipping and open editor
This commit is contained in:
1 parent
94fb793f99
commit
a99e05c53c
3 files changed
+191
-27
No files matched your search
@@ -56,10 +56,35 @@ export async function GET(req: NextRequest) {
|
||||
text = extracted.remainingText;
|
||||
}
|
||||
}
|
||||
if (!url && title) {
|
||||
const extracted = extractUrl(title);
|
||||
if (extracted.extractedUrl) {
|
||||
url = extracted.extractedUrl;
|
||||
title = extracted.remainingText;
|
||||
}
|
||||
}
|
||||
if (!url && title && /^https?:\/\/\S+$/i.test(title)) {
|
||||
url = title;
|
||||
title = '';
|
||||
}
|
||||
if (url) {
|
||||
url = url.replace(/[.,;:)\]]+$/, '');
|
||||
}
|
||||
if (url && text) {
|
||||
const remaining = text.replace(url, '').trim();
|
||||
if (
|
||||
!remaining ||
|
||||
remaining === title ||
|
||||
title.includes(remaining) ||
|
||||
remaining.includes(title) ||
|
||||
(!remaining.includes('\n') && remaining.length < 300)
|
||||
) {
|
||||
if (!title && remaining) {
|
||||
title = remaining;
|
||||
}
|
||||
text = '';
|
||||
}
|
||||
}
|
||||
|
||||
let noteId: string;
|
||||
if (url && !text) {
|
||||
@@ -150,10 +175,39 @@ export async function POST(req: NextRequest) {
|
||||
text = extracted.remainingText;
|
||||
}
|
||||
}
|
||||
if (!url && title) {
|
||||
const extracted = extractUrl(title);
|
||||
if (extracted.extractedUrl) {
|
||||
url = extracted.extractedUrl;
|
||||
title = extracted.remainingText;
|
||||
}
|
||||
}
|
||||
if (!url && title && /^https?:\/\/\S+$/i.test(title)) {
|
||||
url = title;
|
||||
title = '';
|
||||
}
|
||||
if (url) {
|
||||
url = url.replace(/[.,;:)\]]+$/, '');
|
||||
}
|
||||
if (url && text) {
|
||||
const remaining = text.replace(url, '').trim();
|
||||
if (
|
||||
!remaining ||
|
||||
remaining === title ||
|
||||
title.includes(remaining) ||
|
||||
remaining.includes(title) ||
|
||||
(!remaining.includes('\n') && remaining.length < 300)
|
||||
) {
|
||||
if (!title && remaining) {
|
||||
title = remaining;
|
||||
}
|
||||
text = '';
|
||||
}
|
||||
}
|
||||
|
||||
const wantsJson =
|
||||
contentType.includes('application/json') ||
|
||||
Boolean(req.headers.get('accept')?.includes('application/json'));
|
||||
|
||||
// 1. If sharing a URL with no uploaded files and no extra body text, clip the webpage
|
||||
if (url && !text && uploadedFiles.length === 0) {
|
||||
@@ -164,6 +218,9 @@ export async function POST(req: NextRequest) {
|
||||
tags: ['inbox', 'web-clip'],
|
||||
});
|
||||
await applyAutoSortToNote(clippedId, userId).catch(() => {});
|
||||
if (wantsJson) {
|
||||
return NextResponse.json({ ok: true, noteId: clippedId, mode: 'web-clip' }, { status: 201 });
|
||||
}
|
||||
return NextResponse.redirect(getRedirectUrl(req, clippedId), 303);
|
||||
} catch (e) {
|
||||
console.warn('URL clipping failed in /share, falling back to basic link note:', e);
|
||||
@@ -262,6 +319,13 @@ export async function POST(req: NextRequest) {
|
||||
// 4. Run Smart Auto-Sorting & Auto-Tagging
|
||||
await applyAutoSortToNote(note.id, userId).catch(() => {});
|
||||
|
||||
if (wantsJson) {
|
||||
return NextResponse.json(
|
||||
{ ok: true, noteId: note.id, title: note.title },
|
||||
{ status: 201 }
|
||||
);
|
||||
}
|
||||
|
||||
// 5. Redirect browser / Android WebAPK straight into Everclone displaying the new note
|
||||
return NextResponse.redirect(getRedirectUrl(req, note.id), 303);
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user