fix: project data save

This commit is contained in:
DomWane 2024-09-20 12:06:54 +02:00
parent a41e784a14
commit da6b17b194
3 changed files with 15 additions and 6 deletions

View file

@ -30,15 +30,17 @@ export const useProject = defineStore('project', () => {
async function publishProject() {
isPublishing.value = true
try {
const imageArrayBuffer = await projectImage.value?.arrayBuffer()
let imageBuffer: Buffer | undefined
let base64Image: string | undefined
if (projectImage.value) {
const imageArrayBuffer = await projectImage.value?.arrayBuffer()
if (imageArrayBuffer) {
imageBuffer = Buffer.from(imageArrayBuffer)
const base64String = imageBuffer.toString('base64')
base64Image = base64String
}
}
await $fetch(`/api/data`, {
method: 'POST',

View file

@ -98,6 +98,7 @@ name.value = project.value?.name || 'Untitled'
function save() {
saveProject({
...project.value,
name: name.value,
})
}
@ -123,11 +124,14 @@ async function publish() {
if (selectedTab.value === 'basic_info') {
if (!currentComponent.value.isFormValid())
return
else save()
}
else if (isPublishing) {
return
}
currentComponent.value.save()
await publishProject()
navigateTo(`/project/${project.value?.id || project.value?.name?.toLowerCase().replace(/\s+/g, '-')}`)
}

View file

@ -107,13 +107,16 @@ async function publish() {
if (selectedTab.value === 'basic_info') {
if (!currentComponent.value.isFormValid())
return
else save()
}
else if (isPublishing) {
return
}
currentComponent.value?.save()
await publishProject()
navigateTo(`/project/${project.value?.id || project.value?.name?.toLowerCase().replace(/\s+/g, '-')}`)
navigateTo('/')
}
function jumpTo(tab: string) {