fix(compliance): improve compliance
This commit is contained in:
@ -67,31 +67,42 @@ export class CorpusLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all files from a category
|
||||
* Load all files from a category (recursively)
|
||||
*/
|
||||
static async loadCategory(category: keyof typeof CorpusLoader.CATEGORIES): Promise<CorpusFile[]> {
|
||||
const categoryPath = this.CATEGORIES[category];
|
||||
const fullPath = path.join(this.basePath, categoryPath);
|
||||
|
||||
try {
|
||||
const entries = await fs.readdir(fullPath, { withFileTypes: true });
|
||||
const files: CorpusFile[] = [];
|
||||
|
||||
for (const entry of entries) {
|
||||
if (entry.isFile() && this.isInvoiceFile(entry.name)) {
|
||||
const filePath = path.join(categoryPath, entry.name);
|
||||
const stat = await fs.stat(path.join(this.basePath, filePath));
|
||||
// Recursive function to scan directories
|
||||
const scanDirectory = async (dirPath: string, relativePath: string = '') => {
|
||||
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const entryPath = path.join(dirPath, entry.name);
|
||||
const relativeFilePath = path.join(relativePath, entry.name);
|
||||
|
||||
files.push({
|
||||
path: filePath,
|
||||
format: this.detectFormatFromPath(filePath),
|
||||
category: category,
|
||||
size: stat.size,
|
||||
valid: !categoryPath.includes('fail')
|
||||
});
|
||||
if (entry.isDirectory()) {
|
||||
// Recursively scan subdirectories
|
||||
await scanDirectory(entryPath, relativeFilePath);
|
||||
} else if (entry.isFile() && this.isInvoiceFile(entry.name)) {
|
||||
const stat = await fs.stat(entryPath);
|
||||
const fullRelativePath = path.join(categoryPath, relativeFilePath);
|
||||
|
||||
files.push({
|
||||
path: fullRelativePath,
|
||||
format: this.detectFormatFromPath(fullRelativePath),
|
||||
category: category,
|
||||
size: stat.size,
|
||||
valid: !categoryPath.includes('fail')
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await scanDirectory(fullPath);
|
||||
return files;
|
||||
} catch (error) {
|
||||
console.warn(`Failed to load category ${category}: ${error.message}`);
|
||||
|
Reference in New Issue
Block a user