mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00: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
|
|
@ -14,7 +14,7 @@ function encodeImage(imagePath) {
|
|||
});
|
||||
}
|
||||
|
||||
async function encodeAndMove(req, file) {
|
||||
async function updateAndEncode(req, file) {
|
||||
const { publicPath, imageOutput } = req.app.locals.config;
|
||||
const userPath = path.join(imageOutput, req.user.id);
|
||||
|
||||
|
|
@ -23,24 +23,16 @@ async function encodeAndMove(req, file) {
|
|||
}
|
||||
const filepath = path.join(publicPath, file.filepath);
|
||||
|
||||
if (!filepath.includes('temp')) {
|
||||
const base64 = await encodeImage(filepath);
|
||||
return [file, base64];
|
||||
}
|
||||
|
||||
const newPath = path.join(userPath, path.basename(file.filepath));
|
||||
await fs.promises.rename(filepath, newPath);
|
||||
const newFilePath = path.posix.join('/', 'images', req.user.id, path.basename(file.filepath));
|
||||
const promises = [];
|
||||
promises.push(updateFile({ file_id: file.file_id, filepath: newFilePath }));
|
||||
promises.push(encodeImage(newPath));
|
||||
promises.push(updateFile({ file_id: file.file_id }));
|
||||
promises.push(encodeImage(filepath));
|
||||
return await Promise.all(promises);
|
||||
}
|
||||
|
||||
async function encodeAndFormat(req, files) {
|
||||
const promises = [];
|
||||
for (let file of files) {
|
||||
promises.push(encodeAndMove(req, file));
|
||||
promises.push(updateAndEncode(req, file));
|
||||
}
|
||||
|
||||
// TODO: make detail configurable, as of now resizing is done
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue