Skip to content

Commit

Permalink
Merge pull request #3 from carolcoral/2-增加返回基础配置的接口
Browse files Browse the repository at this point in the history
2 增加返回基础配置的接口
  • Loading branch information
carolcoral authored Jun 6, 2024
2 parents f514912 + 62255c5 commit 84bf08b
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 启动插件
Expand All @@ -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) |
|:------------------------|:----------------------------|


## 开发环境

插件开发的详细文档请查阅:<https://docs.halo.run/developer-guide/plugin/introduction>
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.5.1
version=1.5.2
12 changes: 11 additions & 1 deletion src/main/java/site/xindu/afdian/controller/AfdianController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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;
import org.springframework.web.bind.annotation.RequestMapping;
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")
Expand All @@ -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;
}


Expand All @@ -34,4 +39,9 @@ public Mono<JsonNode> listSponsor(@PathVariable("pageNumber") int pageNumber){
return sponsorService.getSponsorList(pageNumber);
}

@GetMapping("/config")
public Mono<JsonNode> getConfig(){
return configService.getConfig();
}

}
56 changes: 56 additions & 0 deletions src/main/java/site/xindu/afdian/service/ConfigService.java
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;
});
}

}
8 changes: 6 additions & 2 deletions src/main/resources/templates/afdian2.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<div class="flink-list-item"
th:each="sponsor : ${afdianFinder.listAllSponsor().data.list}">
<a class="cf-friends-link" rel="external nofollow" target="_blank"
th:attr="href='https://afdian.net/u/'+'${sponsor.user.user_id}'">
th:attr="onclick=|sponsorSelf('https://afdian.net/u/'+'${sponsor.user.user_id}')|">
<img class="flink-avatar cf-friends-avatar entered loaded"
th:alt="${sponsor.user.name}"
data-ll-status="loaded"
Expand Down Expand Up @@ -99,5 +99,9 @@
color: #5d0ac7;
}
</style>

<script th:inline="javascript">
function sponsorSelf(url){
window.open(url, '_blank');
}
</script>
</html>
7 changes: 6 additions & 1 deletion src/main/resources/templates/afdian3.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<div class="flink-list">
<div class="flink-list-item" th:each="sponsor : ${afdianFinder.listAllSponsor().data.list}">
<a class="cf-friends-link" rel="external nofollow" target="_blank"
th:attr="href='https://afdian.net/u/'+'${sponsor.user.user_id}'">
th:attr="onclick=|sponsorSelf('https://afdian.net/u/'+'${sponsor.user.user_id}')|">
<img class="flink-avatar cf-friends-avatar entered loaded" alt="Shadowsocks"
th:src="${sponsor.user.avatar}"
data-ll-status="loaded">
Expand Down Expand Up @@ -119,4 +119,9 @@
}
</style>
</th:block>
<script th:inline="javascript">
function sponsorSelf(url){
window.open(url, '_blank');
}
</script>
</html>

0 comments on commit 84bf08b

Please sign in to comment.