mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-30 19:03:01 +01:00
Skip indexing non-existent folders on Desktop app
This commit is contained in:
parent
cd05f262a6
commit
5def14e3bb
1 changed files with 26 additions and 14 deletions
|
@ -121,24 +121,36 @@ function isSupportedFileType(filePath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function processDirectory(filesToPush, folder) {
|
function processDirectory(filesToPush, folder) {
|
||||||
const files = fs.readdirSync(folder.path, { withFileTypes: true });
|
try {
|
||||||
|
const files = fs.readdirSync(folder.path, { withFileTypes: true });
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const filePath = path.join(file.path, file.name || '');
|
const filePath = path.join(file.path, file.name || '');
|
||||||
// Skip hidden files and folders
|
// Skip hidden files and folders
|
||||||
if (file.name.startsWith('.')) {
|
if (file.name.startsWith('.')) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
// Add supported files to index
|
||||||
|
if (file.isFile() && isSupportedFileType(filePath)) {
|
||||||
|
console.log(`Add ${file.name} in ${file.path} for indexing`);
|
||||||
|
filesToPush.push(filePath);
|
||||||
|
}
|
||||||
|
// Recursively process subdirectories
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
processDirectory(filesToPush, {'path': filePath});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Add supported files to index
|
} catch (err) {
|
||||||
if (file.isFile() && isSupportedFileType(filePath)) {
|
if (err.code === 'EACCES') {
|
||||||
console.log(`Add ${file.name} in ${file.path} for indexing`);
|
console.error(`Access denied to ${folder.path}`);
|
||||||
filesToPush.push(filePath);
|
} else if (err.code === 'ENOENT') {
|
||||||
}
|
console.error(`${folder.path} does not exist`);
|
||||||
// Recursively process subdirectories
|
} else {
|
||||||
if (file.isDirectory()) {
|
console.error(`An error occurred while reading directory: ${error.message}`);
|
||||||
processDirectory(filesToPush, {'path': filePath});
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushDataToKhoj (regenerate = false) {
|
function pushDataToKhoj (regenerate = false) {
|
||||||
|
|
Loading…
Reference in a new issue