mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 10:20:15 +01:00
Move usermethods and models to data-schema
This commit is contained in:
parent
4808c5be48
commit
4049b5572c
93 changed files with 2396 additions and 1267 deletions
6
api/cache/banViolation.js
vendored
6
api/cache/banViolation.js
vendored
|
|
@ -1,8 +1,8 @@
|
|||
const { ViolationTypes } = require('librechat-data-provider');
|
||||
const { isEnabled, math, removePorts } = require('~/server/utils');
|
||||
const { deleteAllUserSessions } = require('~/models');
|
||||
const getLogStores = require('./getLogStores');
|
||||
const { logger } = require('~/config');
|
||||
const db = require('~/lib/db/connectDb');
|
||||
|
||||
const { BAN_VIOLATIONS, BAN_INTERVAL } = process.env ?? {};
|
||||
const interval = math(BAN_INTERVAL, 20);
|
||||
|
|
@ -32,7 +32,6 @@ const banViolation = async (req, res, errorMessage) => {
|
|||
if (!isEnabled(BAN_VIOLATIONS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!errorMessage) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -46,12 +45,11 @@ const banViolation = async (req, res, errorMessage) => {
|
|||
return;
|
||||
}
|
||||
|
||||
await deleteAllUserSessions({ userId: user_id });
|
||||
await db.models.Session.deleteAllUserSessions({ userId: user_id });
|
||||
res.clearCookie('refreshToken');
|
||||
|
||||
const banLogs = getLogStores(ViolationTypes.BAN);
|
||||
const duration = errorMessage.duration || banLogs.opts.ttl;
|
||||
|
||||
if (duration <= 0) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
35
api/cache/banViolation.spec.js
vendored
35
api/cache/banViolation.spec.js
vendored
|
|
@ -1,7 +1,40 @@
|
|||
const banViolation = require('./banViolation');
|
||||
|
||||
jest.mock('@librechat/data-schemas', () => {
|
||||
const sessionModelMock = {
|
||||
deleteAllUserSessions: jest.fn(),
|
||||
};
|
||||
|
||||
return {
|
||||
registerModels: jest.fn().mockReturnValue({
|
||||
Session: sessionModelMock,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
const mockModels = {
|
||||
Session: {
|
||||
deleteAllUserSessions: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
jest.mock('~/lib/db/connectDb', () => {
|
||||
return {
|
||||
connectDb: jest.fn(),
|
||||
get models() {
|
||||
return mockModels;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('~/server/utils', () => ({
|
||||
isEnabled: jest.fn(() => true), // default to false, override per test if needed
|
||||
math: jest.fn(() => 20), // default to false, override per test if needed
|
||||
removePorts: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('keyv');
|
||||
jest.mock('../models/Session');
|
||||
// jest.mock('../models/Session');
|
||||
// Mocking the getLogStores function
|
||||
jest.mock('./getLogStores', () => {
|
||||
return jest.fn().mockImplementation(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue