Skip to content

Commit 03e653e

Browse files
Merge pull request #80 from wavemaker/dev-pavan/header-contenttype
Handle header contenttype based on the files upload
2 parents 58e698d + 6d528ee commit 03e653e

8 files changed

Lines changed: 136 additions & 31 deletions

dist/config-import-bundle.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/config-import-bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/log.bundle-sizes.rest-import-ui.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ immutable: 139.01 KB (1.24%)
88
react-dom: 129.98 KB (1.16%)
99
js-yaml: 105.01 KB (0.939%)
1010
axios: 87.01 KB (0.778%)
11-
i18next: 82.68 KB (0.740%)
12-
@popperjs/core: 68.84 KB (0.616%)
13-
buffer: 56.99 KB (0.510%)
14-
react-transition-group: 55.52 KB (0.497%)
11+
i18next: 82.68 KB (0.739%)
12+
@popperjs/core: 68.84 KB (0.615%)
13+
buffer: 56.99 KB (0.509%)
14+
react-transition-group: 55.52 KB (0.496%)
1515
@emotion/cache: 40.02 KB (0.358%)
1616
react-redux: 36.88 KB (0.330%)
1717
@mui/utils: 34.3 KB (0.307%)
1818
react-i18next: 25.61 KB (0.229%)
1919
x2js: 24.59 KB (0.220%)
20-
stylis: 23.54 KB (0.211%)
20+
stylis: 23.54 KB (0.210%)
2121
@emotion/react: 23.27 KB (0.208%)
2222
@emotion/styled: 19 KB (0.170%)
2323
sha.js: 18.57 KB (0.166%)
2424
redux: 16.37 KB (0.146%)
2525
url-parse: 16.23 KB (0.145%)
2626
@emotion/serialize: 13.35 KB (0.119%)
27-
js-base64: 10.11 KB (0.0904%)
28-
reselect: 8.85 KB (0.0792%)
27+
js-base64: 10.11 KB (0.0903%)
28+
reselect: 8.85 KB (0.0791%)
2929
react: 7.98 KB (0.0714%)
3030
redux-immutable: 5.43 KB (0.0486%)
3131
process: 5.29 KB (0.0473%)
@@ -34,32 +34,32 @@ scheduler: 4.33 KB (0.0387%)
3434
@emotion/is-prop-valid: 4.33 KB (0.0387%)
3535
deep-extend: 4.19 KB (0.0375%)
3636
base64-js: 3.84 KB (0.0343%)
37-
@mui/styled-engine: 3.55 KB (0.0318%)
38-
@mui/private-theming: 3.5 KB (0.0314%)
37+
@mui/styled-engine: 3.55 KB (0.0317%)
38+
@mui/private-theming: 3.5 KB (0.0313%)
3939
css.escape: 3.08 KB (0.0275%)
4040
@babel/runtime-corejs3: 3 KB (0.0269%)
4141
serialize-error: 2.93 KB (0.0262%)
42-
hoist-non-react-statics: 2.68 KB (0.0240%)
43-
prop-types: 2.6 KB (0.0233%)
42+
hoist-non-react-statics: 2.68 KB (0.0239%)
43+
prop-types: 2.6 KB (0.0232%)
4444
querystringify: 2.5 KB (0.0224%)
4545
react-is: 2.4 KB (0.0215%)
4646
ieee754: 2.1 KB (0.0188%)
4747
html-parse-stringify: 2.09 KB (0.0187%)
4848
@emotion/utils: 1.72 KB (0.0154%)
4949
safe-buffer: 1.63 KB (0.0146%)
5050
@babel/runtime: 1.63 KB (0.0146%)
51-
@emotion/hash: 1.62 KB (0.0145%)
51+
@emotion/hash: 1.62 KB (0.0144%)
5252
clipboard-copy: 1.61 KB (0.0144%)
53-
dom-helpers: 1.57 KB (0.0141%)
53+
dom-helpers: 1.57 KB (0.0140%)
5454
randombytes: 1.54 KB (0.0138%)
5555
@braintree/sanitize-url: 1.38 KB (0.0123%)
5656
use-sync-external-store: 1.28 KB (0.0115%)
5757
@emotion/unitless: 924 B (0.00807%)
58-
inherits: 753 B (0.00658%)
59-
requires-port: 753 B (0.00658%)
58+
inherits: 753 B (0.00657%)
59+
requires-port: 753 B (0.00657%)
6060
@emotion/use-insertion-effect-with-fallbacks: 472 B (0.00412%)
6161
@emotion/weak-memoize: 379 B (0.00331%)
62-
clsx: 374 B (0.00327%)
62+
clsx: 374 B (0.00326%)
6363
void-elements: 338 B (0.00295%)
6464
@emotion/memoize: 202 B (0.00176%)
65-
<self>: 1.67 MB (15.3%)
65+
<self>: 1.68 MB (15.4%)

dist/rest-import-bundle.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rest-import-bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wavemaker/rest-client-ui",
3-
"version": "0.0.24",
3+
"version": "0.0.25",
44
"private": false,
55
"main": "./dist/core/components/RestImport.js",
66
"release": {

src/core/components/RestImport.tsx

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,91 @@ export interface INotifyMessage {
9393
type: "error" | 'info' | 'success' | 'warning'
9494
}
9595

96+
const MIME_TYPES: Record<string, string> = {
97+
"aac": "audio/aac",
98+
"abw": "application/x-abiword",
99+
"apng": "image/apng",
100+
"arc": "application/x-freearc",
101+
"avif": "image/avif",
102+
"avi": "video/x-msvideo",
103+
"azw": "application/vnd.amazon.ebook",
104+
"bin": "application/octet-stream",
105+
"bmp": "image/bmp",
106+
"bz": "application/x-bzip",
107+
"bz2": "application/x-bzip2",
108+
"cda": "application/x-cdf",
109+
"csh": "application/x-csh",
110+
"css": "text/css",
111+
"csv": "text/csv",
112+
"doc": "application/msword",
113+
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
114+
"eot": "application/vnd.ms-fontobject",
115+
"epub": "application/epub+zip",
116+
"gz": "application/gzip",
117+
"gzip": "application/gzip",
118+
"yml": "application/x-yaml",
119+
"yaml": "application/x-yaml",
120+
"gif": "image/gif",
121+
"htm": "text/html",
122+
"html": "text/html",
123+
"ico": "image/vnd.microsoft.icon",
124+
"ics": "text/calendar",
125+
"jar": "application/java-archive",
126+
"jpeg": "image/jpeg",
127+
"jpg": "image/jpeg",
128+
"js": "text/javascript",
129+
"json": "application/json",
130+
"jsonld": "application/ld+json",
131+
"md": "text/markdown",
132+
"mid": "audio/midi",
133+
"midi": "audio/midi",
134+
"mjs": "text/javascript",
135+
"mp3": "audio/mpeg",
136+
"mp4": "video/mp4",
137+
"mpeg": "video/mpeg",
138+
"mpkg": "application/vnd.apple.installer+xml",
139+
"odp": "application/vnd.oasis.opendocument.presentation",
140+
"ods": "application/vnd.oasis.opendocument.spreadsheet",
141+
"odt": "application/vnd.oasis.opendocument.text",
142+
"oga": "audio/ogg",
143+
"ogv": "video/ogg",
144+
"ogx": "application/ogg",
145+
"opus": "audio/ogg",
146+
"otf": "font/otf",
147+
"png": "image/png",
148+
"pdf": "application/pdf",
149+
"php": "application/x-httpd-php",
150+
"ppt": "application/vnd.ms-powerpoint",
151+
"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
152+
"rar": "application/vnd.rar",
153+
"rtf": "application/rtf",
154+
"sh": "application/x-sh",
155+
"svg": "image/svg+xml",
156+
"tar": "application/x-tar",
157+
"tif": "image/tiff",
158+
"tiff": "image/tiff",
159+
"ts": "application/typescript",
160+
"ttf": "font/ttf",
161+
"txt": "text/plain",
162+
"vsd": "application/vnd.visio",
163+
"wav": "audio/wav",
164+
"weba": "audio/webm",
165+
"webm": "video/webm",
166+
"webmanifest": "application/manifest+json",
167+
"webp": "image/webp",
168+
"woff": "font/woff",
169+
"woff2": "font/woff2",
170+
"xhtml": "application/xhtml+xml",
171+
"xls": "application/vnd.ms-excel",
172+
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
173+
"xml": "application/xml",
174+
"xul": "application/vnd.mozilla.xul+xml",
175+
"zip": "application/zip",
176+
"3gp": "video/3gpp",
177+
"3g2": "video/3gpp2",
178+
"7z": "application/x-7z-compressed"
179+
};
180+
96181
interface APII {
97182
base_path: string,
98183
proxy_path: string,
@@ -815,7 +900,8 @@ export default function RestImport({ language, restImportConfig }: { language: s
815900
multipartParams.forEach((data, index) => {
816901
if (data.name && data.value) {
817902
if (data.type === 'file') {
818-
formDataOject.append(data.name, new Blob([data.value], { type: 'application/json' }), data.filename)
903+
//@ts-ignore
904+
formDataOject.append(data.name, new Blob([data.value], { type: getContentTypeFromFileName(data.filename, data?.value?.type) }), data.filename)
819905
multiParamInfoList.push({ name: data.name, type: 'file', list: true, contentType: undefined, testValue: undefined })
820906
} else {
821907
formDataOject.append(data.name, data.contentType === 'text' ? data.value : new Blob([data.value], { type: data.contentType }))
@@ -827,6 +913,25 @@ export default function RestImport({ language, restImportConfig }: { language: s
827913
})
828914
return formDataOject
829915
}
916+
function getContentTypeFromFileName(filename: string | null | undefined, type: string | null | undefined): string {
917+
if(type && type.trim() && type.trim() !== "") {
918+
return type;
919+
}
920+
921+
if (!filename || !filename.trim()) {
922+
return "application/octet-stream";
923+
}
924+
925+
const ext = filename.includes(".")
926+
? filename.split(".").pop()?.toLowerCase()
927+
: "";
928+
929+
if (!ext || ext.trim() === "") {
930+
return "application/octet-stream";
931+
}
932+
933+
return MIME_TYPES[ext] || "application/octet-stream";
934+
}
830935
let requestConfig: ICustomAxiosConfig = {}
831936
if (useProxy) {
832937
requestConfig = {

0 commit comments

Comments
 (0)