Support mode for getEnvironment api.

pull/195/head
ruibaby 2019-06-10 19:41:31 +08:00
parent 006edf13d7
commit 186611d529
2 changed files with 14 additions and 1 deletions

View File

@ -16,4 +16,6 @@ public class EnvironmentDTO {
private long startTime;
private String version;
private String mode;
}

View File

@ -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;
}