Sanitize file names on chat renaming

3e2b892aaec238412ad9093427235ec4b597162e

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +8 -3Ignore whitespace
public/script.js+4 -0
@@ -8828,6 +8828,10 @@ export async function renameChat(oldFileName, newName) {
88288828 throw new Error('Server returned an error.');
88298829 }
88308830
8831+ if (data.sanitizedFileName) {
8832+ newName = data.sanitizedFileName;
8833+ }
8834+
88318835 if (selected_group) {
88328836 await renameGroupChat(selected_group, oldFileName, newName);
88338837 }
src/endpoints/chats.js+4 -3
@@ -199,8 +199,9 @@ router.post('/rename', jsonParser, async function (request, response) {
199199 const pathToFolder = request.body.is_group
200200 ? request.user.directories.groupChats
201201 : path.join(request.user.directories.chats, String(request.body.avatar_url).replace('.png', ''));
202202 const pathToOriginalFile = path.join(pathToFolder, sanitize(request.body.original_file));
203203 const pathToRenamedFile = path.join(pathToFolder, sanitize(request.body.renamed_file));
204+ const sanitizedFileName = path.parse(pathToRenamedFile).name;
204205 console.log('Old chat name', pathToOriginalFile);
205206 console.log('New chat name', pathToRenamedFile);
206207
@@ -212,7 +213,7 @@ router.post('/rename', jsonParser, async function (request, response) {
212213 fs.copyFileSync(pathToOriginalFile, pathToRenamedFile);
213214 fs.rmSync(pathToOriginalFile);
214215 console.log('Successfully renamed.');
215216 return response.send({ ok: true, sanitizedFileName });
216217});
217218
218219router.post('/delete', jsonParser, function (request, response) {