Sotaro KARASAWA 9 ani în urmă
părinte
comite
50c1f18fc5
1 a modificat fișierele cu 6 adăugiri și 2 ștergeri
  1. 6 2
      lib/routes/attachment.js

+ 6 - 2
lib/routes/attachment.js

@@ -61,8 +61,8 @@ module.exports = function(crowi, app) {
    * @apiParam {File} file
    * @apiParam {File} file
    */
    */
   api.add = function(req, res){
   api.add = function(req, res){
-    var id = req.body.page_id,
-      path = decodeURIComponent(req.body.path),
+    var id = req.body.page_id || 0,
+      path = decodeURIComponent(req.body.path) || null,
       pageCreated = false,
       pageCreated = false,
       page = {};
       page = {};
 
 
@@ -76,6 +76,9 @@ module.exports = function(crowi, app) {
 
 
     new Promise(function(resolve, reject) {
     new Promise(function(resolve, reject) {
       if (id == 0) {
       if (id == 0) {
+        if (path === null) {
+          throw new Error('path required if page_id is not specified.');
+        }
         debug('Create page before file upload');
         debug('Create page before file upload');
         Page.create(path, '# '  + path, req.user, {grant: Page.GRANT_OWNER})
         Page.create(path, '# '  + path, req.user, {grant: Page.GRANT_OWNER})
           .then(function(page) {
           .then(function(page) {
@@ -133,6 +136,7 @@ module.exports = function(crowi, app) {
         })
         })
       ;
       ;
     }).catch(function(err) {
     }).catch(function(err) {
+      debug('Attachement upload error', err);
       return res.json(ApiResponse.error('Error.'));
       return res.json(ApiResponse.error('Error.'));
     });
     });
   };
   };