Replace path "\" with "/" server-side
This commit is contained in:
parent
795ca2247b
commit
39d771cc4a
|
@ -167,7 +167,7 @@ export async function uploadFileAttachment(fileName, base64Data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseData = await result.json();
|
const responseData = await result.json();
|
||||||
return responseData.path.replace(/\\/g, '/');
|
return responseData.path;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toastr.error(String(error), 'Could not upload file');
|
toastr.error(String(error), 'Could not upload file');
|
||||||
console.error('Could not upload file', error);
|
console.error('Could not upload file', error);
|
||||||
|
|
|
@ -950,7 +950,7 @@ export async function saveBase64AsFile(base64Data, characterName, filename = '',
|
||||||
// If the response is successful, get the saved image path from the server's response
|
// If the response is successful, get the saved image path from the server's response
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const responseData = await response.json();
|
const responseData = await response.json();
|
||||||
return responseData.path.replace(/\\/g, '/'); // Replace backslashes with forward slashes
|
return responseData.path;
|
||||||
} else {
|
} else {
|
||||||
const errorData = await response.json();
|
const errorData = await response.json();
|
||||||
throw new Error(errorData.error || 'Failed to upload the image to the server');
|
throw new Error(errorData.error || 'Failed to upload the image to the server');
|
||||||
|
|
|
@ -1588,7 +1588,8 @@ app.post('/uploadimage', jsonParser, async (request, response) => {
|
||||||
const imageBuffer = Buffer.from(base64Data, 'base64');
|
const imageBuffer = Buffer.from(base64Data, 'base64');
|
||||||
await fs.promises.writeFile(pathToNewFile, imageBuffer);
|
await fs.promises.writeFile(pathToNewFile, imageBuffer);
|
||||||
// send the path to the image, relative to the client folder, which means removing the first folder from the path which is 'public'
|
// send the path to the image, relative to the client folder, which means removing the first folder from the path which is 'public'
|
||||||
pathToNewFile = pathToNewFile.split(path.sep).slice(1).join(path.sep);
|
// Use forward slashes, even on Windows
|
||||||
|
pathToNewFile = pathToNewFile.split(path.sep).slice(1).join('/');
|
||||||
response.send({ path: pathToNewFile });
|
response.send({ path: pathToNewFile });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
|
@ -102,7 +102,7 @@ router.post('/get', jsonParser, async (_, response) => {
|
||||||
file = path.normalize(file.replace('public' + path.sep, ''));
|
file = path.normalize(file.replace('public' + path.sep, ''));
|
||||||
if (file.includes('model') && file.endsWith('.json')) {
|
if (file.includes('model') && file.endsWith('.json')) {
|
||||||
//console.debug("Asset live2d model found:",file)
|
//console.debug("Asset live2d model found:",file)
|
||||||
output[folder].push(path.normalize(path.join(file)));
|
output[folder].push(path.normalize(file).replace(/\\/g, '/'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -115,7 +115,7 @@ router.post('/get', jsonParser, async (_, response) => {
|
||||||
});
|
});
|
||||||
output[folder] = [];
|
output[folder] = [];
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
output[folder].push(path.join('assets', folder, file));
|
output[folder].push(path.join('assets', folder, file).replace(/\\/g, '/'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ router.post('/upload', jsonParser, async (request, response) => {
|
||||||
|
|
||||||
const pathToUpload = path.join(DIRECTORIES.files, request.body.name);
|
const pathToUpload = path.join(DIRECTORIES.files, request.body.name);
|
||||||
writeFileSyncAtomic(pathToUpload, request.body.data, 'base64');
|
writeFileSyncAtomic(pathToUpload, request.body.data, 'base64');
|
||||||
const url = path.normalize(pathToUpload.replace('public' + path.sep, ''));
|
const url = path.normalize(pathToUpload.replace('public' + path.sep, '').replace(/\\/g, '/'));
|
||||||
return response.send({ path: url });
|
return response.send({ path: url });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
Loading…
Reference in New Issue