Sanitize file names on chat renaming
| @@ -8828,6 +8828,10 @@ export async function renameChat(oldFileName, newName) { | ||
| 8828 | 8828 | throw new Error('Server returned an error.'); |
| 8829 | 8829 | } |
| 8830 | 8830 | |
| 8831 | + if (data.sanitizedFileName) { | |
| 8832 | + newName = data.sanitizedFileName; | |
| 8833 | + } | |
| 8834 | + | |
| 8831 | 8835 | if (selected_group) { |
| 8832 | 8836 | await renameGroupChat(selected_group, oldFileName, newName); |
| 8833 | 8837 | } |
| @@ -199,8 +199,9 @@ router.post('/rename', jsonParser, async function (request, response) { | ||
| 199 | 199 | const pathToFolder = request.body.is_group |
| 200 | 200 | ? request.user.directories.groupChats |
| 201 | 201 | : path.join(request.user.directories.chats, String(request.body.avatar_url).replace('.png', '')); |
| 202 | 202 | const pathToOriginalFile = path.join(pathToFolder, sanitize(request.body.original_file)); |
| 203 | 203 | const pathToRenamedFile = path.join(pathToFolder, sanitize(request.body.renamed_file)); |
| 204 | + const sanitizedFileName = path.parse(pathToRenamedFile).name; | |
| 204 | 205 | console.log('Old chat name', pathToOriginalFile); |
| 205 | 206 | console.log('New chat name', pathToRenamedFile); |
| 206 | 207 | |
| @@ -212,7 +213,7 @@ router.post('/rename', jsonParser, async function (request, response) { | ||
| 212 | 213 | fs.copyFileSync(pathToOriginalFile, pathToRenamedFile); |
| 213 | 214 | fs.rmSync(pathToOriginalFile); |
| 214 | 215 | console.log('Successfully renamed.'); |
| 215 | 216 | return response.send({ ok: true, sanitizedFileName }); |
| 216 | 217 | }); |
| 217 | 218 | |
| 218 | 219 | router.post('/delete', jsonParser, function (request, response) { |