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

* feat: Add banner schema and model * feat: Add optional JwtAuth To handle the conditional logic with and without authentication within the model. * feat: Add an endpoint to retrieve a banner * feat: Add implementation for client to use banner and access API * feat: Display a banner on UI * feat: Script for updating and deleting banners * style: Update banner style * fix: Adjust the height when the banner is displayed * fix: failed specs
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
const path = require('path');
|
|
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
|
const { askQuestion, silentExit } = require('./helpers');
|
|
const Banner = require('~/models/schema/banner');
|
|
const connect = require('./connect');
|
|
|
|
(async () => {
|
|
await connect();
|
|
|
|
console.purple('--------------------------');
|
|
console.purple('Delete the banner!');
|
|
console.purple('--------------------------');
|
|
|
|
const now = new Date();
|
|
|
|
try {
|
|
const banner = await Banner.findOne({
|
|
displayFrom: { $lte: now },
|
|
$or: [{ displayTo: { $gte: now } }, { displayTo: null }],
|
|
});
|
|
|
|
if (!banner) {
|
|
console.yellow('No banner found to delete.');
|
|
silentExit(0);
|
|
}
|
|
|
|
console.purple('Current banner:');
|
|
console.log(`Message: ${banner.message}`);
|
|
console.log(`Display From: ${banner.displayFrom}`);
|
|
console.log(`Display To: ${banner.displayTo || 'Not specified'}`);
|
|
console.log(`Is Public: ${banner.isPublic}`);
|
|
|
|
const confirmDelete = await askQuestion('Do you want to delete this banner? (y/N): ');
|
|
|
|
if (confirmDelete.toLowerCase() === 'y') {
|
|
await Banner.findByIdAndDelete(banner._id);
|
|
console.green('Banner deleted successfully!');
|
|
} else {
|
|
console.yellow('Banner deletion cancelled.');
|
|
}
|
|
} catch (error) {
|
|
console.red('Error: ' + error.message);
|
|
console.error(error);
|
|
silentExit(1);
|
|
}
|
|
|
|
silentExit(0);
|
|
})();
|
|
|
|
process.on('uncaughtException', (err) => {
|
|
if (!err.message.includes('fetch failed')) {
|
|
console.error('There was an uncaught error:');
|
|
console.error(err);
|
|
}
|
|
|
|
if (err.message.includes('fetch failed')) {
|
|
return;
|
|
} else {
|
|
process.exit(1);
|
|
}
|
|
});
|