mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-10 02:02:31 +08:00
feat: add URL content extraction for AI diagram generation
This commit is contained in:
29
lib/url-utils.ts
Normal file
29
lib/url-utils.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export interface UrlData {
|
||||
url: string
|
||||
title: string
|
||||
content: string
|
||||
charCount: number
|
||||
isExtracting: boolean
|
||||
}
|
||||
|
||||
export async function extractUrlContent(url: string): Promise<UrlData> {
|
||||
const response = await fetch("/api/parse-url", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ url }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => null)
|
||||
throw new Error(error?.error || "Failed to extract URL content")
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return {
|
||||
url,
|
||||
title: data.title,
|
||||
content: data.content,
|
||||
charCount: data.charCount,
|
||||
isExtracting: false,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user