refactor: 优化N8N模板数据提取逻辑
- 简化数据提取路径,直接使用res.data而不是res.data.data - 改进数组处理逻辑,当数组有元素时返回第一个元素 - 添加数组长度检查,确保数组不为空 - 统一代码格式,改进空格和条件判断 - 提升数据处理的准确性和可靠性
This commit is contained in:
parent
a6ea36f11f
commit
33efcffcaa
|
|
@ -19,10 +19,10 @@ export abstract class N8nImageGenerateTemplate extends ImageGenerateTemplate {
|
||||||
}
|
}
|
||||||
}).then(res => res.data).then(res => {
|
}).then(res => res.data).then(res => {
|
||||||
if (res.status) {
|
if (res.status) {
|
||||||
const data = res.data?.data;
|
const data = res.data;
|
||||||
if(!data) throw new Error(`结果有误`)
|
if (!data) throw new Error(`结果有误`)
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data) && data.length > 0) {
|
||||||
return data;
|
return data[0];
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
@ -60,10 +60,10 @@ export abstract class N8nVideoGenerateTemplate extends VideoGenerateTemplate {
|
||||||
}
|
}
|
||||||
}).then(res => res.data).then(res => {
|
}).then(res => res.data).then(res => {
|
||||||
if (res.status) {
|
if (res.status) {
|
||||||
const data = res.data?.data;
|
const data = res.data;
|
||||||
if(!data) throw new Error(`结果有误`)
|
if (!data) throw new Error(`结果有误`)
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data) && data.length > 0) {
|
||||||
return data;
|
return data[0];
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue