diff --git a/README.md b/README.md index 871ab42..4ef2eae 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,10 @@ * 插件自带多款赞赏展示页面 * 如果你也喜欢该插件,可以通过 [爱发电](https://afdian.net/a/carolcoral) 或下面赞赏码对我进行支持~~ +![665ff6de2659a.webp](https://redirect.cnkj.site:8099/b/2024/665ff6de2659a.webp?type=blog) + ![theme1](https://redirect.cnkj.site:8099/shudaosan/2024/66568d582726b.webp?type=blog) -![theme3](./theme3.png) +![theme3](https://redirect.cnkj.site:8099/shudaosan/2024/665f0b959c340.webp?type=blog) ## 使用方式 1. 启动插件 @@ -31,7 +33,6 @@ | ![weixin](https://redirect.cnkj.site:8099/b/2024/665de1eeaf4a4.webp?type=blog) | ![zhifubao](https://redirect.cnkj.site:8099/b/2024/665de1cda2c05.webp?type=blog) | |:------------------------|:----------------------------| - ## 开发环境 插件开发的详细文档请查阅: diff --git a/gradle.properties b/gradle.properties index c5cc09c..99453ff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.5.1 +version=1.5.2 diff --git a/src/main/java/site/xindu/afdian/controller/AfdianController.java b/src/main/java/site/xindu/afdian/controller/AfdianController.java index 3c0f4e3..b5c40cb 100644 --- a/src/main/java/site/xindu/afdian/controller/AfdianController.java +++ b/src/main/java/site/xindu/afdian/controller/AfdianController.java @@ -1,6 +1,7 @@ package site.xindu.afdian.controller; import com.fasterxml.jackson.databind.JsonNode; +import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Mono; import run.halo.app.plugin.ApiVersion; +import site.xindu.afdian.service.ConfigService; import site.xindu.afdian.service.SponsorService; @ApiVersion("v1alpha1") @@ -19,8 +21,11 @@ public class AfdianController { private final SponsorService sponsorService; - public AfdianController(SponsorService sponsorService) { + private final ConfigService configService; + + public AfdianController(SponsorService sponsorService, ConfigService configService) { this.sponsorService = sponsorService; + this.configService = configService; } @@ -34,4 +39,9 @@ public Mono listSponsor(@PathVariable("pageNumber") int pageNumber){ return sponsorService.getSponsorList(pageNumber); } + @GetMapping("/config") + public Mono getConfig(){ + return configService.getConfig(); + } + } diff --git a/src/main/java/site/xindu/afdian/service/ConfigService.java b/src/main/java/site/xindu/afdian/service/ConfigService.java new file mode 100644 index 0000000..7b864a9 --- /dev/null +++ b/src/main/java/site/xindu/afdian/service/ConfigService.java @@ -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 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; + }); + } + +} diff --git a/src/main/resources/templates/afdian2.html b/src/main/resources/templates/afdian2.html index ef6d585..3206a07 100644 --- a/src/main/resources/templates/afdian2.html +++ b/src/main/resources/templates/afdian2.html @@ -34,7 +34,7 @@