File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ export const ImageGenerator = async (
1313 json : JSONObjectImageSuccessRequest ,
1414) : Promise < [ NodeHTMLToImageBuffer , string ] > => {
1515 // HTMLGenerator already handles font size conversion and generates the HTML
16- const code = await HTMLGenerator (
16+ const [ code ] = await HTMLGenerator (
1717 json as unknown as JSONObjectHTMLSuccessRequest ,
1818 ) ;
1919
Original file line number Diff line number Diff line change 11import { mkdir } from "node:fs/promises" ;
22
3- export const getOutputDir = async ( ) : Promise < string > => {
3+ const replaceProcessEnv = ( input : string ) : string => {
4+ return input . replace ( / \$ ( [ A - Z _ ] + ) / g, ( _ , varName ) => {
5+ return process . env [ varName ] || "" ;
6+ } ) ;
7+ } ;
8+
9+ export const getOutputDir = async (
10+ userConfigOutDir ?: string ,
11+ ) : Promise < string > => {
12+ if ( userConfigOutDir ) {
13+ if ( userConfigOutDir . startsWith ( "~" ) ) {
14+ const homeDir = process . env . HOME || process . env . USERPROFILE || null ;
15+ if ( ! homeDir ) {
16+ throw new Error ( "Could not determine the user's home directory." ) ;
17+ }
18+ userConfigOutDir = userConfigOutDir . replace ( "~" , homeDir ) ;
19+ }
20+ return replaceProcessEnv ( userConfigOutDir ) ;
21+ }
422 const homeDir = process . env . HOME || process . env . USERPROFILE || null ;
523 if ( ! homeDir ) {
624 throw new Error ( "Could not determine the user's home directory." ) ;
@@ -20,7 +38,7 @@ export const getFullOutputPath = async (
2038 filename : string ,
2139 filenamePattern : string ,
2240) : Promise < string > => {
23- if ( ! outputDir ) outputDir = await getOutputDir ( ) ;
41+ outputDir = await getOutputDir ( outputDir ) ;
2442 return `${ outputDir . replace ( / \/ + $ / , "" ) } /${ generateFilename (
2543 filenamePattern ,
2644 filename ,
You can’t perform that action at this time.
0 commit comments