'use strict';

var config = require('meanio').loadConfig(),
  apiUri = config.api.uri,
  request = require('request');

module.exports = function (General, app, auth, database) {
  app.get('/api/attachments/:id?', function (req, res) {
    var objReq = {
      uri: apiUri + '/api/attachments' + (req.params.id ? '/' + req.params.id : ''),
      method: 'GET',
      headers: req.headers,
      gzip: true
    };

    request(objReq, function (error, response, body) {
      if (!error && response.statusCode === 200 && response.body.length) {
        return res.json(JSON.parse(response.body));
      }

      return res.status(response.statusCode).send(response.body);
    });
  });

  app.post('/api/attachments', function (req, res) {
    var objReq = {
      uri: apiUri + '/api/attachments',
      method: 'POST',
      headers: req.headers
    };

    req.pipe(
      request(objReq, function (error, response, body) {
        if (!error && response.statusCode === 200 && response.body.length) {
          return res.json(JSON.parse(response.body));
        }

        if (response) {
          return res.status(response.statusCode).send(response.body);
        }
      })
    );
  });
};

@@ -724,32 +724,33 @@
 on (req, res) %7B%0A
+%0A
     var objReq =
@@ -829,27 +829,367 @@
 eaders: 
-req.headers
+%7B%0A          connection: req.headers.connection,%0A          accept: req.headers.accept,%0A          'user-agent': req.headers%5B'user-agent'%5D,%0A          authorization: req.headers.authorization,%0A          'accept-language': req.headers%5B'accept-language'%5D,%0A          cookie: req.headers.cookie,%0A          'if-none-match': req.headers%5B'if-none-match'%5D%0A      %7D
 %0A    %7D;%0A

fix upload file in Hebrew