* Main entry point for the program. * @param {string} inputDir The directory in which to run the sample. * @returns {Promise }
(inputDir)
| 217 | * @returns {Promise<void>} |
| 218 | */ |
| 219 | async function main(inputDir) { |
| 220 | const index = new Index(); |
| 221 | try { |
| 222 | const files = await fs.readdir(inputDir); |
| 223 | |
| 224 | // Get a list of all files in the directory (filter out other directories) |
| 225 | const allImageFiles = ( |
| 226 | await Promise.all( |
| 227 | files.map(async file => { |
| 228 | const filename = path.join(inputDir, file); |
| 229 | const stats = await fs.stat(filename); |
| 230 | if (!stats.isDirectory()) { |
| 231 | return filename; |
| 232 | } |
| 233 | }) |
| 234 | ) |
| 235 | ).filter(f => !!f); |
| 236 | |
| 237 | // Figure out which files have already been processed |
| 238 | let imageFilesToProcess = ( |
| 239 | await Promise.all( |
| 240 | allImageFiles.map(async filename => { |
| 241 | const processed = await index.documentIsProcessed(filename); |
| 242 | if (!processed) { |
| 243 | // Forward this filename on for further processing |
| 244 | return filename; |
| 245 | } |
| 246 | }) |
| 247 | ) |
| 248 | ).filter(file => !!file); |
| 249 | |
| 250 | // The batch endpoint won't handle |
| 251 | if (imageFilesToProcess.length > 15) { |
| 252 | console.log( |
| 253 | 'Maximum of 15 images allowed. Analyzing the first 15 found.' |
| 254 | ); |
| 255 | imageFilesToProcess = imageFilesToProcess.slice(0, 15); |
| 256 | } |
| 257 | |
| 258 | // Analyze any remaining unprocessed files |
| 259 | if (imageFilesToProcess.length > 0) { |
| 260 | console.log('Files to process: '); |
| 261 | await getTextFromFiles(index, imageFilesToProcess); |
| 262 | } |
| 263 | console.log('All files processed!'); |
| 264 | } catch (e) { |
| 265 | console.error(e); |
| 266 | } |
| 267 | index.quit(); |
| 268 | } |
| 269 | |
| 270 | const usage = |
| 271 | 'Usage: node textDetection <command> <arg> ... \n\n Commands: analyze, lookup'; |
no test coverage detected