feat: add URL content extraction for AI diagram generation

This commit is contained in:
Biki Kalita
2026-01-04 22:36:46 +05:30
parent 3ce047f794
commit 64268b0fac
11 changed files with 3301 additions and 2037 deletions

View File

@@ -51,7 +51,8 @@
"badResponse": "Bad response",
"clickToEdit": "Click to edit",
"editMessage": "Edit message",
"saveAndSubmit": "Save & Submit"
"saveAndSubmit": "Save & Submit",
"ExtractURL": "Extract from URL"
},
"examples": {
"title": "Create diagrams with AI",
@@ -186,6 +187,13 @@
"chars": "chars",
"removeFile": "Remove file"
},
"pdf": {
"title": "Extract Content from URL",
"description": "Paste a URL to extract and analyze its content",
"Extracting": "Extracting...",
"extract": "Extract",
"Cancel": "Cancel"
},
"reasoning": {
"thinking": "Thinking...",
"thoughtFor": "Thought for {duration} seconds",

View File

@@ -51,7 +51,8 @@
"badResponse": "悪い応答",
"clickToEdit": "クリックして編集",
"editMessage": "メッセージを編集",
"saveAndSubmit": "保存して送信"
"saveAndSubmit": "保存して送信",
"ExtractURL": "URLから抽出"
},
"examples": {
"title": "AI でダイアグラムを作成",
@@ -186,6 +187,13 @@
"chars": "文字",
"removeFile": "ファイルを削除"
},
"pdf": {
"title": "URLからコンテンツを抽出",
"description": "URLを貼り付けてそのコンテンツを抽出および分析します",
"Extracting": "抽出中...",
"extract": "抽出",
"Cancel": "キャンセル"
},
"reasoning": {
"thinking": "考え中...",
"thoughtFor": "{duration} 秒考えました",

View File

@@ -51,7 +51,8 @@
"badResponse": "无帮助",
"clickToEdit": "点击编辑",
"editMessage": "编辑消息",
"saveAndSubmit": "保存并提交"
"saveAndSubmit": "保存并提交",
"ExtractURL": "从 URL 提取"
},
"examples": {
"title": "用 AI 创建图表",
@@ -186,6 +187,13 @@
"chars": "字符",
"removeFile": "移除文件"
},
"pdf": {
"title": "从 URL 提取内容",
"description": "粘贴 URL 以提取和分析其内容",
"Extracting": "提取中...",
"extract": "提取",
"Cancel": "取消"
},
"reasoning": {
"thinking": "思考中...",
"thoughtFor": "思考了 {duration} 秒",

29
lib/url-utils.ts Normal file
View 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,
}
}