From be74addce7093b553c76b9d10bc10d86826aef72 Mon Sep 17 00:00:00 2001 From: Samy Laumonier <159024@supinfo.com> Date: Wed, 24 Jun 2015 20:44:10 +0200 Subject: [PATCH] =?UTF-8?q?Augmentation=20de=20la=20taille=20limite=20des?= =?UTF-8?q?=20requ=C3=AAtes=20sur=20l'API=20Correction=20d'un=20bug=20lors?= =?UTF-8?q?=20de=20l'upload=20d'image=20via=20l'API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/router.js | 6 ++++++ private/doc/event/add.js | 14 ++++++-------- server/lib/api.js | 31 ++++++++++++++++++++++++------- 3 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 lib/router.js diff --git a/lib/router.js b/lib/router.js new file mode 100644 index 0000000..76b7cef --- /dev/null +++ b/lib/router.js @@ -0,0 +1,6 @@ +Router.configureBodyParsers = function() { + Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({ + extended: true, + limit: '20mb' + }), {where: 'server'}); +}; diff --git a/private/doc/event/add.js b/private/doc/event/add.js index f7d7a17..5b8e7b5 100644 --- a/private/doc/event/add.js +++ b/private/doc/event/add.js @@ -14,8 +14,8 @@ * @apiHeader {String} X-User-Id User ID * * @apiParam {String} name Name of the event - * @apiParam {Date} begin Begin date - * @apiParam {Date} end Ending date + * @apiParam {Date} begin Begin date, format: DD/MM/YYYY HH:mm + * @apiParam {Date} end Ending date, format: DD/MM/YYYY HH:mm * @apiParam {Double} price Price of the event * @apiParam {String} address Address where the event takes place * @apiParam {String} zipCode ZIP code @@ -24,7 +24,8 @@ * @apiParam {String} link Link to a website or to a page * @apiParam {String} comment Description of the event * @apiParam {String} image Format: "data:[MIME_TYPE];base64,[BASE64]". You have to replace "[MIME_TYPE]" with - * the image MIME type and "[BASE64]" with the base64 encoded image file. + * the image MIME type and "[BASE64]" with the base64 encoded image file. Request + * size limit: 20mb. * * @apiSuccess {String} status Request result * @apiSuccess {Object} id Event ID @@ -32,12 +33,9 @@ * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { + * "statusCode": 200, * "status": "success", - * "data": { - * "_id": "XbGwBxK9hc2NGeoi2", - * "name": "Event title", - * "description": "Event description" - * } + * "id": "XbGwBxK9hc2NGeoi2" * } * * @apiError EventNotFound The ID of the event was not found. diff --git a/server/lib/api.js b/server/lib/api.js index d4c6fb6..6866736 100644 --- a/server/lib/api.js +++ b/server/lib/api.js @@ -1,4 +1,6 @@ var base64Img = Meteor.npmRequire('base64-img'); +var fs = Meteor.npmRequire('fs'); +var path = Meteor.npmRequire('path'); restivusInit = function() { Restivus.configure({ @@ -88,18 +90,33 @@ restivusInit = function() { } this.bodyParams.groupId = this.user.groupId; + this.bodyParams.date = new Date(); + var image = this.bodyParams.image; delete this.bodyParams.image; - var id = Events.insert(this.bodyParams); - // Create image - base64Img.imgSync(image, UPLOAD_FULL_PATH, id, function(err) { - if (err) { - throw err; - } - }); + var id = Events.insert(this.bodyParams); if (id) { + // Create image + base64Img.imgSync(image, UPLOAD_FULL_PATH, id); + var files = fs.readdirSync(UPLOAD_FULL_PATH); + var imageExtension = null; + + files.forEach(function (file) { + if (file.lastIndexOf(id, 0) === 0) { + imageExtension = path.extname(file); + + return false; + } + }); + + Events.update(id, { + $set: { + imageExtension: imageExtension + } + }); + return { statusCode: 200, status: 'success',