fix: editor
This commit is contained in:
@@ -54,7 +54,6 @@ export const useProductStore = defineStore('product', () => {
|
||||
try {
|
||||
const response = await useFetchJson<ProductDescription>(`/api/v1/restricted/product-translation/translate-product-description?productID=${productID}&productFromLangID=${settingStore.shopDefaultLanguage}&productToLangID=${toLangId}&model=${model}`)
|
||||
productDescription.value = response.items
|
||||
saveProductDescription(productID, toLangId)
|
||||
return response.items
|
||||
} catch (e: any) {
|
||||
error.value = e?.message || 'Failed to translate product description'
|
||||
@@ -64,42 +63,6 @@ export const useProductStore = defineStore('product', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function fixHtml(html: string) {
|
||||
return html
|
||||
// 1. fix img
|
||||
.replace(/<img([^>]*?)>/g, '<img$1 />')
|
||||
|
||||
// 2. escape text only
|
||||
.replace(/>([^<]+)</g, (match, text) => {
|
||||
const escaped = text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
|
||||
return `>${escaped}<`
|
||||
})
|
||||
}
|
||||
|
||||
function fixAll(obj: any): any {
|
||||
if (typeof obj === 'string') {
|
||||
return fixHtml(obj)
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(fixAll)
|
||||
}
|
||||
|
||||
if (typeof obj === 'object' && obj !== null) {
|
||||
const result: any = {}
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
result[key] = fixAll(value)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
|
||||
async function saveProductDescription(productID?: number, langId?: number | null) {
|
||||
const id = productID || 1
|
||||
const lang = langId || 1
|
||||
|
||||
Reference in New Issue
Block a user