mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
🚀 feat: Banner (#3952)
* 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
This commit is contained in:
parent
07e5531b5b
commit
aea01f0bc5
26 changed files with 453 additions and 4 deletions
61
config/delete-banner.js
Normal file
61
config/delete-banner.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
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);
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue