Merge pull request #1 from C4illin/main

merge new
This commit is contained in:
Kosztyk 2026-01-11 23:09:48 +02:00 committed by GitHub
commit ddb7292116
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 181 additions and 2 deletions

View file

@ -31,6 +31,7 @@ RUN apt-get update && apt-get install -y \
poppler-utils \
potrace \
python3-numpy \
python3-tinycss2 \
resvg \
texlive \
texlive-fonts-recommended \

View file

@ -68,6 +68,7 @@ RUN apt-get update && apt-get install -y \
poppler-utils \
potrace \
python3-numpy \
python3-tinycss2 \
resvg \
texlive \
texlive-fonts-recommended \
@ -108,4 +109,4 @@ EXPOSE 3000/tcp
# used for calibre
ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox"
ENV NODE_ENV=production
ENTRYPOINT [ "bun", "run", "dist/src/index.js" ]
ENTRYPOINT [ "bun", "run", "dist/src/index.js" ]

View file

@ -38,6 +38,7 @@ A self-hosted online file converter. Supports over a thousand different formats.
| [Dasel](https://github.com/TomWright/dasel) | Data Files | 5 | 4 |
| [Pandoc](https://pandoc.org/) | Documents | 43 | 65 |
| [msgconvert](https://github.com/mvz/email-outlook-message-perl) | Outlook | 1 | 1 |
| VCF to CSV | Contacts | 1 | 1 |
| [dvisvgm](https://dvisvgm.de/) | Vector images | 4 | 2 |
| [ImageMagick](https://imagemagick.org/) | Images | 245 | 183 |
| [GraphicsMagick](http://www.graphicsmagick.org/) | Images | 167 | 130 |
@ -128,6 +129,8 @@ Tutorial in french: <https://belginux.com/installer-convertx-avec-docker/>
Tutorial in chinese: <https://xzllll.com/24092901/>
Tutorial in polish: <https://www.kreatywnyprogramista.pl/convertx-lokalny-konwerter-plikow>
## Screenshots
![ConvertX Preview](images/preview.png)

View file

@ -1,3 +1,5 @@
# This compose file is for development and testing purposes only. See README for production deployment instructions.
services:
convertx:
build:

View file

@ -2,5 +2,5 @@
bun = "1.2.2"
[env]
JWT_SECRET = "JustForDevelopmentPurposesOnlyChangeMeInProduction!"
JWT_SECRET = "aLongAndSecretStringUsedToSignTheJSONWebToken1234"
FFMPEG_OUTPUT_ARGS = "-preset veryfast -threads 2"

View file

@ -22,6 +22,7 @@ import { convert as convertPotrace, properties as propertiesPotrace } from "./po
import { convert as convertresvg, properties as propertiesresvg } from "./resvg";
import { convert as convertImage, properties as propertiesImage } from "./vips";
import { convert as convertVtracer, properties as propertiesVtracer } from "./vtracer";
import { convert as convertVcf, properties as propertiesVcf } from "./vcf";
import { convert as convertxelatex, properties as propertiesxelatex } from "./xelatex";
import { convert as convertMarkitdown, properties as propertiesMarkitdown } from "./markitdown";
@ -128,6 +129,10 @@ const properties: Record<
properties: propertiesVtracer,
converter: convertVtracer,
},
vcf: {
properties: propertiesVcf,
converter: convertVcf,
},
markitDown: {
properties: propertiesMarkitdown,
converter: convertMarkitdown,

69
src/converters/vcf.ts Normal file
View file

@ -0,0 +1,69 @@
import { readFile, writeFile } from "fs/promises";
export const properties = {
from: {
contacts: ["vcf"],
},
to: {
contacts: ["csv"],
},
};
export function parseVCF(data: string): Record<string, string>[] {
const cards = data
.split(/BEGIN:VCARD/)
.slice(1)
.map((card) => card.split(/END:VCARD/)[0])
.filter((card) => card);
return cards
.map((card) => {
if (!card) return {};
const lines = card.split("\n").filter((line) => line.trim());
const contact: Record<string, string> = {};
for (const line of lines) {
const colonIndex = line.indexOf(":");
if (colonIndex === -1) continue;
const key = line.slice(0, colonIndex).trim();
const value = line.slice(colonIndex + 1).trim();
if (key === "FN") {
contact["Full Name"] = value;
} else if (key === "N") {
const parts = value.split(";");
contact["Last Name"] = parts[0] || "";
contact["First Name"] = parts[1] || "";
} else if (key.startsWith("TEL")) {
contact["Phone"] = value;
} else if (key.startsWith("EMAIL")) {
contact["Email"] = value;
} else if (key === "ORG") {
contact["Organization"] = value.split(";")[0] || "";
}
}
return contact;
})
.filter((contact) => Object.keys(contact).length > 0);
}
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 escape = (str: string) => `"${str.replace(/"/g, '""')}"`;
const rows = data.map((row) => headers.map((h) => escape(row[h] || "")).join(","));
return [headers.join(","), ...rows].join("\n");
}
export async function convert(
filePath: string,
fileType: string,
convertTo: string,
targetPath: string,
options?: unknown, // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<string> {
const vcfData = await readFile(filePath, "utf-8");
const contacts = parseVCF(vcfData);
const csvData = toCSV(contacts);
await writeFile(targetPath, csvData, "utf-8");
return "Done";
}

View file

@ -0,0 +1,98 @@
import { expect, test, describe } from "bun:test";
import { convert, parseVCF, toCSV } from "../../src/converters/vcf";
describe("parseVCF", () => {
test("should parse a simple VCF card", () => {
const vcfData = `BEGIN:VCARD
VERSION:3.0
FN:John Doe
N:Doe;John;;;
TEL:+123456789
EMAIL:john@example.com
ORG:Example Corp
END:VCARD`;
const result = parseVCF(vcfData);
expect(result).toEqual([
{
"Full Name": "John Doe",
"Last Name": "Doe",
"First Name": "John",
Phone: "+123456789",
Email: "john@example.com",
Organization: "Example Corp",
},
]);
});
test("should handle multiple cards", () => {
const vcfData = `BEGIN:VCARD
FN:John Doe
END:VCARD
BEGIN:VCARD
FN:Jane Smith
END:VCARD`;
const result = parseVCF(vcfData);
expect(result).toEqual([{ "Full Name": "John Doe" }, { "Full Name": "Jane Smith" }]);
});
test("should parse VCF with TYPE parameters", () => {
const vcfData = `BEGIN:VCARD
VERSION:3.0
FN:John Doe
N:Doe;John;;;
TEL;TYPE=WORK,VOICE:(111) 555-1212
EMAIL;TYPE=PREF,INTERNET:john.doe@example.com
END:VCARD`;
const result = parseVCF(vcfData);
expect(result).toEqual([
{
"Full Name": "John Doe",
"Last Name": "Doe",
"First Name": "John",
Phone: "(111) 555-1212",
Email: "john.doe@example.com",
},
]);
});
});
describe("toCSV", () => {
test("should convert contacts to CSV", () => {
const contacts = [
{
"Full Name": "John Doe",
Phone: "+123",
Email: "john@example.com",
},
];
const result = toCSV(contacts);
expect(result).toBe('Full Name,Phone,Email\n"John Doe","+123","john@example.com"');
});
test("should escape quotes", () => {
const contacts = [{ "Full Name": 'John "Johnny" Doe' }];
const result = toCSV(contacts);
expect(result).toBe('Full Name\n"John ""Johnny"" Doe"');
});
test("should handle empty data", () => {
const result = toCSV([]);
expect(result).toBe("");
});
});
describe("convert", () => {
test("should be a function", () => {
expect(typeof convert).toBe("function");
});
});