Files
myDrive/backend/db/mongoDB/userDB.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

60 lines
1.4 KiB
TypeScript

import { ObjectId } from "mongodb";
import User from "../../models/user-model";
import { IUserDB } from "../dbTypes";
// READ
class UserDB implements IUserDB {
constructor() {}
getUserInfo = async (userID: string) => {
const user = await User.findOne({ _id: new ObjectId(userID) });
return user;
};
findByEmail = async (email: string) => {
const user = await User.findOne({ email });
return user;
};
findByCreds = async (email: string, password: string) => {
const userStatics = User as unknown as {
findByCreds: (email: string, password: string) => Promise<any>;
};
return userStatics.findByCreds(email, password);
};
createUser = async (email: string, password: string) => {
const user = new User({ email, password });
await user.save();
return user;
};
removeOldTokens = async (
userID: string,
uuid: string | undefined,
minusTime: number,
isTemp: boolean
) => {
uuid = uuid ? uuid : "unknown";
if (uuid === "unknown") return;
const field = isTemp ? "tempTokens" : "tokens";
await User.updateOne(
{ _id: new ObjectId(userID) },
{ $pull: { [field]: { uuid, time: { $lt: minusTime } } } }
);
};
removeTempTokenByValue = async (userID: string, token: string) => {
await User.updateOne(
{ _id: new ObjectId(userID) },
{ $pull: { tempTokens: { token } } }
);
};
}
export default UserDB;