mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
fix: recommend to use unlinkSync instead of rmSync, which has a better compatibility handling non-English characters
This commit is contained in:
@@ -235,14 +235,14 @@ router.post('/download', async (request, response) => {
|
||||
const contentType = mime.lookup(temp_path) || 'application/octet-stream';
|
||||
response.setHeader('Content-Type', contentType);
|
||||
response.send(fileContent);
|
||||
fs.rmSync(temp_path);
|
||||
fs.unlinkSync(temp_path);
|
||||
return;
|
||||
}
|
||||
|
||||
// Move into asset place
|
||||
console.info('Download finished, moving file from', temp_path, 'to', file_path);
|
||||
fs.copyFileSync(temp_path, file_path);
|
||||
fs.rmSync(temp_path);
|
||||
fs.unlinkSync(temp_path);
|
||||
response.sendStatus(200);
|
||||
}
|
||||
catch (error) {
|
||||
|
@@ -53,7 +53,7 @@ router.post('/upload', async (request, response) => {
|
||||
const filename = request.body.overwrite_name || `${Date.now()}.png`;
|
||||
const pathToNewFile = path.join(request.user.directories.avatars, filename);
|
||||
writeFileAtomicSync(pathToNewFile, image);
|
||||
fs.rmSync(pathToUpload);
|
||||
fs.unlinkSync(pathToUpload);
|
||||
return response.send({ path: filename });
|
||||
} catch (err) {
|
||||
return response.status(400).send('Is not a valid image');
|
||||
|
@@ -204,7 +204,7 @@ router.post('/transcribe-audio', async function (request, response) {
|
||||
console.debug('Transcribing audio with KoboldCpp', server);
|
||||
|
||||
const fileBase64 = fs.readFileSync(request.file.path).toString('base64');
|
||||
fs.rmSync(request.file.path);
|
||||
fs.unlinkSync(request.file.path);
|
||||
|
||||
const headers = {};
|
||||
setAdditionalHeadersByType(headers, TEXTGEN_TYPES.KOBOLDCPP, server, request.user.directories);
|
||||
|
@@ -30,7 +30,7 @@ router.post('/delete', getFileNameValidationFunction('bg'), function (request, r
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
fs.rmSync(fileName);
|
||||
fs.unlinkSync(fileName);
|
||||
invalidateThumbnail(request.user.directories, 'bg', request.body.bg);
|
||||
return response.send('ok');
|
||||
});
|
||||
@@ -52,7 +52,7 @@ router.post('/rename', function (request, response) {
|
||||
}
|
||||
|
||||
fs.copyFileSync(oldFileName, newFileName);
|
||||
fs.rmSync(oldFileName);
|
||||
fs.unlinkSync(oldFileName);
|
||||
invalidateThumbnail(request.user.directories, 'bg', request.body.old_bg);
|
||||
return response.send('ok');
|
||||
});
|
||||
@@ -65,7 +65,7 @@ router.post('/upload', function (request, response) {
|
||||
|
||||
try {
|
||||
fs.copyFileSync(img_path, path.join(request.user.directories.backgrounds, filename));
|
||||
fs.rmSync(img_path);
|
||||
fs.unlinkSync(img_path);
|
||||
invalidateThumbnail(request.user.directories, 'bg', filename);
|
||||
response.send(filename);
|
||||
} catch (err) {
|
||||
|
@@ -720,7 +720,7 @@ function convertWorldInfoToCharacterBook(name, entries) {
|
||||
*/
|
||||
async function importFromYaml(uploadPath, context, preservedFileName) {
|
||||
const fileText = fs.readFileSync(uploadPath, 'utf8');
|
||||
fs.rmSync(uploadPath);
|
||||
fs.unlinkSync(uploadPath);
|
||||
const yamlData = yaml.parse(fileText);
|
||||
console.info('Importing from YAML');
|
||||
yamlData.name = sanitize(yamlData.name);
|
||||
@@ -754,7 +754,7 @@ async function importFromYaml(uploadPath, context, preservedFileName) {
|
||||
*/
|
||||
async function importFromCharX(uploadPath, { request }, preservedFileName) {
|
||||
const data = fs.readFileSync(uploadPath).buffer;
|
||||
fs.rmSync(uploadPath);
|
||||
fs.unlinkSync(uploadPath);
|
||||
console.info('Importing from CharX');
|
||||
const cardBuffer = await extractFileFromZipBuffer(data, 'card.json');
|
||||
|
||||
@@ -995,7 +995,7 @@ router.post('/rename', validateAvatarUrlMiddleware, async function (request, res
|
||||
}
|
||||
|
||||
// Remove the old character file
|
||||
fs.rmSync(oldAvatarPath);
|
||||
fs.unlinkSync(oldAvatarPath);
|
||||
|
||||
// Return new avatar name to ST
|
||||
return response.send({ avatar: newAvatarName });
|
||||
|
@@ -433,7 +433,7 @@ router.post('/rename', validateAvatarUrlMiddleware, async function (request, res
|
||||
}
|
||||
|
||||
fs.copyFileSync(pathToOriginalFile, pathToRenamedFile);
|
||||
fs.rmSync(pathToOriginalFile);
|
||||
fs.unlinkSync(pathToOriginalFile);
|
||||
console.info('Successfully renamed.');
|
||||
return response.send({ ok: true, sanitizedFileName });
|
||||
});
|
||||
@@ -665,7 +665,7 @@ router.post('/group/delete', (request, response) => {
|
||||
const pathToFile = path.join(request.user.directories.groupChats, `${id}.jsonl`);
|
||||
|
||||
if (fs.existsSync(pathToFile)) {
|
||||
fs.rmSync(pathToFile);
|
||||
fs.unlinkSync(pathToFile);
|
||||
return response.send({ ok: true });
|
||||
}
|
||||
|
||||
|
@@ -66,7 +66,7 @@ router.post('/delete', async (request, response) => {
|
||||
return response.status(404).send('File not found');
|
||||
}
|
||||
|
||||
fs.rmSync(pathToDelete);
|
||||
fs.unlinkSync(pathToDelete);
|
||||
console.info(`Deleted file: ${request.body.path} from ${request.user.profile.handle}`);
|
||||
return response.sendStatus(200);
|
||||
} catch (error) {
|
||||
|
@@ -117,7 +117,7 @@ router.post('/delete', async (request, response) => {
|
||||
const pathToFile = path.join(request.user.directories.groupChats, `${id}.jsonl`);
|
||||
|
||||
if (fs.existsSync(pathToFile)) {
|
||||
fs.rmSync(pathToFile);
|
||||
fs.unlinkSync(pathToFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ router.post('/delete', async (request, response) => {
|
||||
}
|
||||
|
||||
if (fs.existsSync(pathToGroup)) {
|
||||
fs.rmSync(pathToGroup);
|
||||
fs.unlinkSync(pathToGroup);
|
||||
}
|
||||
|
||||
return response.send({ ok: true });
|
||||
|
@@ -234,7 +234,7 @@ router.post('/transcribe-audio', async (request, response) => {
|
||||
return response.status(500).send(text);
|
||||
}
|
||||
|
||||
fs.rmSync(request.file.path);
|
||||
fs.unlinkSync(request.file.path);
|
||||
const data = await result.json();
|
||||
console.debug('OpenAI transcription response', data);
|
||||
return response.json(data);
|
||||
|
@@ -124,7 +124,7 @@ router.post('/delete-openai', function (request, response) {
|
||||
const pathToFile = path.join(request.user.directories.openAI_Settings, `${name}.json`);
|
||||
|
||||
if (fs.existsSync(pathToFile)) {
|
||||
fs.rmSync(pathToFile);
|
||||
fs.unlinkSync(pathToFile);
|
||||
return response.send({ ok: true });
|
||||
}
|
||||
|
||||
|
@@ -165,7 +165,7 @@ router.post('/delete', async (request, response) => {
|
||||
// Remove existing sprite with the same label
|
||||
for (const file of files) {
|
||||
if (path.parse(file).name === spriteName) {
|
||||
fs.rmSync(path.join(spritesPath, file));
|
||||
fs.unlinkSync(path.join(spritesPath, file));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ router.post('/upload-zip', async (request, response) => {
|
||||
const existingFile = files.find(file => path.parse(file).name === path.parse(filename).name);
|
||||
|
||||
if (existingFile) {
|
||||
fs.rmSync(path.join(spritesPath, existingFile));
|
||||
fs.unlinkSync(path.join(spritesPath, existingFile));
|
||||
}
|
||||
|
||||
// Write sprite buffer to disk
|
||||
@@ -215,7 +215,7 @@ router.post('/upload-zip', async (request, response) => {
|
||||
}
|
||||
|
||||
// Remove uploaded ZIP file
|
||||
fs.rmSync(spritePackPath);
|
||||
fs.unlinkSync(spritePackPath);
|
||||
return response.send({ count: sprites.length });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -251,7 +251,7 @@ router.post('/upload', async (request, response) => {
|
||||
// Remove existing sprite with the same label
|
||||
for (const file of files) {
|
||||
if (path.parse(file).name === spriteName) {
|
||||
fs.rmSync(path.join(spritesPath, file));
|
||||
fs.unlinkSync(path.join(spritesPath, file));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ router.post('/upload', async (request, response) => {
|
||||
// Copy uploaded file to sprites folder
|
||||
fs.cpSync(spritePath, pathToFile);
|
||||
// Remove uploaded file
|
||||
fs.rmSync(spritePath);
|
||||
fs.unlinkSync(spritePath);
|
||||
return response.sendStatus(200);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
@@ -419,7 +419,7 @@ export function removeOldBackups(directory, prefix, limit = null) {
|
||||
break;
|
||||
}
|
||||
|
||||
fs.rmSync(oldest);
|
||||
fs.unlinkSync(oldest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user