mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-10-23 18:43:21 +00:00
♻️ refactor: Share MAX_AUDIT_LOG_LIMIT between methods and handler
Renamed the methods-layer constant from the generic `MAX_LIMIT` to `MAX_AUDIT_LOG_LIMIT`, exported it through `@librechat/data-schemas`, and consumed it from the handler instead of duplicating `500` there. Now the limit is single-sourced; bumping it once updates both the clamp inside `listAuditLogPage` and the 400-error boundary the handler returns to clients.
This commit is contained in:
parent
b6eba41e29
commit
681fd73468
4 changed files with 8 additions and 6 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { PrincipalType } from 'librechat-data-provider';
|
||||
import { logger } from '@librechat/data-schemas';
|
||||
import { logger, MAX_AUDIT_LOG_LIMIT } from '@librechat/data-schemas';
|
||||
import type {
|
||||
AdminAuditLogEntry,
|
||||
AuditAction,
|
||||
|
|
@ -23,7 +23,6 @@ const VALID_PRINCIPAL_TYPES = new Set<string>(Object.values(PrincipalType));
|
|||
*/
|
||||
const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2}))?$/;
|
||||
const OBJECT_ID_RE = /^[a-fA-F0-9]{24}$/;
|
||||
const MAX_LIMIT = 500;
|
||||
|
||||
export interface AdminAuditLogDeps {
|
||||
listAuditLogPage: (
|
||||
|
|
@ -94,7 +93,8 @@ function parseLimit(
|
|||
const n = typeof raw === 'number' ? raw : Number.parseInt(String(raw), 10);
|
||||
if (!Number.isFinite(n)) return { ok: false, error: 'limit must be a number' };
|
||||
if (n < 1) return { ok: false, error: 'limit must be >= 1' };
|
||||
if (n > MAX_LIMIT) return { ok: false, error: `limit must be <= ${MAX_LIMIT}` };
|
||||
if (n > MAX_AUDIT_LOG_LIMIT)
|
||||
return { ok: false, error: `limit must be <= ${MAX_AUDIT_LOG_LIMIT}` };
|
||||
return { ok: true, value: Math.floor(n) };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export {
|
|||
validateSkillFrontmatter,
|
||||
validateSkillDescription,
|
||||
deriveStructuredFrontmatterFields,
|
||||
MAX_AUDIT_LOG_LIMIT,
|
||||
} from './methods';
|
||||
export type * from './types';
|
||||
export type * from './methods';
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import type {
|
|||
import logger from '~/config/winston';
|
||||
|
||||
const DEFAULT_LIMIT = 100;
|
||||
export const MAX_LIMIT = 500;
|
||||
export const MAX_AUDIT_LOG_LIMIT = 500;
|
||||
const MAX_SEARCH_LENGTH = 200;
|
||||
|
||||
export interface AuditLogMethods {
|
||||
|
|
@ -96,7 +96,7 @@ function buildFilter(
|
|||
|
||||
function clampLimit(limit?: number): number {
|
||||
if (!limit || Number.isNaN(limit) || limit < 1) return DEFAULT_LIMIT;
|
||||
return Math.min(Math.floor(limit), MAX_LIMIT);
|
||||
return Math.min(Math.floor(limit), MAX_AUDIT_LOG_LIMIT);
|
||||
}
|
||||
|
||||
export function createAuditLogMethods(mongoose: typeof import('mongoose')): AuditLogMethods {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import { createAccessRoleMethods, type AccessRoleMethods } from './accessRole';
|
|||
import { createUserGroupMethods, type UserGroupMethods } from './userGroup';
|
||||
import { createAclEntryMethods, permissionBitSupersets, type AclEntryMethods } from './aclEntry';
|
||||
import { createSystemGrantMethods, type SystemGrantMethods } from './systemGrant';
|
||||
import { createAuditLogMethods, type AuditLogMethods } from './auditLog';
|
||||
import { createAuditLogMethods, MAX_AUDIT_LOG_LIMIT, type AuditLogMethods } from './auditLog';
|
||||
import { createShareMethods, type ShareMethods } from './share';
|
||||
/* Tier 1 — Simple CRUD */
|
||||
import { createActionMethods, type ActionMethods } from './action';
|
||||
|
|
@ -102,6 +102,7 @@ export {
|
|||
deriveStructuredFrontmatterFields,
|
||||
inferSkillFileCategory,
|
||||
};
|
||||
export { MAX_AUDIT_LOG_LIMIT };
|
||||
|
||||
export type AllMethods = UserMethods &
|
||||
SessionMethods &
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue