Skip to content

Commit

Permalink
feat: Wrap conversion options into an optional object.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Camarasa authored and lynxtaa committed Jan 30, 2024
1 parent 2f6dae6 commit 14080f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ export const routes: FastifyPluginCallback = (app, options, next) => {
})
})

const { targetPath } = await convertFile(
srcPath,
req.params.format,
req.query.filter,
)
const { targetPath } = await convertFile(srcPath, req.params.format, {
filter: req.query.filter,
})

const stream = createReadStream(targetPath)

Expand Down
4 changes: 2 additions & 2 deletions src/utils/convertFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { unoserver } from './unoserver.js'
export async function convertFile(
srcPath: string,
format: string,
filter?: string,
options?: { filter?: string },
): Promise<{ targetPath: string }> {
const ext = path.extname(srcPath).toLowerCase()
assert(
Expand All @@ -25,7 +25,7 @@ export async function convertFile(

const targetPath = `${pathWithoutExtension}.${format}`

await unoserver.convert(srcPath, targetPath, filter)
await unoserver.convert(srcPath, targetPath, { filter: options?.filter })

return { targetPath }
}
7 changes: 4 additions & 3 deletions src/utils/unoserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export class Unoserver {
*
* @param from source file
* @param to target file
* @param filter filter name to use during conversion process
* @param options conversion options
*/
convert(from: string, to: string, filter?: string): Promise<void> {
convert(from: string, to: string, options?: { filter?: string }): Promise<void> {
return this.queue.add(() =>
pRetry(
async () => {
Expand All @@ -59,7 +59,8 @@ export class Unoserver {
}

const portCommandArg = ['--port', String(this.port)]
const filterCommandArg = filter !== undefined ? ['--filter', filter] : []
const filterCommandArg =
options?.filter !== undefined ? ['--filter', options.filter] : []

const commandArguments = [...portCommandArg, ...filterCommandArg, from, to]

Expand Down

0 comments on commit 14080f7

Please sign in to comment.