From 7ccd6e80cafb0428c2f66fc51a8cae294773796e Mon Sep 17 00:00:00 2001 From: songtianlun Date: Wed, 30 Jul 2025 22:24:09 +0800 Subject: [PATCH] add dupli --- CLAUDE.md | 2 +- messages/en.json | 1 + messages/zh.json | 1 + src/app/studio/[id]/page.tsx | 61 ++++++++++++++++++++++++++++-------- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 3429eee..051feaf 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -135,7 +135,7 @@ Required environment variables: - [x] Prompt Version Controll - [x] Generate a new version when save - [x] Save last [LIMIT] versions - - [ ] [LIMIT] can setting in use profile + - [x] [LIMIT] can setting in use profile - [ ] [LIMIT] max is by Subscribe - [ ] Delete Version Button - [x] Prompt Debugger run diff --git a/messages/en.json b/messages/en.json index 762ade7..bbf7e83 100644 --- a/messages/en.json +++ b/messages/en.json @@ -14,6 +14,7 @@ "delete": "Delete", "edit": "Edit", "create": "Create", + "duplicate": "Duplicate", "search": "Search", "filter": "Filter", "close": "Close", diff --git a/messages/zh.json b/messages/zh.json index 2064b0e..a218537 100644 --- a/messages/zh.json +++ b/messages/zh.json @@ -14,6 +14,7 @@ "delete": "删除", "edit": "编辑", "create": "创建", + "duplicate": "复制", "search": "搜索", "filter": "筛选", "close": "关闭", diff --git a/src/app/studio/[id]/page.tsx b/src/app/studio/[id]/page.tsx index 8f59edf..417778f 100644 --- a/src/app/studio/[id]/page.tsx +++ b/src/app/studio/[id]/page.tsx @@ -15,9 +15,7 @@ import { Play, Save, Copy, - Settings, Zap, - History, ArrowLeft, FileText, Clock @@ -71,6 +69,7 @@ export default function PromptPage({ params }: PromptPageProps) { const [originalContent, setOriginalContent] = useState('') const [originalTitle, setOriginalTitle] = useState('') const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false) + const [isDuplicating, setIsDuplicating] = useState(false) const versionTimelineRef = useRef(null) useEffect(() => { @@ -246,6 +245,40 @@ export default function PromptPage({ params }: PromptPageProps) { } } + const handleDuplicatePrompt = async () => { + if (!user || !prompt) return + + setIsDuplicating(true) + try { + // 创建新的prompt,使用当前显示的内容 + const duplicatedPrompt = { + name: `${promptTitle} 副本`, + content: promptContent, + description: prompt.description, + tags: prompt.tags, + userId: user.id + } + + const response = await fetch('/api/prompts', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(duplicatedPrompt) + }) + + if (response.ok) { + const newPrompt = await response.json() + // 跳转到新创建的prompt页面 + router.push(`/studio/${newPrompt.id}`) + } else { + console.error('Failed to duplicate prompt') + } + } catch (error) { + console.error('Error duplicating prompt:', error) + } finally { + setIsDuplicating(false) + } + } + if (loading || isLoading) { return (
@@ -292,17 +325,19 @@ export default function PromptPage({ params }: PromptPageProps) {
- - -