Fixed potential indexing issues

This commit is contained in:
Simon Cambier
2023-01-20 22:56:02 +01:00
parent e243c32a8d
commit c1b3c6d0ec
4 changed files with 78 additions and 55 deletions

View File

@@ -60,12 +60,10 @@ async function getAndMapIndexedDocument(
}
// ** Image or PDF **
if (extractor) {
if (extractor.canFileBeExtracted(path)) {
content = await extractor.extractText(file)
} else {
throw new Error('Invalid file format: ' + file.path)
}
else if (extractor?.canFileBeExtracted(path)) {
content = await extractor.extractText(file)
} else {
throw new Error(`Unsupported file type: "${path}"`)
}
if (content === null || content === undefined) {
@@ -125,6 +123,10 @@ class CacheManager {
*/
private documents: Map<string, IndexedDocument> = new Map()
/**
* Set or update the live cache with the content of the given file.
* @param path
*/
public async addToLiveCache(path: string): Promise<void> {
try {
const doc = await getAndMapIndexedDocument(path)