mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🛠️ 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:
parent
650759306d
commit
cc39074e0a
15 changed files with 160 additions and 66 deletions
|
|
@ -8,8 +8,8 @@ const router = express.Router();
|
|||
|
||||
const isUUID = z.string().uuid();
|
||||
|
||||
const isValidPath = (base, subfolder, filepath) => {
|
||||
const normalizedBase = path.resolve(base, subfolder, 'temp');
|
||||
const isValidPath = (req, base, subfolder, filepath) => {
|
||||
const normalizedBase = path.resolve(base, subfolder, req.user.id);
|
||||
const normalizedFilepath = path.resolve(filepath);
|
||||
return normalizedFilepath.startsWith(normalizedBase);
|
||||
};
|
||||
|
|
@ -20,7 +20,7 @@ const deleteFile = async (req, file) => {
|
|||
const subfolder = parts[1];
|
||||
const filepath = path.join(publicPath, file.filepath);
|
||||
|
||||
if (!isValidPath(publicPath, subfolder, filepath)) {
|
||||
if (!isValidPath(req, publicPath, subfolder, filepath)) {
|
||||
throw new Error('Invalid file path');
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +40,11 @@ router.delete('/', async (req, res) => {
|
|||
return isUUID.safeParse(file.file_id).success;
|
||||
});
|
||||
|
||||
if (files.length === 0) {
|
||||
res.status(204).json({ message: 'Nothing provided to delete' });
|
||||
return;
|
||||
}
|
||||
|
||||
const file_ids = files.map((file) => file.file_id);
|
||||
const promises = [];
|
||||
promises.push(await deleteFiles(file_ids));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue