mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-30 10:28:42 +00:00
HTTP support jsonPath; System plugin support save file. (#2969)
* perf: system plugin auto save file * feat: http support jsonPath * fix: assistant response * reset milvus version * fix: textarea register * fix: global variable * delete tip * doc
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
"expr-eval": "^2.0.2",
|
||||
"lodash": "^4.17.21",
|
||||
"mysql2": "^3.11.3",
|
||||
"json5": "^2.2.3",
|
||||
"pg": "^8.10.0",
|
||||
"wikijs": "^6.4.1"
|
||||
},
|
||||
|
@@ -1,4 +1,8 @@
|
||||
import * as echarts from 'echarts';
|
||||
import json5 from 'json5';
|
||||
import { getFileSavePath } from '../../../utils';
|
||||
import * as fs from 'fs';
|
||||
import { SystemPluginSpecialResponse } from '../../../type.d';
|
||||
|
||||
type Props = {
|
||||
title: string;
|
||||
@@ -8,7 +12,7 @@ type Props = {
|
||||
};
|
||||
|
||||
type Response = Promise<{
|
||||
result: string;
|
||||
result: SystemPluginSpecialResponse;
|
||||
}>;
|
||||
|
||||
type SeriesData = {
|
||||
@@ -37,8 +41,8 @@ const generateChart = async (title: string, xAxis: string, yAxis: string, chartT
|
||||
let parsedXAxis: string[] = [];
|
||||
let parsedYAxis: number[] = [];
|
||||
try {
|
||||
parsedXAxis = JSON.parse(xAxis);
|
||||
parsedYAxis = JSON.parse(yAxis);
|
||||
parsedXAxis = json5.parse(xAxis);
|
||||
parsedYAxis = json5.parse(yAxis);
|
||||
} catch (error: any) {
|
||||
console.error('解析数据时出错:', error);
|
||||
return Promise.reject('Data error');
|
||||
@@ -78,16 +82,26 @@ const generateChart = async (title: string, xAxis: string, yAxis: string, chartT
|
||||
|
||||
chart.setOption(option);
|
||||
// 生成 Base64 图像
|
||||
const base64Image = chart.getDataURL({ type: 'png' });
|
||||
const base64Image = chart.getDataURL();
|
||||
const svgData = decodeURIComponent(base64Image.split(',')[1]);
|
||||
|
||||
const fileName = `chart_${Date.now()}.svg`;
|
||||
const filePath = getFileSavePath(fileName);
|
||||
fs.writeFileSync(filePath, svgData);
|
||||
// 释放图表实例
|
||||
chart.dispose();
|
||||
|
||||
return base64Image;
|
||||
return filePath;
|
||||
};
|
||||
|
||||
const main = async ({ title, xAxis, yAxis, chartType }: Props): Response => {
|
||||
const filePath = await generateChart(title, xAxis, yAxis, chartType);
|
||||
return {
|
||||
result: await generateChart(title, xAxis, yAxis, chartType)
|
||||
result: {
|
||||
type: 'SYSTEM_PLUGIN_FILE',
|
||||
path: filePath,
|
||||
contentType: 'image/svg+xml'
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
@@ -50,10 +50,10 @@
|
||||
"canEdit": true,
|
||||
"key": "xAxis",
|
||||
"label": "xAxis",
|
||||
"description": "x轴数据,例如:['A', 'B', 'C']",
|
||||
"description": "x轴数据,例如:[\"A\", \"B\", \"C\"]",
|
||||
"defaultValue": "",
|
||||
"required": true,
|
||||
"toolDescription": "x轴数据,例如:['A', 'B', 'C']",
|
||||
"toolDescription": "x轴数据,例如:[\"A\", \"B\", \"C\"]",
|
||||
"list": [
|
||||
{
|
||||
"label": "",
|
||||
|
6
packages/plugins/type.d.ts
vendored
6
packages/plugins/type.d.ts
vendored
@@ -1,7 +1,13 @@
|
||||
import { PluginTemplateType } from '@fastgpt/global/core/plugin/type.d';
|
||||
import { systemPluginResponseEnum } from '@fastgpt/global/core/workflow/runtime/constants';
|
||||
import { SystemPluginTemplateItemType } from '@fastgpt/global/core/workflow/type';
|
||||
|
||||
export type SystemPluginResponseType = Promise<Record<string, any>>;
|
||||
export type SystemPluginSpecialResponse = {
|
||||
type: 'SYSTEM_PLUGIN_FILE';
|
||||
path: string;
|
||||
contentType: string;
|
||||
};
|
||||
|
||||
declare global {
|
||||
var systemPlugins: SystemPluginTemplateItemType[];
|
||||
|
15
packages/plugins/utils.ts
Normal file
15
packages/plugins/utils.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
|
||||
export const getFileSavePath = (name: string) => {
|
||||
if (isProduction) {
|
||||
return `/app/plugin_file/${name}`;
|
||||
}
|
||||
const filePath = path.join(process.cwd(), 'local', 'plugin_file', name);
|
||||
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
|
||||
return filePath;
|
||||
};
|
Reference in New Issue
Block a user