|
@@ -27,14 +27,20 @@ public class PublicController {
|
|
|
@GetMapping("/api/version")
|
|
|
public String getVersion() {
|
|
|
|
|
|
- Integer level = 1;
|
|
|
String activeProfile = env.getActiveProfiles()[0];
|
|
|
- if ("local".equals(activeProfile)) level = 2;
|
|
|
+ if ("local".equals(activeProfile)) {
|
|
|
+ // jar 包所在目录 + 文件名
|
|
|
+ String path = FileUtil.getParent(
|
|
|
+ this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile(), 2) + "./version.txt";
|
|
|
+ return FileUtil.readUtf8String(path).trim();
|
|
|
+ } else {
|
|
|
+ // 自动部署的目录
|
|
|
+ String versionFile = "/app/build/version.txt"; // 上一级目录
|
|
|
+ return FileUtil.exist(versionFile)
|
|
|
+ ? FileUtil.readUtf8String(versionFile).trim()
|
|
|
+ : "0.0.0";
|
|
|
+ }
|
|
|
|
|
|
- // jar 包所在目录 + 文件名
|
|
|
- String path = FileUtil.getParent(
|
|
|
- this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile(), level) + "./version.txt";
|
|
|
- return FileUtil.readUtf8String(path).trim();
|
|
|
}
|
|
|
|
|
|
}
|