<commit_before>/*
These are routes as defined in https://docs.google.com/document/d/1337m6i7Y0GPULKLsKpyHR4NRzRwhoxJnAZNnDFCigkc/edit#
Each route implementes a basic parameter/payload validation and a swagger API documentation description
*/
'use strict';

const Joi = require('joi'),
  handlers = require('./controllers/handler');

const MAX_FILESIZE_MB = 300;
const MAX_FILESIZE = MAX_FILESIZE_MB * 1024 * 1024;

module.exports = function(server) {

    //TODO: try multipart multipart/form-data?
    // SEE RISIS SERVER.JS FOR EXAMPLE
  //TODO figure out how I can send file as parameter - maybe filestream? should be POST!!!
  //Upload a PPTX powerpoint presentation which is converted to HTML
  server.route({
    //will be POST
    method: 'POST',
    path: '/importPPTX',
    handler: handlers.importPPTX,
    config: {
      cors: true,
      payload: {
        maxBytes: MAX_FILESIZE,
        parse: true,
        //allow: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' - works!
        //allow: 'application/x-www-form-urlencoded'
        allow: 'multipart/form-data'
      },
      //validate: {
    //    params: {
    //      payload: Joi.object().keys({
    //        file: Joi.string()
    //      }).requiredKeys('file')
    //    },
     // },
      tags: ['api'],
      description: 'Import PPTX presentation file to SlideWiki'
    }
  });

  server.route({
    //will be POST
    method: 'POST',
    path: '/importImage/{jwt}',

    handler: handlers.importImage,
    config: {
      cors: true,
      validate: {
        params: {
          jwt: Joi.string()
        },
      },
      payload: {
        parse: true,
        //allow: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' - works!
        //allow: 'application/x-www-form-urlencoded'
        //allow: 'multipart/form-data'
        maxBytes: 209715200,
        output:'stream',
      },
      //validate: {
    //    params: {
    //      payload: Joi.object().keys({
    //        file: Joi.string()
    //      }).requiredKeys('file')
    //    },
     // },
      tags: ['api'],
      description: 'Import image file to SlideWiki'
    }
  });

  server.route({
    //will be POST
    method: 'POST',
    path: '/importImagePaste/{jwt}',

    handler: handlers.importImagePaste,
    config: {
      cors: true,
      validate: {
        params: {
          jwt: Joi.string()
        },
      },
      payload: {
        parse: true,
        //allow: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' - works!
        //allow: 'application/x-www-form-urlencoded'
        //allow: 'multipart/form-data'
        maxBytes: 209715200,
        output:'stream',
      },
      //validate: {
    //    params: {
    //      payload: Joi.object().keys({
    //        file: Joi.string()
    //      }).requiredKeys('file')
    //    },
     // },
      tags: ['api'],
      description: 'Import image file, pasted in CKeditor in slide edit view, to SlideWiki'
    }
  });

  // server.route({// Dejan added this to test pptx2html in the microservice
  //   //will be POST
  //   method: 'POST',
  //   path: '/testPPTX2HTML',
  //   handler: handlers.testPPTX2HTML,
  //   config: {
  //     cors: true,
  //     payload: {
  //
  //     },
  //     //validate: {
  //   //    params: {
  //   //      payload: Joi.object().keys({
  //   //        file: Joi.string()
  //   //      }).requiredKeys('file')
  //   //    },<commit_msg>[description_improvement_of_importPPTX] Updated route description for importPPTX<commit_after>/*
These are routes as defined in https://docs.google.com/document/d/1337m6i7Y0GPULKLsKpyHR4NRzRwhoxJnAZNnDFCigkc/edit#
Each route implementes a basic parameter/payload validation and a swagger API documentation description
*/
'use strict';

const Joi = require('joi'),
  handlers = require('./controllers/handler');

const MAX_FILESIZE_MB = 300;
const MAX_FILESIZE = MAX_FILESIZE_MB * 1024 * 1024;

module.exports = function(server) {

    //TODO: try multipart multipart/form-data?
    // SEE RISIS SERVER.JS FOR EXAMPLE
  //TODO figure out how I can send file as parameter - maybe filestream? should be POST!!!
  //Upload a PPTX powerpoint presentation which is converted to HTML
  server.route({
    //will be POST
    method: 'POST',
    path: '/importPPTX',
    handler: handlers.importPPTX,
    config: {
      cors: true,
      payload: {
        maxBytes: MAX_FILESIZE,
        parse: true,
        //allow: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' - works!
        //allow: 'application/x-www-form-urlencoded'
        allow: 'multipart/form-data'
      },
      //validate: {
    //    params: {
    //      payload: Joi.object().keys({
    //        file: Joi.string()
    //      }).requiredKeys('file')
    //    },
     // },
      tags: ['api'],
      description: 'Import PPTX presentation file to SlideWiki. This route will retrieve multiform data with the following attributes in it: user (integer), jwt (string), language (string, 2 or 5 characters), license (string), title (string), description (string), tags (JSON), theme (string), filename (string) and file (binary). Example: https://github.com/slidewiki/slidewiki-platform/blob/master/services/import.js#L18',
      plugins: {
        'hapi-swagger': {
          responses: {
            ' 200 ': {
              'description': 'import completed',
              'headers': {
                'deckId': {
                  'description': 'Id of the new deck'
                },
                'noOfSlides': {
                  'description': 'Number of slides in the new deck'
                }
              }
            }
          }
        }
      }
    }
  });

  server.route({
    //will be POST
    method: 'POST',
    path: '/importImage/{jwt}',

    handler: handlers.importImage,
    config: {
      cors: true,
      validate: {
        params: {
          jwt: Joi.string()
        },
      },
      payload: {
        parse: true,
        //allow: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' - works!
        //allow: 'application/x-www-form-urlencoded'
        //allow: 'multipart/form-data'
        maxBytes: 209715200,
        output:'stream',
      },
      //validate: {
    //    params: {
    //      payload: Joi.object().keys({
    //        file: Joi.string()
    //      }).requiredKeys('file')
    //    },
     // },
      tags: ['api'],
      description: 'Import image file to SlideWiki. This is only used by CKEditor and is bounded to it.'
    }
  });

  server.route({
    //will be POST
    method: 'POST',
    path: '/importImagePaste/{jwt}',

    handler: handlers.importImagePaste,
    config: {
      cors: true,
      validate: {
        params: {
          jwt: Joi.string()
        },
      },
      payload: {
        parse: true,
        //allow: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' - works!
        //allow: 'application/x-www-form-urlencoded'
        //allow: 'multipart/form-data'
        maxBytes: 209715200,
        output:'stream',
      },
      //validate: {
    //    params: {
    //      payload: Joi.object().keys({
    //        file: Joi.string()
    //      }).requiredKeys('file')
    //    },
     // },
      tags: ['api'],
      description: 'Import image file, pasted in CKeditor in slide edit view, to SlideWiki. This is only used by CKEditor and is bounded to it.'
    }
  });

  // server.route({// Dejan added this to test pptx2html in the microservice
  //   //will be POST
  //   method: 'POST',
  //   path: '/testPPTX2HTML',
  //   handler: handlers.testPPTX2HTML,
  //   config: {
  //     cors: true,
  //     payload: {
  //
  //     },
  //     //validate: {
  //   //    params: {
  //   //      payload: Joi.object().keys({
  //   //        file: Joi.string()
  //   //      }).requiredKeys('file')
  //   //    },
{'fraction_non_alphanumeric': 0.14558712597435253, 'fraction_numerical': 0.01093789288408348, 'mean_word_length': 1.9001093693036821, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 6, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '313865', 'n_tokens_mistral': 2587, 'n_tokens_neox': 2460, 'n_words': 570}