diff --git a/README.md b/README.md index 5e5a5baa..adacdd9f 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,8 @@ [badge:plugin-homepage]: https://img.shields.io/badge/Plugin%20Home-Leetcode%20Editor-blue?logo=jetbrains&style=flat-square [badge:plugin-homepage-pro]: https://img.shields.io/badge/Pro%20Plugin%20Home-Leetcode%20Editor%20Pro-blue?logo=jetbrains&style=flat-square&color=blueviolet -[badge:release]: https://img.shields.io/github/workflow/status/shuzijun/leetcode-editor/Release?style=flat-square&logo=github&&label=Release%20Build -[badge:snapshot]: https://img.shields.io/github/workflow/status/shuzijun/leetcode-editor/Snapshot?style=flat-square&logo=github&&label=Snapshot%20Build +[badge:release]: https://img.shields.io/github/actions/workflow/status/shuzijun/leetcode-editor/release.yml?branch=master&style=flat-square&logo=github&&label=Release%20Build +[badge:snapshot]: https://img.shields.io/github/actions/workflow/status/shuzijun/leetcode-editor/snapshot.yml?branch=master&style=flat-square&logo=github&&label=Snapshot%20Build [badge:license]: https://img.shields.io/github/license/shuzijun/leetcode-editor.svg?style=flat-square&&label=License [badge:downloads]: https://img.shields.io/jetbrains/plugin/d/12132?style=flat-square&label=Plugin%20Downloads&logo=jetbrains [badge:version]: https://img.shields.io/jetbrains/plugin/v/12132?label=Plugin%20Version&logo=jetbrains&style=flat-square diff --git a/README_ZH.md b/README_ZH.md index 2519b955..c171156f 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -113,8 +113,8 @@ [badge:plugin-homepage]: https://img.shields.io/badge/Plugin%20Home-Leetcode%20Editor-blue?logo=jetbrains&style=flat-square [badge:plugin-homepage-pro]: https://img.shields.io/badge/Pro%20Plugin%20Home-Leetcode%20Editor%20Pro-blue?logo=jetbrains&style=flat-square&color=blueviolet -[badge:release]: https://img.shields.io/github/workflow/status/shuzijun/leetcode-editor/Release?style=flat-square&logo=github&label=Release%20Build -[badge:snapshot]: https://img.shields.io/github/workflow/status/shuzijun/leetcode-editor/Snapshot?style=flat-square&logo=github&label=Snapshot%20Build +[badge:release]: https://img.shields.io/github/actions/workflow/status/shuzijun/leetcode-editor/release.yml?branch=master&style=flat-square&logo=github&&label=Release%20Build +[badge:snapshot]: https://img.shields.io/github/actions/workflow/status/shuzijun/leetcode-editor/snapshot.yml?branch=master&style=flat-square&logo=github&&label=Snapshot%20Build [badge:license]: https://img.shields.io/github/license/shuzijun/leetcode-editor.svg?style=flat-square&&label=License [badge:downloads]: https://img.shields.io/jetbrains/plugin/d/12132?style=flat-square&label=Plugin%20Downloads&logo=jetbrains [badge:version]: https://img.shields.io/jetbrains/plugin/v/12132?label=Plugin%20Version&logo=jetbrains&style=flat-square diff --git a/src/main/java/com/shuzijun/leetcode/plugin/manager/SubmissionManager.java b/src/main/java/com/shuzijun/leetcode/plugin/manager/SubmissionManager.java index 1a7e6674..99dac6bb 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/manager/SubmissionManager.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/manager/SubmissionManager.java @@ -102,6 +102,7 @@ public static File openSubmission(Submission submission, String titleSlug, Proje sb.append(codeTypeEnum.getComment()).append("input_formatted:").append(submissionData.getString("input_formatted")).append("\n"); sb.append(codeTypeEnum.getComment()).append("expected_output:").append(submissionData.getString("expected_output")).append("\n"); sb.append(codeTypeEnum.getComment()).append("code_output:").append(submissionData.getString("code_output")).append("\n"); + sb.append(codeTypeEnum.getComment()).append("last_testcase:").append(submissionData.getString("last_testcase")).append("\n"); } else if ("Runtime Error".equals(submission.getStatus())) { sb.append(codeTypeEnum.getComment()).append("runtime_error:").append(submissionData.getString("runtime_error")).append("\n"); sb.append(codeTypeEnum.getComment()).append("last_testcase:").append(submissionData.getString("last_testcase").replaceAll("(\\r|\\r\\n|\\n\\r|\\n)", " ")).append("\n"); @@ -137,21 +138,30 @@ public static File openSubmission(Submission submission, String titleSlug, Proje } private static JSONObject loadSubmissionEn(Submission submission, Project project) { - HttpResponse response = HttpRequest.builderGet(URLUtils.getLeetcodeSubmissions() + submission.getId() + "/").request(); + HttpResponse response = Graphql.builder().operationName("submissionDetail","submissionDetails").variables("id", submission.getId()).request(); if (response.getStatusCode() == 200) { - String html = response.getBody(); - String body = CommentUtils.createSubmissions(html); - if (StringUtils.isBlank(body)) { - LogUtils.LOG.error(html); - MessageUtils.getInstance(project).showWarnMsg("error", PropertiesUtils.getInfo("submission.parse")); - } else { - try { - JSONObject jsonObject = JSONObject.parseObject(body); - return jsonObject; - } catch (Exception e) { - LogUtils.LOG.error(body, e); - MessageUtils.getInstance(project).showWarnMsg("error", PropertiesUtils.getInfo("submission.parse")); - } + String body = response.getBody(); + if (StringUtils.isNotBlank(body)) { + JSONObject jsonObject = new JSONObject(); + JSONObject enObject = JSONObject.parseObject(body).getJSONObject("data").getJSONObject("submissionDetails"); + + jsonObject.put("submissionCode", enObject.getString("code")); + + JSONObject submissionData = new JSONObject(); + submissionData.put("runtime", enObject.getString("runtimeDisplay")); + submissionData.put("memory", enObject.getString("memoryDisplay")); + submissionData.put("total_testcases", ""); + submissionData.put("total_correct", ""); + submissionData.put("input_formatted", ""); + submissionData.put("expected_output", ""); + submissionData.put("code_output", ""); + submissionData.put("runtime_error", enObject.getString("runtimeError")); + submissionData.put("last_testcase", enObject.getString("lastTestcase")); + submissionData.put("compile_error", enObject.getString("compileError")); + jsonObject.put("submissionData", submissionData); + + return jsonObject; + } } else { MessageUtils.getInstance(project).showWarnMsg("error", PropertiesUtils.getInfo("request.failed")); @@ -161,7 +171,7 @@ private static JSONObject loadSubmissionEn(Submission submission, Project projec private static JSONObject loadSubmissionCn(Submission submission, Project project) { HttpResponse response = Graphql.builder().cn(URLUtils.isCn()).operationName("submissionDetail").variables("id", submission.getId()).request(); - if (response != null && response.getStatusCode() == 200) { + if (response.getStatusCode() == 200) { String body = response.getBody(); if (StringUtils.isNotBlank(body)) { JSONObject jsonObject = new JSONObject(); diff --git a/src/main/resources/graphql/submissionDetail.graphql b/src/main/resources/graphql/submissionDetail.graphql new file mode 100644 index 00000000..b60620ef --- /dev/null +++ b/src/main/resources/graphql/submissionDetail.graphql @@ -0,0 +1,38 @@ +query submissionDetails($id: Int!) { + submissionDetails(submissionId: $id) { + runtime + runtimeDisplay + runtimePercentile + runtimeDistribution + memory + memoryDisplay + memoryPercentile + memoryDistribution + code + timestamp + statusCode + user { + username + profile { + realName + userAvatar + } + } + lang { + name + verboseName + } + question { + questionId + } + notes + topicTags { + tagId + slug + name + } + runtimeError + compileError + lastTestcase + } +} \ No newline at end of file