mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01: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
27 lines
743 B
JavaScript
27 lines
743 B
JavaScript
const Banner = require('./schema/banner');
|
|
const logger = require('~/config/winston');
|
|
/**
|
|
* Retrieves the current active banner.
|
|
* @returns {Promise<Object|null>} The active banner object or null if no active banner is found.
|
|
*/
|
|
const getBanner = async (user) => {
|
|
try {
|
|
const now = new Date();
|
|
const banner = await Banner.findOne({
|
|
displayFrom: { $lte: now },
|
|
$or: [{ displayTo: { $gte: now } }, { displayTo: null }],
|
|
type: 'banner',
|
|
}).lean();
|
|
|
|
if (!banner || banner.isPublic || user) {
|
|
return banner;
|
|
}
|
|
|
|
return null;
|
|
} catch (error) {
|
|
logger.error('[getBanners] Error getting banners', error);
|
|
throw new Error('Error getting banners');
|
|
}
|
|
};
|
|
|
|
module.exports = { getBanner };
|