Auto backup \2026-\04-\20
This commit is contained in:
@@ -6,7 +6,6 @@ import { authApi } from '../api/auth'
|
||||
import { Card, CardHeader, CardTitle, CardDescription, CardBody, CardFooter } from '../components-preline/Card'
|
||||
import { Button } from '../components-preline/Button'
|
||||
import { Input, Textarea, Label, FormError } from '../components-preline/Input'
|
||||
import { postsApi } from '../api/posts'
|
||||
import { categoriesApi } from '../api/categories'
|
||||
import { tagsApi } from '../api/tags'
|
||||
import { API_BASE_URL } from '../api/config'
|
||||
@@ -200,25 +199,55 @@ export function UniversalCrawlEdit() {
|
||||
// 保存文章
|
||||
const handleSubmit = async (e, isDraft = false) => {
|
||||
e.preventDefault()
|
||||
|
||||
|
||||
if (!form.title.trim() || !form.content.trim()) {
|
||||
alert('请填写标题和内容')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
setSaving(true)
|
||||
try {
|
||||
const data = {
|
||||
...form,
|
||||
category_id: form.category_id || null,
|
||||
is_draft: isDraft,
|
||||
is_published: !isDraft
|
||||
const token = localStorage.getItem('token')
|
||||
// 将 tag_ids 转换为 tag 名称数组
|
||||
const tagNames = form.tag_ids.map(tid => {
|
||||
const tag = tags.find(t => t.id === Number(tid))
|
||||
return tag ? tag.name : ''
|
||||
}).filter(Boolean)
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/universal-crawl/save`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(token ? { 'Authorization': `Bearer ${token}` } : {})
|
||||
},
|
||||
body: JSON.stringify({
|
||||
title: form.title,
|
||||
content: form.content,
|
||||
content_html: '',
|
||||
images: crawledImages,
|
||||
summary: form.summary,
|
||||
category_id: form.category_id || null,
|
||||
is_draft: isDraft,
|
||||
is_published: !isDraft,
|
||||
tags: tagNames,
|
||||
source_url: crawlUrl
|
||||
}),
|
||||
credentials: 'include'
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
if (!data.success) {
|
||||
throw new Error(data.detail || data.message || '保存失败')
|
||||
}
|
||||
|
||||
await postsApi.createPost(data)
|
||||
|
||||
// 提示图片下载情况
|
||||
if (data.images_failed > 0) {
|
||||
alert(`文章已保存成功!\n图片:${data.images_saved} 张下载成功,${data.images_failed} 张下载失败(保留原始链接)。`)
|
||||
}
|
||||
|
||||
navigate('/admin/posts')
|
||||
} catch (error) {
|
||||
alert('保存失败: ' + (error.response?.data?.detail || '未知错误'))
|
||||
alert('保存失败: ' + (error.message || error.response?.data?.detail || '未知错误'))
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user