From 186611d5290020e2747c3c7d5544e4e09234ccf1 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Mon, 10 Jun 2019 19:41:31 +0800 Subject: [PATCH] Support mode for getEnvironment api. --- .../java/run/halo/app/model/dto/EnvironmentDTO.java | 2 ++ .../run/halo/app/service/impl/AdminServiceImpl.java | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java b/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java index 644da2bee..77063b26f 100644 --- a/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java +++ b/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java @@ -16,4 +16,6 @@ public class EnvironmentDTO { private long startTime; private String version; + + private String mode; } diff --git a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java index 9a6e2ca32..5899ee4f1 100644 --- a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java @@ -2,6 +2,7 @@ package run.halo.app.service.impl; import cn.hutool.core.lang.Validator; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.lang.NonNull; @@ -63,6 +64,8 @@ public class AdminServiceImpl implements AdminService { private final String driverClassName; + private final String mode; + public AdminServiceImpl(PostService postService, SheetService sheetService, AttachmentService attachmentService, @@ -74,7 +77,8 @@ public class AdminServiceImpl implements AdminService { LinkService linkService, StringCacheStore cacheStore, ApplicationEventPublisher eventPublisher, - @Value("${spring.datasource.driver-class-name}") String driverClassName) { + @Value("${spring.datasource.driver-class-name}") String driverClassName, + @Value("${spring.profiles.active}") String mode) { this.postService = postService; this.sheetService = sheetService; this.attachmentService = attachmentService; @@ -87,6 +91,7 @@ public class AdminServiceImpl implements AdminService { this.cacheStore = cacheStore; this.eventPublisher = eventPublisher; this.driverClassName = driverClassName; + this.mode = mode; } @Override @@ -189,6 +194,12 @@ public class AdminServiceImpl implements AdminService { environmentDTO.setVersion(HaloConst.HALO_VERSION); + if (StringUtils.isNotEmpty(mode)) { + environmentDTO.setMode(StringUtils.equals("dev", mode) ? "development" : "production"); + } else { + environmentDTO.setMode("test"); + } + return environmentDTO; }