Skip to content

Commit a505082

Browse files
committed
feat: add source to MongoFile schema, as well as BatchFile, and ExtendedFile types
1 parent 0f6cf2d commit a505082

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

api/models/schema/fileSchema.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { FileSources } = require('librechat-data-provider');
12
const mongoose = require('mongoose');
23

34
/**
@@ -12,6 +13,7 @@ const mongoose = require('mongoose');
1213
* @property {'file'} object - Type of object, always 'file'
1314
* @property {string} type - Type of file
1415
* @property {number} usage - Number of uses of the file
16+
* @property {string} [source] - The source of the file
1517
* @property {number} [width] - Optional width of the file
1618
* @property {number} [height] - Optional height of the file
1719
* @property {Date} [expiresAt] - Optional height of the file
@@ -42,11 +44,6 @@ const fileSchema = mongoose.Schema(
4244
type: Number,
4345
required: true,
4446
},
45-
usage: {
46-
type: Number,
47-
required: true,
48-
default: 0,
49-
},
5047
filename: {
5148
type: String,
5249
required: true,
@@ -64,6 +61,15 @@ const fileSchema = mongoose.Schema(
6461
type: String,
6562
required: true,
6663
},
64+
usage: {
65+
type: Number,
66+
required: true,
67+
default: 0,
68+
},
69+
source: {
70+
type: String,
71+
default: FileSources.local,
72+
},
6773
width: Number,
6874
height: Number,
6975
expiresAt: {

client/src/common/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { FileSources } from 'librechat-data-provider';
12
import type {
23
TConversation,
34
TMessage,
@@ -230,6 +231,7 @@ export interface ExtendedFile {
230231
size: number;
231232
preview: string;
232233
progress: number;
234+
source?: FileSources;
233235
}
234236

235237
export type ContextType = { navVisible: boolean; setNavVisible: (visible: boolean) => void };

client/src/components/Chat/Input/Files/Images.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import debounce from 'lodash/debounce';
22
import { useState, useEffect, useCallback } from 'react';
3+
import { FileSources } from 'librechat-data-provider';
34
import type { BatchFile } from 'librechat-data-provider';
45
import { useDeleteFilesMutation } from '~/data-provider';
56
import { useSetFilesToDelete } from '~/hooks';
@@ -70,13 +71,20 @@ export default function Images({
7071
}
7172

7273
const deleteFile = (_file: ExtendedFile) => {
73-
const { file_id, progress, temp_file_id = '', filepath = '' } = _file;
74+
const {
75+
file_id,
76+
progress,
77+
temp_file_id = '',
78+
filepath = '',
79+
source = FileSources.local,
80+
} = _file;
7481
if (progress < 1) {
7582
return;
7683
}
77-
const file = {
84+
const file: BatchFile = {
7885
file_id,
7986
filepath,
87+
source,
8088
};
8189

8290
setFiles((currentFiles) => {

client/src/hooks/useFileHandling.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ const useFileHandling = () => {
133133
height: data.height,
134134
width: data.width,
135135
filename: data.filename,
136+
source: data.source,
136137
});
137138
}, 300);
138139
},

packages/data-provider/src/types/files.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export type DeleteFilesResponse = {
5151
export type BatchFile = {
5252
file_id: string;
5353
filepath: string;
54+
source: FileSources;
5455
};
5556

5657
export type DeleteFilesBody = {

0 commit comments

Comments
 (0)