diff --git a/Dockerfile b/Dockerfile index 372b91e..4d96c83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -82,14 +82,11 @@ RUN ARCH=$(uname -m) && \ else \ VTRACER_ASSET="vtracer-x86_64-unknown-linux-musl.tar.gz"; \ fi && \ - echo "Downloading VTracer: $VTRACER_ASSET" && \ curl -L -o /tmp/vtracer.tar.gz "https://github.com/visioncortex/vtracer/releases/download/0.6.4/${VTRACER_ASSET}" && \ tar -xzf /tmp/vtracer.tar.gz -C /tmp/ && \ mv /tmp/vtracer /usr/local/bin/vtracer && \ chmod +x /usr/local/bin/vtracer && \ - rm /tmp/vtracer.tar.gz && \ - echo "VTracer installed successfully" && \ - vtracer --help + rm /tmp/vtracer.tar.gz COPY --from=install /temp/prod/node_modules node_modules COPY --from=prerelease /app/public/generated.css /app/public/ diff --git a/src/converters/main.ts b/src/converters/main.ts index fc33318..f90a3fc 100644 --- a/src/converters/main.ts +++ b/src/converters/main.ts @@ -20,9 +20,8 @@ import { convert as convertPandoc, properties as propertiesPandoc } from "./pand import { convert as convertPotrace, properties as propertiesPotrace } from "./potrace"; 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 convertxelatex, properties as propertiesxelatex } from "./xelatex"; -import {convert as convertVtracer, properties as propertiesVtracer} from './vtracer'; - // This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular @@ -122,7 +121,7 @@ const properties: Record< vtracer: { properties: propertiesVtracer, converter: convertVtracer, - } + }, }; function chunks(arr: T[], size: number): T[][] { diff --git a/src/converters/vtracer.ts b/src/converters/vtracer.ts index 1c0d706..31ce110 100644 --- a/src/converters/vtracer.ts +++ b/src/converters/vtracer.ts @@ -10,6 +10,20 @@ export const properties = { }, }; +interface VTracerOptions { + colormode?: string; + hierarchical?: string; + mode?: string; + filter_speckle?: string | number; + color_precision?: string | number; + layer_difference?: string | number; + corner_threshold?: string | number; + length_threshold?: string | number; + max_iterations?: string | number; + splice_threshold?: string | number; + path_precision?: string | number; +} + export function convert( filePath: string, fileType: string, @@ -24,34 +38,40 @@ export function convert( // Add optional parameter if provided if (options && typeof options === "object") { - const opts = options as Record; - - const validOptions = [ - "colormode", "hierarchical", "mode", "filter_speckle", - "color_precision", "layer_difference", "corner_threshold", - "length_threshold", "max_iterations", "splice_threshold", + const opts = options as VTracerOptions; + const validOptions: Array = [ + "colormode", + "hierarchical", + "mode", + "filter_speckle", + "color_precision", + "layer_difference", + "corner_threshold", + "length_threshold", + "max_iterations", + "splice_threshold", "path_precision", ]; for (const option of validOptions) { - if(opts[option]){ - args.push(`--${option}`, opts[option]); - } + if (opts[option] !== undefined) { + args.push(`--${option}`, String(opts[option])); + } } } execFile("vtracer", args, (error, stdout, stderr) => { - if(error){ - reject(`error: ${error}${stderr ? `\nstderr: ${stderr}` : ''}`) + if (error) { + reject(`error: ${error}${stderr ? `\nstderr: ${stderr}` : ""}`); return; } - if(stdout){ - console.log(`stdout: ${stdout}`) + if (stdout) { + console.log(`stdout: ${stdout}`); } - if(stderr){ - console.log(`stderr: ${stderr}`) + if (stderr) { + console.log(`stderr: ${stderr}`); } resolve("Done");