|
11 | 11 | * Response: { success, url, name, mimeType, tokens, markdown } |
12 | 12 | */ |
13 | 13 |
|
14 | | -import { handlePreflight, jsonResponse, errorResponse } from './cors'; |
| 14 | +import { handlePreflight, jsonResponse, errorResponse, textResponse } from './cors'; |
15 | 15 | import { robustFetch } from './fetch'; |
16 | 16 | import { extractTitle, preprocessHtml } from './html'; |
17 | 17 | import { collectImageUrls, rewriteImageUrls, uploadImages } from './r2'; |
@@ -42,13 +42,17 @@ export default { |
42 | 42 |
|
43 | 43 | // --- Parse target URL from request --- |
44 | 44 | let targetUrl: string | null = null; |
| 45 | + let rawFormat = false; |
45 | 46 |
|
46 | 47 | if (request.method === 'GET') { |
47 | | - targetUrl = new URL(request.url).searchParams.get('url'); |
| 48 | + const params = new URL(request.url).searchParams; |
| 49 | + targetUrl = params.get('url'); |
| 50 | + rawFormat = params.get('format') === 'raw'; |
48 | 51 | } else if (request.method === 'POST') { |
49 | 52 | try { |
50 | | - const body = (await request.json()) as { url?: string }; |
| 53 | + const body = (await request.json()) as { url?: string; format?: string }; |
51 | 54 | targetUrl = body.url ?? null; |
| 55 | + rawFormat = body.format === 'raw'; |
52 | 56 | } catch { |
53 | 57 | return errorResponse(env, 'Invalid JSON body. Expected: { "url": "https://..." }'); |
54 | 58 | } |
@@ -130,6 +134,11 @@ export default { |
130 | 134 | } |
131 | 135 | } |
132 | 136 |
|
| 137 | + // Return raw Markdown text or JSON envelope |
| 138 | + if (rawFormat) { |
| 139 | + return textResponse(env, markdown); |
| 140 | + } |
| 141 | + |
133 | 142 | return jsonResponse(env, { |
134 | 143 | success: true, |
135 | 144 | url: targetUrl, |
|
0 commit comments