bowling-analysis-system
Version:
A comprehensive system for analyzing bowling techniques using video processing and metrics calculation
70 lines (62 loc) • 2 kB
JavaScript
/**
* Multi-File Loader Processor
*
* Loads multiple files from the filesystem
* @module processors/MultiFileLoaderProcessor
*/
const { BaseProcessor } = require('../core/BaseProcessor');
const { defaultFileService } = require('../utils/FileService');
/**
* @class MultiFileLoaderProcessor
* @description Processor for loading multiple files from the filesystem
* @extends BaseProcessor
*/
class MultiFileLoaderProcessor extends BaseProcessor {
/**
* Create a new multi-file loader processor
* @param {Object} config - Processor configuration
*/
constructor(config = {}) {
super('multiFileLoader', config);
this.fileService = defaultFileService;
}
/**
* Process input by loading multiple files
* @param {*} input - Input data (usually null or path overrides)
* @param {Object} context - Processing context
* @returns {Promise<Array<Object>>} Loaded file data
* @protected
*/
async _process(input, context) {
const paths = input || this.config.paths || context.inputPaths;
if (!paths || !Array.isArray(paths) || paths.length === 0) {
throw new Error('No file paths specified');
}
try {
const results = [];
// Load each file
for (const filePath of paths) {
try {
const data = await this.fileService.readJsonFile(filePath);
results.push({
path: filePath,
data
});
} catch (error) {
if (this.config.continueOnError) {
// Log error but continue
if (context.logger) {
context.logger.warn(`Failed to load file ${filePath}: ${error.message}`);
}
} else {
throw error;
}
}
}
return results;
} catch (error) {
throw new Error(`Failed to load files: ${error.message}`);
}
}
}
module.exports = MultiFileLoaderProcessor;