generated from halo-dev/plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from carolcoral/2-增加返回基础配置的接口
2 增加返回基础配置的接口
- Loading branch information
Showing
6 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=1.5.1 | ||
version=1.5.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/site/xindu/afdian/service/ConfigService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package site.xindu.afdian.service; | ||
|
||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.JsonSerializable; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.Disposable; | ||
import reactor.core.publisher.Mono; | ||
import reactor.core.scheduler.Scheduler; | ||
import run.halo.app.infra.utils.JsonUtils; | ||
import run.halo.app.plugin.ReactiveSettingFetcher; | ||
import site.xindu.afdian.config.BaseSettingConfig; | ||
|
||
@Service | ||
@Slf4j | ||
public class ConfigService { | ||
|
||
private final ReactiveSettingFetcher settingFetcher; | ||
|
||
public ConfigService(ReactiveSettingFetcher settingFetcher) { | ||
this.settingFetcher = settingFetcher; | ||
} | ||
|
||
private static final String BASIC = "basic"; | ||
|
||
public Mono<JsonNode> getConfig() { | ||
return this.settingFetcher.get(BASIC).map(res -> { | ||
var fields = res.fields(); | ||
while (fields.hasNext()) { | ||
var next = fields.next(); | ||
var key = next.getKey(); | ||
var value = next.getValue(); | ||
try { | ||
if ("userId".equalsIgnoreCase(key)) { | ||
next.setValue(new ObjectMapper().readTree("")); | ||
} else if ("token".equalsIgnoreCase(key)) { | ||
next.setValue(new ObjectMapper().readTree("")); | ||
} else { | ||
next.setValue(value); | ||
} | ||
} catch (JsonProcessingException e) { | ||
log.error("转换Config 数据出现异常!", e); | ||
} | ||
} | ||
return res; | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters