mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
🔑 feat: infinite key expiry (#3252)
This commit is contained in:
parent
1aad315de6
commit
1edbfdbce2
4 changed files with 37 additions and 23 deletions
|
@ -93,7 +93,7 @@ const getUserKeyExpiry = async ({ userId, name }) => {
|
|||
if (!keyValue) {
|
||||
return { expiresAt: null };
|
||||
}
|
||||
return { expiresAt: keyValue.expiresAt };
|
||||
return { expiresAt: keyValue.expiresAt || 'never' };
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -108,18 +108,23 @@ const getUserKeyExpiry = async ({ userId, name }) => {
|
|||
* @description This function either updates an existing user key or inserts a new one into the database,
|
||||
* after encrypting the provided value. It sets the provided expiry date for the key.
|
||||
*/
|
||||
const updateUserKey = async ({ userId, name, value, expiresAt }) => {
|
||||
const updateUserKey = async ({ userId, name, value, expiresAt = null }) => {
|
||||
const encryptedValue = encrypt(value);
|
||||
return await Key.findOneAndUpdate(
|
||||
{ userId, name },
|
||||
{
|
||||
userId,
|
||||
name,
|
||||
value: encryptedValue,
|
||||
expiresAt: new Date(expiresAt),
|
||||
},
|
||||
{ upsert: true, new: true },
|
||||
).lean();
|
||||
let updateObject = {
|
||||
userId,
|
||||
name,
|
||||
value: encryptedValue,
|
||||
};
|
||||
|
||||
// Only add expiresAt to the update object if it's not null
|
||||
if (expiresAt) {
|
||||
updateObject.expiresAt = new Date(expiresAt);
|
||||
}
|
||||
|
||||
return await Key.findOneAndUpdate({ userId, name }, updateObject, {
|
||||
upsert: true,
|
||||
new: true,
|
||||
}).lean();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue