From 0efce63cd0b147793734bc802d99f444898a67bb Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Fri, 8 Nov 2024 09:51:31 +0800 Subject: [PATCH] [Refactor] Refactor get version function (#3898) Signed-off-by: Zzm0809 <934230207@qq.com> Co-authored-by: Zzm0809 --- .../org/dinky/controller/AdminController.java | 7 ++++++- .../src/main/java/org/dinky/DinkyVersion.java | 17 +++++++++++++++++ dinky-web/src/pages/Other/Login/function.tsx | 18 ++++++++++-------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/controller/AdminController.java b/dinky-admin/src/main/java/org/dinky/controller/AdminController.java index 327768c20d..b9bf093c05 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/AdminController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/AdminController.java @@ -132,8 +132,13 @@ public Result getTokenInfo() { @GetMapping("/version") @ApiOperation(value = "Query Service Version", notes = "Query Dinky Service Version Number") + @ApiImplicitParam(name = "isExternalCall", value = "isExternalCall", dataTypeClass = Boolean.class) @SaCheckLogin - public Result getVersionInfo() { + public Result getVersionInfo( + @RequestParam(required = false, defaultValue = "true") boolean isExternalCall) { + if (isExternalCall) { + return Result.succeed((Object) DinkyVersion.getShortVersion()); + } return Result.succeed((Object) DinkyVersion.getVersion()); } } diff --git a/dinky-common/src/main/java/org/dinky/DinkyVersion.java b/dinky-common/src/main/java/org/dinky/DinkyVersion.java index 0ab21351e1..9659d58a89 100644 --- a/dinky-common/src/main/java/org/dinky/DinkyVersion.java +++ b/dinky-common/src/main/java/org/dinky/DinkyVersion.java @@ -36,4 +36,21 @@ public static String getVersion() { return "${revision}"; } } + + /** + * Return the short version string of the present Dinky codebase. + * @return the short version of Dinky + */ + public static String getShortVersion() { + try { + String version = getVersion(); + int idx = version.indexOf('-'); + if (idx > 0) { + return version.substring(0, idx); + } + return version; + } catch (Exception e) { + return "${revision}"; + } + } } diff --git a/dinky-web/src/pages/Other/Login/function.tsx b/dinky-web/src/pages/Other/Login/function.tsx index 9f575e7273..2e148e920b 100644 --- a/dinky-web/src/pages/Other/Login/function.tsx +++ b/dinky-web/src/pages/Other/Login/function.tsx @@ -47,15 +47,17 @@ export const redirectToLogin = (tipMsg: string) => { export const initSomeThing = () => { // initialize setting theme setLocalThemeToStorage(); - queryDataByParams(API_CONSTANTS.GET_SERVICE_VERSION).then((result) => { - if (result && result != getValueFromLocalStorage(SERVER_VERSION)) { - console.log('current version:', getValueFromLocalStorage(SERVER_VERSION)); - console.log('update server version:', result); - setKeyToLocalStorage(SERVER_VERSION, result); - console.log('clean dva cache'); - window.localStorage.removeItem('persist:root'); + queryDataByParams(API_CONSTANTS.GET_SERVICE_VERSION, { isExternalCall: false }).then( + (result) => { + if (result && result != getValueFromLocalStorage(SERVER_VERSION)) { + console.log('current version:', getValueFromLocalStorage(SERVER_VERSION)); + console.log('update server version:', result); + setKeyToLocalStorage(SERVER_VERSION, result); + console.log('clean dva cache'); + window.localStorage.removeItem('persist:root'); + } } - }); + ); // Retrieve the key for enabling message prompts from the local storage, and if not, set it accordingly if (hasKeyofLocalStorage(ENABLE_MODEL_TIP)) {