mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-10-28 07:44:21 +01:00
fix(converters): improve CSV header generation and FFMPEG argument parsing
This commit is contained in:
@@ -770,9 +770,9 @@ export async function convert(
|
||||
}
|
||||
|
||||
// Parse FFMPEG_ARGS environment variable into array
|
||||
const ffmpegArgs = process.env.FFMPEG_ARGS ? process.env.FFMPEG_ARGS.split(/\s+/) : [];
|
||||
const ffmpegArgs = process.env.FFMPEG_ARGS ? process.env.FFMPEG_ARGS.split(/\s+/).filter(Boolean) : [];
|
||||
const ffmpegOutputArgs = process.env.FFMPEG_OUTPUT_ARGS
|
||||
? process.env.FFMPEG_OUTPUT_ARGS.split(/\s+/)
|
||||
? process.env.FFMPEG_OUTPUT_ARGS.split(/\s+/).filter(Boolean)
|
||||
: [];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -46,12 +46,14 @@ export function parseVCF(data: string): Record<string, string>[] {
|
||||
|
||||
export function toCSV(data: Record<string, string>[]): string {
|
||||
if (!data.length) return "";
|
||||
const first = data[0];
|
||||
if (!first) return "";
|
||||
const headers = Object.keys(first);
|
||||
const headers = new Set<string>();
|
||||
for (const row of data) {
|
||||
Object.keys(row).forEach((key) => headers.add(key));
|
||||
}
|
||||
const headerArray = Array.from(headers);
|
||||
const escape = (str: string) => `"${str.replace(/"/g, '""')}"`;
|
||||
const rows = data.map((row) => headers.map((h) => escape(row[h] || "")).join(","));
|
||||
return [headers.join(","), ...rows].join("\n");
|
||||
const rows = data.map((row) => headerArray.map((h) => escape(row[h] || "")).join(","));
|
||||
return [headerArray.join(","), ...rows].join("\n");
|
||||
}
|
||||
|
||||
export async function convert(
|
||||
|
||||
Reference in New Issue
Block a user