Add comments and stuff

This commit is contained in:
city-unit
2023-08-20 00:15:57 -04:00
parent 24da113670
commit 3ce8343016
4 changed files with 63 additions and 1 deletions

View File

@@ -2614,7 +2614,12 @@ app.post('/uploaduseravatar', urlencodedParser, async (request, response) => {
});
/**
* Ensure the directory for the provided file path exists.
* If not, it will recursively create the directory.
*
* @param {string} filePath - The full path of the file for which the directory should be ensured.
*/
function ensureDirectoryExistence(filePath) {
const dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
@@ -2624,6 +2629,17 @@ function ensureDirectoryExistence(filePath) {
fs.mkdirSync(dirname);
}
/**
* Endpoint to handle image uploads.
* The image should be provided in the request body in base64 format.
* Optionally, a character name can be provided to save the image in a sub-folder.
*
* @route POST /uploadimage
* @param {Object} request.body - The request payload.
* @param {string} request.body.image - The base64 encoded image data.
* @param {string} [request.body.ch_name] - Optional character name to determine the sub-directory.
* @returns {Object} response - The response object containing the path where the image was saved.
*/
app.post('/uploadimage', jsonParser, async (request, response) => {
// Check for image data
if (!request.body || !request.body.image) {