import mongoose, { Schema, Document, Types } from 'mongoose'; import { FileSources } from 'librechat-data-provider'; // @ts-ignore export interface IMongoFile extends Document { user: Types.ObjectId; conversationId?: string; file_id: string; temp_file_id?: string; bytes: number; filename: string; filepath: string; object: 'file'; embedded?: boolean; type: string; context?: string; usage: number; source: string; model?: string; width?: number; height?: number; metadata?: { fileIdentifier?: string; }; expiresAt?: Date; createdAt?: Date; updatedAt?: Date; } const file: Schema = new Schema( { user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', index: true, required: true, }, conversationId: { type: String, ref: 'Conversation', index: true, }, file_id: { type: String, index: true, required: true, }, temp_file_id: { type: String, }, bytes: { type: Number, required: true, }, filename: { type: String, required: true, }, filepath: { type: String, required: true, }, object: { type: String, required: true, default: 'file', }, embedded: { type: Boolean, }, type: { type: String, required: true, }, context: { type: String, }, usage: { type: Number, required: true, default: 0, }, source: { type: String, default: FileSources.local, }, model: { type: String, }, width: Number, height: Number, metadata: { fileIdentifier: String, }, expiresAt: { type: Date, expires: 3600, // 1 hour in seconds }, }, { timestamps: true, }, ); file.index({ createdAt: 1, updatedAt: 1 }); export default file;