mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00

* perf: read file worker * fix: Http node url input * fix: htm2md * fix: html2md * fix: ts * perf: Problem classification increases the matching order * feat: tool response answer
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { ReadRawTextByBuffer, ReadFileResponse } from '../type';
|
|
import xlsx from 'node-xlsx';
|
|
import Papa from 'papaparse';
|
|
|
|
export const readXlsxRawText = async ({
|
|
buffer
|
|
}: ReadRawTextByBuffer): Promise<ReadFileResponse> => {
|
|
const result = xlsx.parse(buffer, {
|
|
skipHidden: false,
|
|
defval: ''
|
|
});
|
|
|
|
const format2Csv = result.map(({ name, data }) => {
|
|
return {
|
|
title: `#${name}`,
|
|
csvText: data.map((item) => item.join(',')).join('\n')
|
|
};
|
|
});
|
|
|
|
const rawText = format2Csv.map((item) => item.csvText).join('\n');
|
|
const formatText = format2Csv
|
|
.map((item) => {
|
|
const csvArr = Papa.parse(item.csvText).data as string[][];
|
|
const header = csvArr[0];
|
|
|
|
const formatText = header
|
|
? csvArr
|
|
.map((item) =>
|
|
item
|
|
.map((item, i) => (item ? `${header[i]}:${item}` : ''))
|
|
.filter(Boolean)
|
|
.join('\n')
|
|
)
|
|
.join('\n')
|
|
: '';
|
|
|
|
return `${item.title}\n${formatText}`;
|
|
})
|
|
.join('\n');
|
|
|
|
return {
|
|
rawText: rawText,
|
|
formatText
|
|
};
|
|
};
|