Skip to content

Commit

Permalink
fix: fix the error caused by SettingFetcher. (#7)
Browse files Browse the repository at this point in the history
使用 ReactiveSettingFetcher 替代 SettingFetcher

Fixes #6 

```release-note
解决由于使用阻塞方法 SettingFetcher 而导致图库报错的问题
```
  • Loading branch information
LIlGG authored Jun 30, 2023
1 parent 02ffa17 commit a1aedb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/main/java/run/halo/photos/PhotoRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import run.halo.app.plugin.SettingFetcher;
import run.halo.app.plugin.ReactiveSettingFetcher;
import run.halo.photos.finders.PhotoFinder;
import run.halo.photos.vo.PhotoGroupVo;

Expand All @@ -27,7 +27,7 @@ public class PhotoRouter {

private PhotoFinder photoFinder;

private final SettingFetcher settingFetcher;
private final ReactiveSettingFetcher settingFetcher;

/**
* Provides a <code>/photos</code> route for the topic end to handle routing.
Expand All @@ -42,12 +42,17 @@ RouterFunction<ServerResponse> photoRouter() {
private HandlerFunction<ServerResponse> handlerFunction() {
return request -> ServerResponse.ok().render("photos",
Map.of("groups", photoGroups(), ModelConst.TEMPLATE_ID, "photos",
"title", Mono.fromCallable(() -> this.settingFetcher.get(
"base").get("title").asText("图库"))
"title", getPhotosTitle()
)
);
}

Mono<String> getPhotosTitle() {
return this.settingFetcher.get("base").map(
setting -> setting.get("title").asText("图库")).defaultIfEmpty(
"图库");
}

private Mono<List<PhotoGroupVo>> photoGroups() {
return photoFinder.groupBy().collectList();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/console/main.js

Large diffs are not rendered by default.

0 comments on commit a1aedb8

Please sign in to comment.