更多样的bing suno生成

This commit is contained in:
zyc404 2024-05-07 23:02:18 +08:00
parent 991c63bb26
commit b20a3db006
6 changed files with 208 additions and 69 deletions

View file

@ -1242,3 +1242,36 @@ function maskString (str) {
return firstThreeChars + maskedChars + lastThreeChars
}
/**
* generated by ai
* @param text
* @returns {array}
*/
export function extractMarkdownJson(text) {
const lines = text.split('\n')
const mdJson = []
let currentObj = null
lines.forEach(line => {
if (line.startsWith('```json') && !currentObj) {
// 开始一个新的JSON对象
currentObj = { json: '' }
} else if (line.startsWith('```') && currentObj) {
// 结束当前的JSON对象
try {
// 尝试将JSON字符串转换为对象
currentObj.json = JSON.parse(currentObj.json)
mdJson.push(currentObj)
currentObj = null
} catch (e) {
console.error('JSON解析错误:', e)
}
} else if (currentObj) {
// 将行添加到当前的JSON对象
currentObj.json += line
}
})
return mdJson.map(obj => obj.json)
}