From b1be87a145e52f4268bfc33918edd49518740cd4 Mon Sep 17 00:00:00 2001 From: PALASH2201 Date: Sat, 5 Oct 2024 17:18:01 +0530 Subject: [PATCH] Added base64 encoding for api call --- .eslintrc.json | 2 +- package-lock.json | 5 +++++ package.json | 1 + src/constants/constants.js | 3 +-- src/pages/EditorComponent.js | 12 +++++++----- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index d300749..a637a57 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,7 +13,7 @@ "react/prop-types": "off", "react/react-in-jsx-scope": "off", "indent": ["error", 2], - "linebreak-style": ["error", "unix"], + "linebreak-style": ["error", "windows"], "quotes": ["error", "double"], "no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }], "import/order": ["error", { "groups": [["builtin", "external", "internal"]] }], diff --git a/package-lock.json b/package-lock.json index 8ee0344..b55ff0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@mui/material": "^6.1.1", "@mui/styled-engine-sc": "^6.0.0-alpha.18", "@snaddyvitch-dispenser/react-router-sitemap": "^1.2.6", + "CustomCodeEditor": "file:", "monaco-themes": "^0.4.4", "notistack": "^3.0.1", "react": "^18.3.1", @@ -8082,6 +8083,10 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" }, + "node_modules/CustomCodeEditor": { + "resolved": "", + "link": true + }, "node_modules/damerau-levenshtein": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz", diff --git a/package.json b/package.json index a00ced6..cc7e09b 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "@mui/material": "^6.1.1", "@mui/styled-engine-sc": "^6.0.0-alpha.18", "@snaddyvitch-dispenser/react-router-sitemap": "^1.2.6", + "CustomCodeEditor": "file:", "monaco-themes": "^0.4.4", "notistack": "^3.0.1", "react": "^18.3.1", diff --git a/src/constants/constants.js b/src/constants/constants.js index 194c91d..e065c0c 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -3,8 +3,7 @@ import JavaLogo from "../components/images/JavaLogo"; import JavascriptLogo from "../components/images/JavaScriptLogo"; import PythonLogo from "../components/images/PythonLogo"; -export const judge0SubmitUrl = - process.env.JUDGE0_SUMBISSION_URL || process.env.REACT_APP_RAPID_API_URL; +export const judge0SubmitUrl = process.env.REACT_APP_RAPID_API_URL; export const rapidApiHost = process.env.REACT_APP_RAPID_API_HOST; export const rapidApiKey = process.env.REACT_APP_RAPID_API_KEY; diff --git a/src/pages/EditorComponent.js b/src/pages/EditorComponent.js index 6ee1138..3dc6db4 100644 --- a/src/pages/EditorComponent.js +++ b/src/pages/EditorComponent.js @@ -117,7 +117,8 @@ function EditorComponent() { } setLoading(true); try { - const response = await fetch(judge0SubmitUrl, { + const encodedCode = btoa(codeToSubmit); + const response = await fetch(`${judge0SubmitUrl}?base64_encoded=true&wait=false&fields=*`, { method: "POST", headers: { "Content-Type": "application/json", @@ -125,7 +126,7 @@ function EditorComponent() { "X-RapidAPI-Host": rapidApiHost, }, body: JSON.stringify({ - source_code: codeToSubmit, + source_code: encodedCode, language_id: languageDetails.ID, stdin: "", expected_output: "", @@ -144,7 +145,7 @@ function EditorComponent() { const submissionId = data["token"]; setTimeout(() => { - fetch(`${judge0SubmitUrl}/${submissionId}`, { + fetch(`${judge0SubmitUrl}/${submissionId}?base64_encoded=true&fields=*`, { method: "GET", headers: { "X-RapidAPI-Key": rapidApiKey, @@ -158,8 +159,9 @@ function EditorComponent() { setOutput(data.message); return; } - const formatedData = data.stdout.split("\n"); - setOutput(formatedData); + const decodedOutput = atob(data.stdout); + const formattedData = decodedOutput.split("\n"); + setOutput(formattedData); }) .catch((error) => { enqueueSnackbar("Error retrieving output: " + error.message, {