Files
myDrive/backend/db/dbFactory.ts
T
oxmc ecc340e7b1
Release Please / release-please (push) Has been cancelled
Docker Build and Push (Development) / build-and-push-dev (push) Has been cancelled
feat: add dark mode UI and SQLite as alternate database backend
Dark mode: CSS custom properties + .dark class toggled via Redux/localStorage,
with a theme toggle in the Header and Settings page. Foundation didn't exist
yet despite prior assumption, so it was built from scratch.

SQLite: new DB_ENGINE=mongo|sqlite env var selects the metadata backend at
runtime (Mongo stays default, no behavior change unless opted in). File/thumbnail
bytes continue to use the existing fs/S3 storage path. Implemented via a shared
DB interface (dbTypes.ts) with parallel mongoDB/ and sqliteDB/ implementations,
selected through dbFactory.ts, with JWT/encryption logic extracted into
userCrypto.ts so both engines share it.
2026-07-05 04:18:33 -07:00

46 lines
1.4 KiB
TypeScript

import env from "../enviroment/env";
import { IFileDB, IFolderDB, IUserDB, IThumbnailDB } from "./dbTypes";
import MongoFileDB from "./mongoDB/fileDB";
import MongoFolderDB from "./mongoDB/folderDB";
import MongoUserDB from "./mongoDB/userDB";
import MongoThumbnailDB from "./mongoDB/thumbnailDB";
// The sqlite/* modules are required lazily (rather than statically imported)
// so that opening the sqlite connection - a side effect of importing
// db/connections/sqlite - only happens when DB_ENGINE=sqlite is actually
// selected, not on every process that merely imports this factory.
const isSqlite = () => env.dbEngine === "sqlite";
export const getFileDB = (): IFileDB => {
if (isSqlite()) {
const SqliteFileDB = require("./sqliteDB/fileDB").default;
return new SqliteFileDB();
}
return new MongoFileDB();
};
export const getFolderDB = (): IFolderDB => {
if (isSqlite()) {
const SqliteFolderDB = require("./sqliteDB/folderDB").default;
return new SqliteFolderDB();
}
return new MongoFolderDB();
};
export const getUserDB = (): IUserDB => {
if (isSqlite()) {
const SqliteUserDB = require("./sqliteDB/userDB").default;
return new SqliteUserDB();
}
return new MongoUserDB();
};
export const getThumbnailDB = (): IThumbnailDB => {
if (isSqlite()) {
const SqliteThumbnailDB = require("./sqliteDB/thumbnailDB").default;
return new SqliteThumbnailDB();
}
return new MongoThumbnailDB();
};