fix: recommend to use unlinkSync instead of rmSync, which has a better compatibility handling non-English characters
| @@ -235,14 +235,14 @@ router.post('/download', async (request, response) => { | ||
| 235 | 235 | const contentType = mime.lookup(temp_path) || 'application/octet-stream'; |
| 236 | 236 | response.setHeader('Content-Type', contentType); |
| 237 | 237 | response.send(fileContent); |
| 238 | 238 | fs.rmSyncunlinkSync(temp_path); |
| 239 | 239 | return; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Move into asset place |
| 243 | 243 | console.info('Download finished, moving file from', temp_path, 'to', file_path); |
| 244 | 244 | fs.copyFileSync(temp_path, file_path); |
| 245 | 245 | fs.rmSyncunlinkSync(temp_path); |
| 246 | 246 | response.sendStatus(200); |
| 247 | 247 | } |
| 248 | 248 | catch (error) { |
| @@ -53,7 +53,7 @@ router.post('/upload', async (request, response) => { | ||
| 53 | 53 | const filename = request.body.overwrite_name || `${Date.now()}.png`; |
| 54 | 54 | const pathToNewFile = path.join(request.user.directories.avatars, filename); |
| 55 | 55 | writeFileAtomicSync(pathToNewFile, image); |
| 56 | 56 | fs.rmSyncunlinkSync(pathToUpload); |
| 57 | 57 | return response.send({ path: filename }); |
| 58 | 58 | } catch (err) { |
| 59 | 59 | return response.status(400).send('Is not a valid image'); |
| @@ -204,7 +204,7 @@ router.post('/transcribe-audio', async function (request, response) { | ||
| 204 | 204 | console.debug('Transcribing audio with KoboldCpp', server); |
| 205 | 205 | |
| 206 | 206 | const fileBase64 = fs.readFileSync(request.file.path).toString('base64'); |
| 207 | 207 | fs.rmSyncunlinkSync(request.file.path); |
| 208 | 208 | |
| 209 | 209 | const headers = {}; |
| 210 | 210 | setAdditionalHeadersByType(headers, TEXTGEN_TYPES.KOBOLDCPP, server, request.user.directories); |
| @@ -30,7 +30,7 @@ router.post('/delete', getFileNameValidationFunction('bg'), function (request, r | ||
| 30 | 30 | return response.sendStatus(400); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | fs.rmSyncunlinkSync(fileName); |
| 34 | 34 | invalidateThumbnail(request.user.directories, 'bg', request.body.bg); |
| 35 | 35 | return response.send('ok'); |
| 36 | 36 | }); |
| @@ -52,7 +52,7 @@ router.post('/rename', function (request, response) { | ||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | fs.copyFileSync(oldFileName, newFileName); |
| 55 | 55 | fs.rmSyncunlinkSync(oldFileName); |
| 56 | 56 | invalidateThumbnail(request.user.directories, 'bg', request.body.old_bg); |
| 57 | 57 | return response.send('ok'); |
| 58 | 58 | }); |
| @@ -65,7 +65,7 @@ router.post('/upload', function (request, response) { | ||
| 65 | 65 | |
| 66 | 66 | try { |
| 67 | 67 | fs.copyFileSync(img_path, path.join(request.user.directories.backgrounds, filename)); |
| 68 | 68 | fs.rmSyncunlinkSync(img_path); |
| 69 | 69 | invalidateThumbnail(request.user.directories, 'bg', filename); |
| 70 | 70 | response.send(filename); |
| 71 | 71 | } catch (err) { |
| @@ -720,7 +720,7 @@ function convertWorldInfoToCharacterBook(name, entries) { | ||
| 720 | 720 | */ |
| 721 | 721 | async function importFromYaml(uploadPath, context, preservedFileName) { |
| 722 | 722 | const fileText = fs.readFileSync(uploadPath, 'utf8'); |
| 723 | 723 | fs.rmSyncunlinkSync(uploadPath); |
| 724 | 724 | const yamlData = yaml.parse(fileText); |
| 725 | 725 | console.info('Importing from YAML'); |
| 726 | 726 | yamlData.name = sanitize(yamlData.name); |
| @@ -754,7 +754,7 @@ async function importFromYaml(uploadPath, context, preservedFileName) { | ||
| 754 | 754 | */ |
| 755 | 755 | async function importFromCharX(uploadPath, { request }, preservedFileName) { |
| 756 | 756 | const data = fs.readFileSync(uploadPath).buffer; |
| 757 | 757 | fs.rmSyncunlinkSync(uploadPath); |
| 758 | 758 | console.info('Importing from CharX'); |
| 759 | 759 | const cardBuffer = await extractFileFromZipBuffer(data, 'card.json'); |
| 760 | 760 | |
| @@ -995,7 +995,7 @@ router.post('/rename', validateAvatarUrlMiddleware, async function (request, res | ||
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | // Remove the old character file |
| 998 | 998 | fs.rmSyncunlinkSync(oldAvatarPath); |
| 999 | 999 | |
| 1000 | 1000 | // Return new avatar name to ST |
| 1001 | 1001 | return response.send({ avatar: newAvatarName }); |
| @@ -433,7 +433,7 @@ router.post('/rename', validateAvatarUrlMiddleware, async function (request, res | ||
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | fs.copyFileSync(pathToOriginalFile, pathToRenamedFile); |
| 436 | 436 | fs.rmSyncunlinkSync(pathToOriginalFile); |
| 437 | 437 | console.info('Successfully renamed.'); |
| 438 | 438 | return response.send({ ok: true, sanitizedFileName }); |
| 439 | 439 | }); |
| @@ -665,7 +665,7 @@ router.post('/group/delete', (request, response) => { | ||
| 665 | 665 | const pathToFile = path.join(request.user.directories.groupChats, `${id}.jsonl`); |
| 666 | 666 | |
| 667 | 667 | if (fs.existsSync(pathToFile)) { |
| 668 | 668 | fs.rmSyncunlinkSync(pathToFile); |
| 669 | 669 | return response.send({ ok: true }); |
| 670 | 670 | } |
| 671 | 671 | |
| @@ -66,7 +66,7 @@ router.post('/delete', async (request, response) => { | ||
| 66 | 66 | return response.status(404).send('File not found'); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | fs.rmSyncunlinkSync(pathToDelete); |
| 70 | 70 | console.info(`Deleted file: ${request.body.path} from ${request.user.profile.handle}`); |
| 71 | 71 | return response.sendStatus(200); |
| 72 | 72 | } catch (error) { |
| @@ -117,7 +117,7 @@ router.post('/delete', async (request, response) => { | ||
| 117 | 117 | const pathToFile = path.join(request.user.directories.groupChats, `${id}.jsonl`); |
| 118 | 118 | |
| 119 | 119 | if (fs.existsSync(pathToFile)) { |
| 120 | 120 | fs.rmSyncunlinkSync(pathToFile); |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | } |
| @@ -126,7 +126,7 @@ router.post('/delete', async (request, response) => { | ||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (fs.existsSync(pathToGroup)) { |
| 129 | 129 | fs.rmSyncunlinkSync(pathToGroup); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | return response.send({ ok: true }); |
| @@ -234,7 +234,7 @@ router.post('/transcribe-audio', async (request, response) => { | ||
| 234 | 234 | return response.status(500).send(text); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | fs.rmSyncunlinkSync(request.file.path); |
| 238 | 238 | const data = await result.json(); |
| 239 | 239 | console.debug('OpenAI transcription response', data); |
| 240 | 240 | return response.json(data); |
| @@ -124,7 +124,7 @@ router.post('/delete-openai', function (request, response) { | ||
| 124 | 124 | const pathToFile = path.join(request.user.directories.openAI_Settings, `${name}.json`); |
| 125 | 125 | |
| 126 | 126 | if (fs.existsSync(pathToFile)) { |
| 127 | 127 | fs.rmSyncunlinkSync(pathToFile); |
| 128 | 128 | return response.send({ ok: true }); |
| 129 | 129 | } |
| 130 | 130 | |
| @@ -165,7 +165,7 @@ router.post('/delete', async (request, response) => { | ||
| 165 | 165 | // Remove existing sprite with the same label |
| 166 | 166 | for (const file of files) { |
| 167 | 167 | if (path.parse(file).name === spriteName) { |
| 168 | 168 | fs.rmSyncunlinkSync(path.join(spritesPath, file)); |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| @@ -206,7 +206,7 @@ router.post('/upload-zip', async (request, response) => { | ||
| 206 | 206 | const existingFile = files.find(file => path.parse(file).name === path.parse(filename).name); |
| 207 | 207 | |
| 208 | 208 | if (existingFile) { |
| 209 | 209 | fs.rmSyncunlinkSync(path.join(spritesPath, existingFile)); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // Write sprite buffer to disk |
| @@ -215,7 +215,7 @@ router.post('/upload-zip', async (request, response) => { | ||
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | // Remove uploaded ZIP file |
| 218 | 218 | fs.rmSyncunlinkSync(spritePackPath); |
| 219 | 219 | return response.send({ count: sprites.length }); |
| 220 | 220 | } catch (error) { |
| 221 | 221 | console.error(error); |
| @@ -251,7 +251,7 @@ router.post('/upload', async (request, response) => { | ||
| 251 | 251 | // Remove existing sprite with the same label |
| 252 | 252 | for (const file of files) { |
| 253 | 253 | if (path.parse(file).name === spriteName) { |
| 254 | 254 | fs.rmSyncunlinkSync(path.join(spritesPath, file)); |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| @@ -261,7 +261,7 @@ router.post('/upload', async (request, response) => { | ||
| 261 | 261 | // Copy uploaded file to sprites folder |
| 262 | 262 | fs.cpSync(spritePath, pathToFile); |
| 263 | 263 | // Remove uploaded file |
| 264 | 264 | fs.rmSyncunlinkSync(spritePath); |
| 265 | 265 | return response.sendStatus(200); |
| 266 | 266 | } catch (error) { |
| 267 | 267 | console.error(error); |
| @@ -419,7 +419,7 @@ export function removeOldBackups(directory, prefix, limit = null) { | ||
| 419 | 419 | break; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | fs.rmSyncunlinkSync(oldest); |
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | } |