🛠️ refactor: Handle .webp, Improve File Life Cycle 📁 (#1213)

* fix: handle webp images correctly

* refactor: use the userPath from the start of the filecycle to avoid handling the blob, whose loading may fail upon user request

* refactor: delete temp files on reload and new chat
This commit is contained in:
Danny Avila 2023-11-24 16:45:06 -05:00 committed by GitHub
parent 650759306d
commit cc39074e0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 160 additions and 66 deletions

View file

@ -15,7 +15,8 @@ import type {
TConversation,
TGetConversationsResponse,
} from 'librechat-data-provider';
import type { TAskFunction, ExtendedFile } from '~/common';
import type { TAskFunction } from '~/common';
import useSetFilesToDelete from './useSetFilesToDelete';
import { useAuthContext } from './AuthContext';
import useNewConvo from './useNewConvo';
import useUserKey from './useUserKey';
@ -23,8 +24,9 @@ import store from '~/store';
// this to be set somewhere else
export default function useChatHelpers(index = 0, paramId: string | undefined) {
const [files, setFiles] = useState(new Map<string, ExtendedFile>());
const [files, setFiles] = useRecoilState(store.filesByIndex(index));
const [filesLoading, setFilesLoading] = useState(false);
const setFilesToDelete = useSetFilesToDelete();
const queryClient = useQueryClient();
const { isAuthenticated } = useAuthContext();
@ -190,6 +192,7 @@ export default function useChatHelpers(index = 0, paramId: string | undefined) {
if (reuseFiles && parentMessage.files?.length) {
currentMsg.files = parentMessage.files;
setFiles(new Map());
setFilesToDelete({});
} else if (files.size > 0) {
currentMsg.files = Array.from(files.values()).map((file) => ({
file_id: file.file_id,
@ -199,6 +202,7 @@ export default function useChatHelpers(index = 0, paramId: string | undefined) {
width: file.width,
}));
setFiles(new Map());
setFilesToDelete({});
}
// construct the placeholder response message