Skip to content
Snippets Groups Projects
Commit d5951fd5 authored by timothycarambat's avatar timothycarambat
Browse files

change path for file storage for cloud-base persistance

parent fc0431fc
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,9 @@ const Document = { ...@@ -19,7 +19,9 @@ const Document = {
const { open } = require("sqlite"); const { open } = require("sqlite");
const db = await open({ const db = await open({
filename: "anythingllm.db", filename: `${
!!process.env.STORAGE_DIR ? `${process.env.STORAGE_DIR}/` : ""
}anythingllm.db`,
driver: sqlite3.Database, driver: sqlite3.Database,
}); });
......
...@@ -17,7 +17,9 @@ const DocumentVectors = { ...@@ -17,7 +17,9 @@ const DocumentVectors = {
const { open } = require("sqlite"); const { open } = require("sqlite");
const db = await open({ const db = await open({
filename: "anythingllm.db", filename: `${
!!process.env.STORAGE_DIR ? `${process.env.STORAGE_DIR}/` : ""
}anythingllm.db`,
driver: sqlite3.Database, driver: sqlite3.Database,
}); });
......
...@@ -16,7 +16,9 @@ const Workspace = { ...@@ -16,7 +16,9 @@ const Workspace = {
const { open } = require("sqlite"); const { open } = require("sqlite");
const db = await open({ const db = await open({
filename: "anythingllm.db", filename: `${
!!process.env.STORAGE_DIR ? `${process.env.STORAGE_DIR}/` : ""
}anythingllm.db`,
driver: sqlite3.Database, driver: sqlite3.Database,
}); });
......
...@@ -14,7 +14,9 @@ const WorkspaceChats = { ...@@ -14,7 +14,9 @@ const WorkspaceChats = {
const { open } = require("sqlite"); const { open } = require("sqlite");
const db = await open({ const db = await open({
filename: "anythingllm.db", filename: `${
!!process.env.STORAGE_DIR ? `${process.env.STORAGE_DIR}/` : ""
}anythingllm.db`,
driver: sqlite3.Database, driver: sqlite3.Database,
}); });
......
...@@ -4,7 +4,11 @@ const { v5: uuidv5 } = require("uuid"); ...@@ -4,7 +4,11 @@ const { v5: uuidv5 } = require("uuid");
async function collectDocumentData(folderName = null) { async function collectDocumentData(folderName = null) {
if (!folderName) throw new Error("No docPath provided in request"); if (!folderName) throw new Error("No docPath provided in request");
const folder = path.resolve(__dirname, `../../documents/${folderName}`); const folder =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, `../../documents/${folderName}`)
: path.resolve(process.env.STORAGE_DIR, `documents/${folderName}`);
const dirExists = fs.existsSync(folder); const dirExists = fs.existsSync(folder);
if (!dirExists) if (!dirExists)
throw new Error( throw new Error(
...@@ -28,7 +32,11 @@ async function collectDocumentData(folderName = null) { ...@@ -28,7 +32,11 @@ async function collectDocumentData(folderName = null) {
// eg: youtube-subject/video-123.json // eg: youtube-subject/video-123.json
async function fileData(filePath = null) { async function fileData(filePath = null) {
if (!filePath) throw new Error("No docPath provided in request"); if (!filePath) throw new Error("No docPath provided in request");
const fullPath = path.resolve(__dirname, `../../documents/${filePath}`);
const fullPath =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, `../../documents/${filePath}`)
: path.resolve(process.env.STORAGE_DIR, `documents/${filePath}`);
const fileExists = fs.existsSync(fullPath); const fileExists = fs.existsSync(fullPath);
if (!fileExists) return null; if (!fileExists) return null;
...@@ -37,9 +45,12 @@ async function fileData(filePath = null) { ...@@ -37,9 +45,12 @@ async function fileData(filePath = null) {
} }
async function viewLocalFiles() { async function viewLocalFiles() {
const folder = path.resolve(__dirname, `../../documents`); const folder =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, `../../documents`)
: path.resolve(process.env.STORAGE_DIR, `documents`);
const dirExists = fs.existsSync(folder); const dirExists = fs.existsSync(folder);
if (!dirExists) return {}; if (!dirExists) fs.mkdirSync(folder);
const directory = { const directory = {
name: "documents", name: "documents",
...@@ -49,7 +60,12 @@ async function viewLocalFiles() { ...@@ -49,7 +60,12 @@ async function viewLocalFiles() {
for (const file of fs.readdirSync(folder)) { for (const file of fs.readdirSync(folder)) {
if (path.extname(file) === ".md") continue; if (path.extname(file) === ".md") continue;
const folderPath = path.resolve(__dirname, `../../documents/${file}`);
const folderPath =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, `../../documents/${file}`)
: path.resolve(process.env.STORAGE_DIR, `documents/${file}`);
const isFolder = fs.lstatSync(folderPath).isDirectory(); const isFolder = fs.lstatSync(folderPath).isDirectory();
if (isFolder) { if (isFolder) {
const subdocs = { const subdocs = {
...@@ -88,7 +104,10 @@ async function cachedVectorInformation(filename = null, checkOnly = false) { ...@@ -88,7 +104,10 @@ async function cachedVectorInformation(filename = null, checkOnly = false) {
if (!filename) return checkOnly ? false : { exists: false, chunks: [] }; if (!filename) return checkOnly ? false : { exists: false, chunks: [] };
const digest = uuidv5(filename, uuidv5.URL); const digest = uuidv5(filename, uuidv5.URL);
const file = path.resolve(__dirname, `../../vector-cache/${digest}.json`); const file =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, `../../vector-cache/${digest}.json`)
: path.resolve(process.env.STORAGE_DIR, `vector-cache/${digest}.json`);
const exists = fs.existsSync(file); const exists = fs.existsSync(file);
if (checkOnly) return exists; if (checkOnly) return exists;
...@@ -109,7 +128,10 @@ async function storeVectorResult(vectorData = [], filename = null) { ...@@ -109,7 +128,10 @@ async function storeVectorResult(vectorData = [], filename = null) {
console.log( console.log(
`Caching vectorized results of ${filename} to prevent duplicated embedding.` `Caching vectorized results of ${filename} to prevent duplicated embedding.`
); );
const folder = path.resolve(__dirname, `../../vector-cache`); const folder =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, `../../vector-cache`)
: path.resolve(process.env.STORAGE_DIR, `vector-cache`);
if (!fs.existsSync(folder)) fs.mkdirSync(folder); if (!fs.existsSync(folder)) fs.mkdirSync(folder);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment