Skip to content

Commit

Permalink
修复图片源显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chengzhongxue committed Apr 26, 2024
1 parent 1cbcba8 commit 074d231
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 303 deletions.
72 changes: 52 additions & 20 deletions src/main/java/la/moony/douban/service/impl/DoubanServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,28 @@ public Flux<String> listAllGenres() {

@Override
public Mono<ListResult<DoubanMovie>> listDoubanMovie(DoubanMovieQuery query) {
return reactiveClient.listBy(DoubanMovie.class, query.toListOptions(), query.toPageRequest())
.flatMap(listResult -> Flux.fromStream(listResult.get())
.collectList()
.map(list -> new ListResult<>(listResult.getPage(), listResult.getSize(),
listResult.getTotal(), list)
)
);
return this.settingFetcher.get("base").flatMap(base ->
reactiveClient.listBy(DoubanMovie.class, query.toListOptions(), query.toPageRequest())
.flatMap(listResult -> Flux.fromStream(listResult.get())
.map(doubanMovie -> {
//替换反代图片地址
String poster = doubanMovie.getSpec().getPoster();
boolean isProxy = base.get("isProxy").asBoolean(false);

if (doubanMovie.getSpec().getDataType() != "halo" && isProxy) {
if (StringUtils.isNotEmpty(base.get("proxyHost").asText())) {
String proxyHost = base.get("proxyHost").asText();
String replace =
poster.replaceAll("https://img\\d+.doubanio.com", proxyHost);
doubanMovie.getSpec().setPoster(replace);
}
}
return doubanMovie;
})
.collectList()
.map(list -> new ListResult<>(listResult.getPage(), listResult.getSize(),
listResult.getTotal(), list)
)));
}

public Mono<DoubanMovieVo> embedHandlerDoubanlist(String type,String id){
Expand Down Expand Up @@ -332,14 +347,15 @@ public Mono<DoubanMovieVo> doubanDetail(String type,String id){
listOptions.setFieldSelector(FieldSelector.of(query));
Flux<DoubanMovie> list = reactiveClient.listAll(DoubanMovie.class, listOptions, null);
Mono<Boolean> booleanMono = list.hasElements();
return booleanMono.flatMap(hasValue ->{
if (hasValue){
return (Mono<DoubanMovieVo>) list.next().flatMap(doubanMovie -> {
return getDoubanMovieVo(doubanMovie);
});
}else {
return this.settingFetcher.get("base").flatMap(base ->booleanMono
.flatMap(hasValue ->{
if (hasValue){
return (Mono<DoubanMovieVo>) list.next().flatMap(doubanMovie -> {
return getDoubanMovieVo(doubanMovie);
});
}else {
DoubanMovie doubanMovieDetail = new DoubanMovie();
return doubanDetailRequest(type, id).flatMap(jsonNode->{
return doubanDetailRequest(type, id).flatMap(jsonNode->{
String name = jsonNode.get("title").asText();
String poster = jsonNode.get("pic").get("large").asText();
String doubanId = jsonNode.get("id").asText();
Expand Down Expand Up @@ -383,12 +399,26 @@ public Mono<DoubanMovieVo> doubanDetail(String type,String id){
doubanMovieDetail.getFaves().setStatus(null);
reactiveClient.create(doubanMovieDetail).subscribe();
return getDoubanMovieVo(doubanMovieDetail);
}).onErrorResume(WebClientResponseException.NotFound.class, error -> {
log.error("Resource not found: ",error.getMessage());
return getDoubanMovieVo(doubanMovieDetail);
});
}
});
}).onErrorResume(WebClientResponseException.NotFound.class, error -> {
log.error("Resource not found: ",error.getMessage());
return getDoubanMovieVo(doubanMovieDetail);
});
}
}).map(doubanMovie -> {
//替换反代图片地址
String poster = doubanMovie.getSpec().getPoster();
boolean isProxy = base.get("isProxy").asBoolean(false);

if (doubanMovie.getSpec().getDataType() != "halo" && isProxy) {
if (StringUtils.isNotEmpty(base.get("proxyHost").asText())) {
String proxyHost = base.get("proxyHost").asText();
String replace =
poster.replaceAll("https://img\\d+.doubanio.com", proxyHost);
doubanMovie.getSpec().setPoster(replace);
}
}
return doubanMovie;
}));
}

public Map<String,Object> matcher(String url){
Expand Down Expand Up @@ -490,4 +520,6 @@ public Mono<JsonNode> tmdbDetailRequest(String type,String tmdbId,String apiKey)
.bodyToMono(JsonNode.class);
}



}
19 changes: 18 additions & 1 deletion src/main/resources/extensions/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,21 @@ spec:
- $formkit: text
label: TMDB API Key
name: apiKey
help: 设置TMDB API Key在https://www.themoviedb.org/settings/api 自行申请
help: 设置TMDB API Key在https://www.themoviedb.org/settings/api 自行申请
- $formkit: radio
label: 启用代理
name: isProxy
id: isProxy
value: false
help: 如果用豆瓣源的图片很慢可以自己搭建给图片反代站点
options:
- value: true
label: 开启
- value: false
label: 关闭
- $formkit: text
if: "$get(isProxy).value === true"
label: 代理地址
name: proxyHost
value: ""
help: "搭建教程:https://docs.kunkunyu.com/docs/plugin-douban/use#%E9%85%8D%E7%BD%AE%E5%9B%BE%E7%89%87%E4%BB%A3%E7%90%86"
2 changes: 1 addition & 1 deletion src/main/resources/static/contact-douban.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

function renderer(data, e) {
let img = data.spec.dataType == 'db' ? `https://dou.img.lithub.cc/${data.spec.type}/${data.spec.id}.jpg` : data.spec.poster
let img = data.spec.dataType == 'db' ? `${data.spec.poster}` : data.spec.poster
let date = new Date(data.faves.createTime);
let dateString = date.toLocaleString(); // 使用默认的日期和时间格式
const r = document.createElement("div");
Expand Down
Loading

0 comments on commit 074d231

Please sign in to comment.