Skip to content

Commit

Permalink
Merge pull request #5537 from Countly/dependabot/npm_and_yarn/jimp-1.6.0
Browse files Browse the repository at this point in the history
Bump jimp from 0.22.12 to 1.6.0
  • Loading branch information
ar2rsawseen authored Nov 28, 2024
2 parents a29ad15 + 8eb7c0e commit c077300
Show file tree
Hide file tree
Showing 5 changed files with 379 additions and 516 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Dependencies:
- Bump countly-sdk-web from 24.4.1 to 24.11.0
- Bump tslib from 2.7.0 to 2.8.1
- Bump form-data from 4.0.0 to 4.0.1
- Bump jimp from 0.22.12 to 1.6.0

## Version 24.05.19
Fixes:
Expand Down
23 changes: 8 additions & 15 deletions api/parts/mgmt/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ appsApi.getAppsDetails = function(params) {
* @param {params} params - params object with args to create app
* @return {object} return promise object;
**/
const iconUpload = function(params) {
const iconUpload = async function(params) {
const appId = params.app_id || common.sanitizeFilename(params.qstring.args.app_id);
if (params.files && params.files.app_image) {
const tmp_path = params.files.app_image.path,
Expand All @@ -183,25 +183,18 @@ const iconUpload = function(params) {
return Promise.reject();
}
try {
return jimp.read(tmp_path, function(err, icon) {
if (err) {
log.e(err, err.stack);
fs.unlink(tmp_path, function() {});
return true;
const icon = await jimp.Jimp.read(tmp_path);
const buffer = await icon.cover({h: 72, w: 72}).getBuffer(jimp.JimpMime.png);
countlyFs.saveData("appimages", target_path, buffer, {id: appId + ".png", writeMode: "overwrite"}, function(err3) {
if (err3) {
log.e(err3, err3.stack);
}
icon.cover(72, 72).getBuffer(jimp.MIME_PNG, function(err2, buffer) {
countlyFs.saveData("appimages", target_path, buffer, {id: appId + ".png", writeMode: "overwrite"}, function(err3) {
if (err3) {
log.e(err3, err3.stack);
}
fs.unlink(tmp_path, function() {});
});
});
});
}
catch (e) {
log.e(e.stack);
console.log("Problem uploading app icon", e);
}
fs.unlink(tmp_path, function() {});
}
};

Expand Down
47 changes: 18 additions & 29 deletions frontend/express/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
req.body.app_id = req.body.app_image_id;
}
var params = paramsGenerator({req, res});
validateCreate(params, 'global_upload', function() {
validateCreate(params, 'global_upload', async function() {
if (!req.session.uid && !req.body.app_image_id) {
res.end();
return false;
Expand All @@ -1634,25 +1634,18 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
}
plugins.callMethod("iconUpload", {req: req, res: res, next: next, data: req.body});
try {
jimp.read(tmp_path, function(err, icon) {
if (err) {
console.log(err, err.stack);
fs.unlink(tmp_path, function() {});
res.status(400).send(false);
return true;
}
icon.cover(72, 72).getBuffer(jimp.MIME_PNG, function(err2, buffer) {
countlyFs.saveData("appimages", target_path, buffer, {id: req.body.app_image_id + ".png", writeMode: "overwrite"}, function() {
fs.unlink(tmp_path, function() {});
res.send("appimages/" + req.body.app_image_id + ".png");
countlyDb.collection('apps').updateOne({_id: countlyDb.ObjectID(req.body.app_image_id)}, {'$set': {'has_image': true}}, function() {});
});
}); // save
const icon = await jimp.Jimp.read(tmp_path);
const buffer = await icon.cover({h: 72, w: 72}).getBuffer(jimp.JimpMime.png);
countlyFs.saveData("appimages", target_path, buffer, {id: req.body.app_image_id + ".png", writeMode: "overwrite"}, function() {
res.send("appimages/" + req.body.app_image_id + ".png");
countlyDb.collection('apps').updateOne({_id: countlyDb.ObjectID(req.body.app_image_id)}, {'$set': {'has_image': true}}, function() {});
});
}
catch (e) {
console.log(e.stack);
console.log("Problem uploading app icon", e);
res.status(400).send(false);
}
fs.unlink(tmp_path, function() {});
});
});

Expand Down Expand Up @@ -1694,23 +1687,19 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
}
plugins.callMethod("iconUpload", {req: req, res: res, next: next, data: req.body});
try {
jimp.read(tmp_path, function(err, icon) {
if (err) {
console.log(err, err.stack);
}
icon.cover(72, 72).getBuffer(jimp.MIME_PNG, function(err2, buffer) {
countlyFs.saveData("memberimages", target_path, buffer, {id: req.body.member_image_id + ".png", writeMode: "overwrite"}, function() {
fs.unlink(tmp_path, function() {});
countlyDb.collection('members').updateOne({_id: countlyDb.ObjectID(req.body.member_image_id + "")}, {'$set': {'member_image': "memberimages/" + req.body.member_image_id + ".png"}}, function() {
res.send("memberimages/" + req.body.member_image_id + ".png");
});
});
}); // save
const icon = await jimp.Jimp.read(tmp_path);
const buffer = await icon.cover({h: 72, w: 72}).getBuffer(jimp.JimpMime.png);
countlyFs.saveData("memberimages", target_path, buffer, {id: req.body.member_image_id + ".png", writeMode: "overwrite"}, function() {
countlyDb.collection('members').updateOne({_id: countlyDb.ObjectID(req.body.member_image_id + "")}, {'$set': {'member_image': "memberimages/" + req.body.member_image_id + ".png"}}, function() {
res.send("memberimages/" + req.body.member_image_id + ".png");
});
});
}
catch (e) {
console.log(e.stack);
console.log("Problem uploading member icon", e);
res.status(400).send(false);
}
fs.unlink(tmp_path, function() {});
});
});

Expand Down
Loading

0 comments on commit c077300

Please sign in to comment.