| 79 | } |
| 80 | |
| 81 | async function createColouringMiniatures() { |
| 82 | const inputDirectory = path.join( |
| 83 | process.cwd(), |
| 84 | "public", |
| 85 | "images", |
| 86 | "colouring" |
| 87 | ); |
| 88 | const filenames = fs.readdirSync(inputDirectory); |
| 89 | |
| 90 | await Promise.all( |
| 91 | filenames |
| 92 | .filter((file: string) => path.parse(file).ext === ".jpg") |
| 93 | .map(async (file: string) => { |
| 94 | const outputFile = `${inputDirectory}/mini/${ |
| 95 | path.parse(file).name |
| 96 | }.jpg`; |
| 97 | if (fs.existsSync(outputFile)) { |
| 98 | // File exists in path |
| 99 | } else { |
| 100 | await sharp(`${inputDirectory}/${file}`) |
| 101 | .resize(500, undefined) |
| 102 | .toFormat("jpg") |
| 103 | .toFile(outputFile); |
| 104 | } |
| 105 | }) |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | const checkStatus = (response: any) => { |
| 110 | if (response.ok) { |