mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-19 20:50:09 +01:00
452582489e
* feat: implement github repo loading fix: purge of folders fix: rendering of sub-files * noshow delete on custom-documents * Add API key support because of rate limits * WIP for frontend of data connectors * wip * Add frontend form for GitHub repo data connector * remove console.logs block custom-documents from being deleted * remove _meta unused arg * Add support for ignore pathing in request Ignore path input via tagging * Update hint
60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const { purgeVectorCache, purgeSourceDocument } = require(".");
|
|
const { Document } = require("../../models/documents");
|
|
const { Workspace } = require("../../models/workspace");
|
|
|
|
async function purgeDocument(filename) {
|
|
const workspaces = await Workspace.where();
|
|
for (const workspace of workspaces) {
|
|
await Document.removeDocuments(workspace, [filename]);
|
|
}
|
|
await purgeVectorCache(filename);
|
|
await purgeSourceDocument(filename);
|
|
return;
|
|
}
|
|
|
|
async function purgeFolder(folderName) {
|
|
if (folderName === "custom-documents") return;
|
|
const documentsFolder =
|
|
process.env.NODE_ENV === "development"
|
|
? path.resolve(__dirname, `../../storage/documents`)
|
|
: path.resolve(process.env.STORAGE_DIR, `documents`);
|
|
|
|
const folderPath = path.resolve(documentsFolder, folderName);
|
|
const filenames = fs
|
|
.readdirSync(folderPath)
|
|
.map((file) => path.join(folderName, file));
|
|
const workspaces = await Workspace.where();
|
|
|
|
const purgePromises = [];
|
|
// Remove associated Vector-cache files
|
|
for (const filename of filenames) {
|
|
const rmVectorCache = () =>
|
|
new Promise((resolve) =>
|
|
purgeVectorCache(filename).then(() => resolve(true))
|
|
);
|
|
purgePromises.push(rmVectorCache);
|
|
}
|
|
|
|
// Remove workspace document associations
|
|
for (const workspace of workspaces) {
|
|
const rmWorkspaceDoc = () =>
|
|
new Promise((resolve) =>
|
|
Document.removeDocuments(workspace, filenames).then(() => resolve(true))
|
|
);
|
|
purgePromises.push(rmWorkspaceDoc);
|
|
}
|
|
|
|
await Promise.all(purgePromises.flat().map((f) => f()));
|
|
fs.rmSync(folderPath, { recursive: true }); // Delete root document and source files.
|
|
|
|
return;
|
|
}
|
|
|
|
module.exports = {
|
|
purgeDocument,
|
|
purgeFolder,
|
|
};
|