Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dist/config-import-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/config-import-bundle.js.map

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/log.bundle-sizes.rest-import-ui.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ immutable: 139.01 KB (1.24%)
react-dom: 129.98 KB (1.16%)
js-yaml: 105.01 KB (0.939%)
axios: 87.01 KB (0.778%)
i18next: 82.68 KB (0.740%)
@popperjs/core: 68.84 KB (0.616%)
buffer: 56.99 KB (0.510%)
react-transition-group: 55.52 KB (0.497%)
i18next: 82.68 KB (0.739%)
@popperjs/core: 68.84 KB (0.615%)
buffer: 56.99 KB (0.509%)
react-transition-group: 55.52 KB (0.496%)
@emotion/cache: 40.02 KB (0.358%)
react-redux: 36.88 KB (0.330%)
@mui/utils: 34.3 KB (0.307%)
react-i18next: 25.61 KB (0.229%)
x2js: 24.59 KB (0.220%)
stylis: 23.54 KB (0.211%)
stylis: 23.54 KB (0.210%)
@emotion/react: 23.27 KB (0.208%)
@emotion/styled: 19 KB (0.170%)
sha.js: 18.57 KB (0.166%)
redux: 16.37 KB (0.146%)
url-parse: 16.23 KB (0.145%)
@emotion/serialize: 13.35 KB (0.119%)
js-base64: 10.11 KB (0.0904%)
reselect: 8.85 KB (0.0792%)
js-base64: 10.11 KB (0.0903%)
reselect: 8.85 KB (0.0791%)
react: 7.98 KB (0.0714%)
redux-immutable: 5.43 KB (0.0486%)
process: 5.29 KB (0.0473%)
Expand All @@ -34,32 +34,32 @@ scheduler: 4.33 KB (0.0387%)
@emotion/is-prop-valid: 4.33 KB (0.0387%)
deep-extend: 4.19 KB (0.0375%)
base64-js: 3.84 KB (0.0343%)
@mui/styled-engine: 3.55 KB (0.0318%)
@mui/private-theming: 3.5 KB (0.0314%)
@mui/styled-engine: 3.55 KB (0.0317%)
@mui/private-theming: 3.5 KB (0.0313%)
css.escape: 3.08 KB (0.0275%)
@babel/runtime-corejs3: 3 KB (0.0269%)
serialize-error: 2.93 KB (0.0262%)
hoist-non-react-statics: 2.68 KB (0.0240%)
prop-types: 2.6 KB (0.0233%)
hoist-non-react-statics: 2.68 KB (0.0239%)
prop-types: 2.6 KB (0.0232%)
querystringify: 2.5 KB (0.0224%)
react-is: 2.4 KB (0.0215%)
ieee754: 2.1 KB (0.0188%)
html-parse-stringify: 2.09 KB (0.0187%)
@emotion/utils: 1.72 KB (0.0154%)
safe-buffer: 1.63 KB (0.0146%)
@babel/runtime: 1.63 KB (0.0146%)
@emotion/hash: 1.62 KB (0.0145%)
@emotion/hash: 1.62 KB (0.0144%)
clipboard-copy: 1.61 KB (0.0144%)
dom-helpers: 1.57 KB (0.0141%)
dom-helpers: 1.57 KB (0.0140%)
randombytes: 1.54 KB (0.0138%)
@braintree/sanitize-url: 1.38 KB (0.0123%)
use-sync-external-store: 1.28 KB (0.0115%)
@emotion/unitless: 924 B (0.00807%)
inherits: 753 B (0.00658%)
requires-port: 753 B (0.00658%)
inherits: 753 B (0.00657%)
requires-port: 753 B (0.00657%)
@emotion/use-insertion-effect-with-fallbacks: 472 B (0.00412%)
@emotion/weak-memoize: 379 B (0.00331%)
clsx: 374 B (0.00327%)
clsx: 374 B (0.00326%)
void-elements: 338 B (0.00295%)
@emotion/memoize: 202 B (0.00176%)
<self>: 1.67 MB (15.3%)
<self>: 1.68 MB (15.4%)
8 changes: 4 additions & 4 deletions dist/rest-import-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/rest-import-bundle.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wavemaker/rest-client-ui",
"version": "0.0.24",
"version": "0.0.25",
"private": false,
"main": "./dist/core/components/RestImport.js",
"release": {
Expand Down
107 changes: 106 additions & 1 deletion src/core/components/RestImport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,91 @@ export interface INotifyMessage {
type: "error" | 'info' | 'success' | 'warning'
}

const MIME_TYPES: Record<string, string> = {
"aac": "audio/aac",
"abw": "application/x-abiword",
"apng": "image/apng",
"arc": "application/x-freearc",
"avif": "image/avif",
"avi": "video/x-msvideo",
"azw": "application/vnd.amazon.ebook",
"bin": "application/octet-stream",
"bmp": "image/bmp",
"bz": "application/x-bzip",
"bz2": "application/x-bzip2",
"cda": "application/x-cdf",
"csh": "application/x-csh",
"css": "text/css",
"csv": "text/csv",
"doc": "application/msword",
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"eot": "application/vnd.ms-fontobject",
"epub": "application/epub+zip",
"gz": "application/gzip",
"gzip": "application/gzip",
"yml": "application/x-yaml",
"yaml": "application/x-yaml",
"gif": "image/gif",
"htm": "text/html",
"html": "text/html",
"ico": "image/vnd.microsoft.icon",
"ics": "text/calendar",
"jar": "application/java-archive",
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"js": "text/javascript",
"json": "application/json",
"jsonld": "application/ld+json",
"md": "text/markdown",
"mid": "audio/midi",
"midi": "audio/midi",
"mjs": "text/javascript",
"mp3": "audio/mpeg",
"mp4": "video/mp4",
"mpeg": "video/mpeg",
"mpkg": "application/vnd.apple.installer+xml",
"odp": "application/vnd.oasis.opendocument.presentation",
"ods": "application/vnd.oasis.opendocument.spreadsheet",
"odt": "application/vnd.oasis.opendocument.text",
"oga": "audio/ogg",
"ogv": "video/ogg",
"ogx": "application/ogg",
"opus": "audio/ogg",
"otf": "font/otf",
"png": "image/png",
"pdf": "application/pdf",
"php": "application/x-httpd-php",
"ppt": "application/vnd.ms-powerpoint",
"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
"rar": "application/vnd.rar",
"rtf": "application/rtf",
"sh": "application/x-sh",
"svg": "image/svg+xml",
"tar": "application/x-tar",
"tif": "image/tiff",
"tiff": "image/tiff",
"ts": "application/typescript",
"ttf": "font/ttf",
"txt": "text/plain",
"vsd": "application/vnd.visio",
"wav": "audio/wav",
"weba": "audio/webm",
"webm": "video/webm",
"webmanifest": "application/manifest+json",
"webp": "image/webp",
"woff": "font/woff",
"woff2": "font/woff2",
"xhtml": "application/xhtml+xml",
"xls": "application/vnd.ms-excel",
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"xml": "application/xml",
"xul": "application/vnd.mozilla.xul+xml",
"zip": "application/zip",
"3gp": "video/3gpp",
"3g2": "video/3gpp2",
"7z": "application/x-7z-compressed"
};

interface APII {
base_path: string,
proxy_path: string,
Expand Down Expand Up @@ -815,7 +900,8 @@ export default function RestImport({ language, restImportConfig }: { language: s
multipartParams.forEach((data, index) => {
if (data.name && data.value) {
if (data.type === 'file') {
formDataOject.append(data.name, new Blob([data.value], { type: 'application/json' }), data.filename)
//@ts-ignore
formDataOject.append(data.name, new Blob([data.value], { type: getContentTypeFromFileName(data.filename, data?.value?.type) }), data.filename)
multiParamInfoList.push({ name: data.name, type: 'file', list: true, contentType: undefined, testValue: undefined })
} else {
formDataOject.append(data.name, data.contentType === 'text' ? data.value : new Blob([data.value], { type: data.contentType }))
Expand All @@ -827,6 +913,25 @@ export default function RestImport({ language, restImportConfig }: { language: s
})
return formDataOject
}
function getContentTypeFromFileName(filename: string | null | undefined, type: string | null | undefined): string {
if(type && type.trim() && type.trim() !== "") {
return type;
}

if (!filename || !filename.trim()) {
return "application/octet-stream";
}

const ext = filename.includes(".")
? filename.split(".").pop()?.toLowerCase()
: "";

if (!ext || ext.trim() === "") {
return "application/octet-stream";
}

return MIME_TYPES[ext] || "application/octet-stream";
}
let requestConfig: ICustomAxiosConfig = {}
if (useProxy) {
requestConfig = {
Expand Down