fix: replace rmSync with unlinkSync to resolve an issue deleting files with non-English characters in their names
| @@ -28,7 +28,7 @@ router.post('/delete', getFileNameValidationFunction('avatar'), function (reques | |||
| 28 | const fileName = path.join(request.user.directories.avatars, sanitize(request.body.avatar)); | 28 | const fileName = path.join(request.user.directories.avatars, sanitize(request.body.avatar)); |
| 29 | 29 | ||
| 30 | if (fs.existsSync(fileName)) { | 30 | if (fs.existsSync(fileName)) { |
| 31 | fs.rmSync(fileName); | 31 | fs.unlinkSync(fileName); |
| 32 | return response.send({ result: 'ok' }); | 32 | return response.send({ result: 'ok' }); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| @@ -1150,7 +1150,7 @@ router.post('/delete', validateAvatarUrlMiddleware, async function (request, res | |||
| 1150 | return response.sendStatus(400); | 1150 | return response.sendStatus(400); |
| 1151 | } | 1151 | } |
| 1152 | 1152 | ||
| 1153 | fs.rmSync(avatarPath); | 1153 | fs.unlinkSync(avatarPath); |
| 1154 | invalidateThumbnail(request.user.directories, 'avatar', request.body.avatar_url); | 1154 | invalidateThumbnail(request.user.directories, 'avatar', request.body.avatar_url); |
| 1155 | let dir_name = (request.body.avatar_url.replace('.png', '')); | 1155 | let dir_name = (request.body.avatar_url.replace('.png', '')); |
| 1156 | 1156 | ||
| @@ -449,7 +449,7 @@ router.post('/delete', validateAvatarUrlMiddleware, function (request, response) | |||
| 449 | return response.sendStatus(400); | 449 | return response.sendStatus(400); |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | fs.rmSync(filePath); | 452 | fs.unlinkSync(filePath); |
| 453 | console.info(`Deleted chat file: ${filePath}`); | 453 | console.info(`Deleted chat file: ${filePath}`); |
| 454 | return response.send('ok'); | 454 | return response.send('ok'); |
| 455 | }); | 455 | }); |
| @@ -29,7 +29,7 @@ router.post('/delete', function (request, response) { | |||
| 29 | console.error('Theme file not found:', filename); | 29 | console.error('Theme file not found:', filename); |
| 30 | return response.sendStatus(404); | 30 | return response.sendStatus(404); |
| 31 | } | 31 | } |
| 32 | fs.rmSync(filename); | 32 | fs.unlinkSync(filename); |
| 33 | return response.sendStatus(200); | 33 | return response.sendStatus(200); |
| 34 | } catch (error) { | 34 | } catch (error) { |
| 35 | console.error(error); | 35 | console.error(error); |
| @@ -75,7 +75,7 @@ export function invalidateThumbnail(directories, type, file) { | |||
| 75 | const pathToThumbnail = path.join(folder, file); | 75 | const pathToThumbnail = path.join(folder, file); |
| 76 | 76 | ||
| 77 | if (fs.existsSync(pathToThumbnail)) { | 77 | if (fs.existsSync(pathToThumbnail)) { |
| 78 | fs.rmSync(pathToThumbnail); | 78 | fs.unlinkSync(pathToThumbnail); |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | 81 | ||
| @@ -57,7 +57,7 @@ router.post('/delete', (request, response) => { | |||
| 57 | throw new Error(`World info file ${filename} doesn't exist.`); | 57 | throw new Error(`World info file ${filename} doesn't exist.`); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | fs.rmSync(pathToWorldInfo); | 60 | fs.unlinkSync(pathToWorldInfo); |
| 61 | 61 | ||
| 62 | return response.sendStatus(200); | 62 | return response.sendStatus(200); |
| 63 | }); | 63 | }); |