mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-04 14:57:42 +00:00
fix: cast file owners in atomic upserts
This commit is contained in:
parent
64a32166e0
commit
2cdd88133d
2 changed files with 20 additions and 0 deletions
|
|
@ -90,6 +90,23 @@ describe('File Methods', () => {
|
|||
expect(file?.expiresAt).toBeUndefined();
|
||||
});
|
||||
|
||||
it('casts string owner ids in atomic pipeline upserts', async () => {
|
||||
const fileId = uuidv4();
|
||||
const userId = new mongoose.Types.ObjectId();
|
||||
|
||||
const file = await fileMethods.createFile({
|
||||
file_id: fileId,
|
||||
user: userId.toString() as unknown as mongoose.Types.ObjectId,
|
||||
filename: 'owned.txt',
|
||||
filepath: '/uploads/owned.txt',
|
||||
type: 'text/plain',
|
||||
bytes: 100,
|
||||
});
|
||||
|
||||
expect(file?.user).toEqual(userId);
|
||||
await expect(File.countDocuments({ file_id: fileId, user: userId })).resolves.toBe(1);
|
||||
});
|
||||
|
||||
it('updates expiredAt monotonically with an atomic minimum', async () => {
|
||||
const fileId = uuidv4();
|
||||
const userId = new mongoose.Types.ObjectId();
|
||||
|
|
|
|||
|
|
@ -368,6 +368,9 @@ export function createFileMethods(mongoose: typeof import('mongoose')): {
|
|||
const definedFields = Object.fromEntries(
|
||||
Object.entries(fields).filter(([, value]) => value !== undefined),
|
||||
);
|
||||
if (definedFields.user != null) {
|
||||
definedFields.user = File.schema.path('user').cast(definedFields.user);
|
||||
}
|
||||
const insertDefaults = {
|
||||
object: { $ifNull: ['$object', 'file'] },
|
||||
usage: { $ifNull: ['$usage', 0] },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue