async function getAllFilesContentsForChat()

in wiki-interface/lib/file/file.js [24:47]


async function getAllFilesContentsForChat(dirPath, uuid) {
    let tempFile = configFile.getWorkDir() + "/temp_" + uuid + ".txt";

    const files = fs.readdirSync(dirPath);

    for (const file of files) {
        const filePath = path.join(dirPath, file);

        // Check if it's a directory
        if (fs.lstatSync(filePath).isDirectory()) {
            // Recursively call the function for subdirectories
            if (await configExcl.filterPath(file)) {
                await getAllFilesContentsForChat(filePath, uuid);
            }
        } else if (await configExcl.filterPath(file) && await configIncl.filterPath(file)) {
            // Read the file content
            let fileContent = fs.readFileSync(filePath, 'utf-8');
            // Add the file content to the temp file
            fs.appendFileSync(tempFile, '\n---------- ' + filePath + ' ----------\n');
            fs.appendFileSync(tempFile, fileContent + '\n---------- SEPARATOR ----------\n');

        }
    }
}