Skip to content

Commit 42ef4d1

Browse files
committed
feat(post): added support for markdown response with JSON coded data.
1 parent 4023a11 commit 42ef4d1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

inertia/pages/posts/form.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,17 @@ async function generateVideoChapters() {
132132
133133
try {
134134
const { data } = await axios.post(`/ai/videos/${form.videoUrl}/chapters`)
135+
const result = data.result.response
135136
136-
if (Array.isArray(data.result.response)) {
137-
form.chapters = data.result.response
137+
if (Array.isArray(result)) {
138+
form.chapters = result
138139
139-
toast.success('Chapters generated successfully')
140+
toast.success('Chapters generated successfully from JSON')
141+
} else if (typeof result === 'string' && result.startsWith('```json[')) {
142+
const chapters = JSON.parse(result.replace('```json', '').replace('```', ''))
143+
form.chapters = chapters
144+
145+
toast.success('Chapters generated successfully from Markdown')
140146
} else {
141147
toast.error('Chapters were generated successfully, but came back in an unexpected format')
142148
}

0 commit comments

Comments
 (0)