mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00

* WIP: initial logging changes add several transports in ~/config/winston omit messages in logs, truncate long strings add short blurb in dotenv for debug logging GoogleClient: using logger OpenAIClient: using logger, handleOpenAIErrors Adding typedef for payload message bumped winston and using winston-daily-rotate-file moved config for server paths to ~/config dir Added `DEBUG_LOGGING=true` to .env.example * WIP: Refactor logging statements in code * WIP: Refactor logging statements and import configurations * WIP: Refactor logging statements and import configurations * refactor: broadcast Redis initialization message with `info` not `debug` * refactor: complete Refactor logging statements and import configurations * chore: delete unused tools * fix: circular dependencies due to accessing logger * refactor(handleText): handle booleans and write tests * refactor: redact sensitive values, better formatting * chore: improve log formatting, avoid passing strings to 2nd arg * fix(ci): fix jest tests due to logger changes * refactor(getAvailablePluginsController): cache plugins as they are static and avoids async addOpenAPISpecs call every time * chore: update docs * chore: update docs * chore: create separate meiliSync logger, clean up logs to avoid being unnecessarily verbose * chore: spread objects where they are commonly logged to allow string truncation * chore: improve error log formatting
86 lines
2.1 KiB
JavaScript
86 lines
2.1 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const { logger } = require('~/config');
|
|
|
|
const major = [0, 0];
|
|
const minor = [0, 0];
|
|
const patch = [0, 5];
|
|
|
|
const configSchema = mongoose.Schema(
|
|
{
|
|
tag: {
|
|
type: String,
|
|
required: true,
|
|
validate: {
|
|
validator: function (tag) {
|
|
const [part1, part2, part3] = tag.replace('v', '').split('.').map(Number);
|
|
|
|
// Check if all parts are numbers
|
|
if (isNaN(part1) || isNaN(part2) || isNaN(part3)) {
|
|
return false;
|
|
}
|
|
|
|
// Check if all parts are within their respective ranges
|
|
if (part1 < major[0] || part1 > major[1]) {
|
|
return false;
|
|
}
|
|
if (part2 < minor[0] || part2 > minor[1]) {
|
|
return false;
|
|
}
|
|
if (part3 < patch[0] || part3 > patch[1]) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
message: 'Invalid tag value',
|
|
},
|
|
},
|
|
searchEnabled: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
usersEnabled: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
startupCounts: {
|
|
type: Number,
|
|
default: 0,
|
|
},
|
|
},
|
|
{ timestamps: true },
|
|
);
|
|
|
|
// Instance method
|
|
configSchema.methods.incrementCount = function () {
|
|
this.startupCounts += 1;
|
|
};
|
|
|
|
// Static methods
|
|
configSchema.statics.findByTag = async function (tag) {
|
|
return await this.findOne({ tag }).lean();
|
|
};
|
|
|
|
configSchema.statics.updateByTag = async function (tag, update) {
|
|
return await this.findOneAndUpdate({ tag }, update, { new: true });
|
|
};
|
|
|
|
const Config = mongoose.models.Config || mongoose.model('Config', configSchema);
|
|
|
|
module.exports = {
|
|
getConfigs: async (filter) => {
|
|
try {
|
|
return await Config.find(filter).lean();
|
|
} catch (error) {
|
|
logger.error('Error getting configs', error);
|
|
return { config: 'Error getting configs' };
|
|
}
|
|
},
|
|
deleteConfigs: async (filter) => {
|
|
try {
|
|
return await Config.deleteMany(filter);
|
|
} catch (error) {
|
|
logger.error('Error deleting configs', error);
|
|
return { config: 'Error deleting configs' };
|
|
}
|
|
},
|
|
};
|