|
1 | 1 | var _ = require('../lodash'),
|
2 |
| - sanitize = require('./sanitize').sanitize; |
| 2 | + sanitize = require('./sanitize').sanitize, |
| 3 | + contentTypeHeaderMap = { |
| 4 | + 'aac': 'audio/aac', |
| 5 | + 'abw': 'application/x-abiword', |
| 6 | + 'arc': 'application/x-freearc', |
| 7 | + 'avi': 'video/x-msvideo', |
| 8 | + 'azw': 'application/vnd.amazon.ebook', |
| 9 | + 'bin': 'application/octet-stream', |
| 10 | + 'bmp': 'image/bmp', |
| 11 | + 'bz': 'application/x-bzip', |
| 12 | + 'bz2': 'application/x-bzip2', |
| 13 | + 'csh': 'application/x-csh', |
| 14 | + 'css': 'text/css', |
| 15 | + 'csv': 'text/csv', |
| 16 | + 'doc': 'application/msword', |
| 17 | + 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
| 18 | + 'eot': 'application/vnd.ms-fontobject', |
| 19 | + 'epub': 'application/epub+zip', |
| 20 | + 'gif': 'image/gif', |
| 21 | + 'htm': 'text/html', |
| 22 | + 'html': 'text/html', |
| 23 | + 'ico': 'image/vnd.microsoft.icon', |
| 24 | + 'ics': 'text/calendar', |
| 25 | + 'jar': 'application/java-archive', |
| 26 | + 'jpeg': 'image/jpeg', |
| 27 | + 'jpg': 'image/jpeg', |
| 28 | + 'js': 'text/javascript', |
| 29 | + 'json': 'application/json', |
| 30 | + 'jsonld': 'application/ld+json', |
| 31 | + 'mid': 'audip/midi', |
| 32 | + 'midi': 'audio/midi', |
| 33 | + 'mjs': 'text/javascript', |
| 34 | + 'mp3': 'audio/mpeg', |
| 35 | + 'mpeg': 'video/mpeg', |
| 36 | + 'mpkg': 'application/vnd.apple.installer+xml', |
| 37 | + 'odp': 'application/vnd.oasis.opendocument.presentation', |
| 38 | + 'ods': 'application/vnd.oasis.opendocument.spreadsheet', |
| 39 | + 'odt': 'application/vnd.oasis.opendocument.text', |
| 40 | + 'oga': 'audio/ogg', |
| 41 | + 'ogv': 'video/ogg', |
| 42 | + 'ogx': 'application/ogg', |
| 43 | + 'otf': 'font/otf', |
| 44 | + 'png': 'image/png', |
| 45 | + 'pdf': 'application/pdf', |
| 46 | + 'ppt': 'application/vnd.ms-powerpoint', |
| 47 | + 'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
| 48 | + 'rar': 'application/x-rar-compressed', |
| 49 | + 'rtf': 'application/rtf', |
| 50 | + 'sh': 'application/x-sh', |
| 51 | + 'svg': 'image/svg+xml', |
| 52 | + 'swf': 'application/x-shockwave-flash', |
| 53 | + 'tar': 'application/x-tar', |
| 54 | + 'tif': 'image/tiff', |
| 55 | + 'tiff': 'image/tiff', |
| 56 | + 'ts': 'video/mp2t', |
| 57 | + 'ttf': 'font/ttf', |
| 58 | + 'txt': 'text/plain', |
| 59 | + 'vsd': 'application/vnd.visio', |
| 60 | + 'wav': 'audio/wav', |
| 61 | + 'weba': 'audio/webm', |
| 62 | + 'webm': 'video/webm', |
| 63 | + 'webp': 'image/webp', |
| 64 | + 'woff': 'font/woff', |
| 65 | + 'woff2': 'font/woff2', |
| 66 | + 'xhtml': 'application/xhtml+xml', |
| 67 | + 'xls': 'application/vnd.ms-excel', |
| 68 | + 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
| 69 | + 'xml': 'text/xml', |
| 70 | + 'xul': 'application/vnd.mozilla.xul+xml', |
| 71 | + 'zip': 'application/zip', |
| 72 | + '3gp': 'video/3gpp', |
| 73 | + '7z': 'application/x-7z-compressed', |
| 74 | + '7-zip': 'application/x-7z-compressed' |
| 75 | + }; |
3 | 76 |
|
4 | 77 | /**
|
5 | 78 | * Used to parse the body of the postman SDK-request and return in the desired format
|
@@ -64,7 +137,16 @@ module.exports = function (request, indentation, bodyTrim) {
|
64 | 137 | `'${sanitize(value.value, request.body.mode, bodyTrim)}'`);
|
65 | 138 | });
|
66 | 139 | bodyFileMap = _.map(_.filter(enabledBodyList, {'type': 'file'}), function (value) {
|
67 |
| - return `${indentation}('${value.key}', open('${sanitize(value.src, request.body.mode, bodyTrim)}','rb'))`; |
| 140 | + var filesrc = value.src, |
| 141 | + fileType = filesrc.split('.')[filesrc.split('.').length - 1], |
| 142 | + contentType = contentTypeHeaderMap[fileType]; |
| 143 | + |
| 144 | + if (!contentType) { |
| 145 | + contentType = 'application/octet-stream'; |
| 146 | + } |
| 147 | + return `${indentation}('${value.key}',('${filesrc.split('/')[filesrc.split('/').length - 1]}'` + |
| 148 | + `,open('${sanitize(filesrc, request.body.mode, bodyTrim)}','rb'),` + |
| 149 | + `'${contentType}'))`; |
68 | 150 | });
|
69 | 151 | requestBody = `payload={${bodyDataMap.join(',\n')}}\nfiles=[\n${bodyFileMap.join(',\n')}\n]\n`;
|
70 | 152 | }
|
|
0 commit comments