From 074d2315af7b59ecd23acbe560b9a7b9e1221eda Mon Sep 17 00:00:00 2001 From: "1152958806@qq.com" <1152958806@qq.com> Date: Fri, 26 Apr 2024 23:14:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87=E6=BA=90?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DoubanServiceImpl.java | 72 +++-- src/main/resources/extensions/settings.yaml | 19 +- .../resources/static/contact-douban.iife.js | 2 +- src/main/resources/static/db.js | 278 ------------------ src/main/resources/static/db.min.js | 4 +- src/main/resources/templates/douban.html | 2 +- 6 files changed, 74 insertions(+), 303 deletions(-) delete mode 100644 src/main/resources/static/db.js diff --git a/src/main/java/la/moony/douban/service/impl/DoubanServiceImpl.java b/src/main/java/la/moony/douban/service/impl/DoubanServiceImpl.java index d7c283d..2460a1b 100644 --- a/src/main/java/la/moony/douban/service/impl/DoubanServiceImpl.java +++ b/src/main/java/la/moony/douban/service/impl/DoubanServiceImpl.java @@ -226,13 +226,28 @@ public Flux listAllGenres() { @Override public Mono> 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 embedHandlerDoubanlist(String type,String id){ @@ -332,14 +347,15 @@ public Mono doubanDetail(String type,String id){ listOptions.setFieldSelector(FieldSelector.of(query)); Flux list = reactiveClient.listAll(DoubanMovie.class, listOptions, null); Mono booleanMono = list.hasElements(); - return booleanMono.flatMap(hasValue ->{ - if (hasValue){ - return (Mono) list.next().flatMap(doubanMovie -> { - return getDoubanMovieVo(doubanMovie); - }); - }else { + return this.settingFetcher.get("base").flatMap(base ->booleanMono + .flatMap(hasValue ->{ + if (hasValue){ + return (Mono) 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(); @@ -383,12 +399,26 @@ public Mono 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 matcher(String url){ @@ -490,4 +520,6 @@ public Mono tmdbDetailRequest(String type,String tmdbId,String apiKey) .bodyToMono(JsonNode.class); } + + } diff --git a/src/main/resources/extensions/settings.yaml b/src/main/resources/extensions/settings.yaml index 04af885..a715a39 100644 --- a/src/main/resources/extensions/settings.yaml +++ b/src/main/resources/extensions/settings.yaml @@ -19,4 +19,21 @@ spec: - $formkit: text label: TMDB API Key name: apiKey - help: 设置TMDB API Key在https://www.themoviedb.org/settings/api 自行申请 \ No newline at end of file + 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" \ No newline at end of file diff --git a/src/main/resources/static/contact-douban.iife.js b/src/main/resources/static/contact-douban.iife.js index 1b2d158..55dbe39 100644 --- a/src/main/resources/static/contact-douban.iife.js +++ b/src/main/resources/static/contact-douban.iife.js @@ -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"); diff --git a/src/main/resources/static/db.js b/src/main/resources/static/db.js deleted file mode 100644 index 5a67a9c..0000000 --- a/src/main/resources/static/db.js +++ /dev/null @@ -1,278 +0,0 @@ -// @ts-nocheck -class HALO_DOUBAN { - constructor() { - this.ver = "1.0.0"; - this.type = "movie"; - this.status = "done"; - this.finished = false; - this.paged = 1; - this.genre_list = []; - this.genre = null; - this.subjects = []; - this._create(); - } - - on(t, e, n) { - var a = document.querySelectorAll(e); - a.forEach((item) => { - item.addEventListener(t, n); - }); - } - _fetchGenres() { - document.querySelector(".db--genres").innerHTML = ""; - const url = '/apis/api.plugin.halo.run/v1alpha1/plugins/plugin-douban/genres'; - fetch(url) - .then((response) => response.json()) - .then((data) => { - if(data.length){ - this.genre_list = data; - this._renderGenre(); - } - }); - return true; - } - - _statusChange() { - this.on("click", ".db--typeItem", (t) => { - const self = t.currentTarget; - if (self.classList.contains("is-active")) { - // const index = this.genre.indexOf(self.innerText); - return; - } - document.querySelector(".db--list").innerHTML = ""; - document.querySelector(".lds-ripple").classList.remove("u-hide"); - document - .querySelector(".db--typeItem.is-active") - .classList.remove("is-active"); - self.classList.add("is-active"); - this.status = self.dataset.status; - this.paged = 1; - this.finished = false; - this.subjects = []; - this._fetchData(); - return; - }); - } - - _handleGenreClick() { - this.on("click", ".db--genreItem", (t) => { - var genreItem = document.querySelector(".db--genreItem.is-active") - if(genreItem!=null){ - genreItem.classList.remove("is-active"); - } - const self = t.currentTarget; - document.querySelector(".db--list").innerHTML = ""; - document.querySelector(".lds-ripple").classList.remove("u-hide"); - - self.classList.add("is-active"); - if(self.innerText=='全部'){ - this.genre = null; - }else{ - this.genre = self.innerText; - } - this.paged = 1; - this.finished = false; - this.subjects = []; - this._fetchData(); - return; - }); - } - - _renderGenre() { - var index = 0; - document.querySelector(".db--genres").innerHTML = this.genre_list - .map((item) => { - index = index+1; - if(index==1){ - return `全部${item}`; - } - return `${item}`; - }) - .join(""); - this._handleGenreClick(); - } - - _fetchData() { - var url = `/apis/api.plugin.halo.run/v1alpha1/plugins/plugin-douban/doubanmovies?page=${this.paged}&size=49&type=${this.type}&status=${this.status}`; - if(this.genre!=null && this.genre!=''){ - url = url + `&genre=${this.genre}` - } - fetch(url) - .then((response) => response.json()) - .then((data) => { - if (data.items.length) { - if(this.subjects==null){ - this.subjects =[] - } - if ( - document - .querySelector(".db--list") - .classList.contains("db--list__card") - ) { - this.subjects = [...this.subjects, ...data.items]; - this._randerDateTemplate(); - } else { - this.subjects = [...this.subjects, ...data.items]; - this._randerListTemplate(); - } - document - .querySelector(".lds-ripple") - .classList.add("u-hide"); - } else { - document - .querySelector(".db--list") - .classList.contains("db--list__card") - ? this._randerDateTemplate() - : this._randerListTemplate(); - this.finished = true; - document - .querySelector(".lds-ripple") - .classList.add("u-hide"); - } - }); - } - - _randerDateTemplate() { - if (!this.subjects.length) - return (document.querySelector( - ".db--list" - ).innerHTML = `
`); - const result = this.subjects.reduce((result, item) => { - const date = new Date(item.faves.createTime); - const year = date.getFullYear(); - const month = date.getMonth() + 1; - const key = `${year}-${month.toString().padStart(2, "0")}`; - if (Object.prototype.hasOwnProperty.call(result, key)) { - result[key].push(item); - } else { - result[key] = [item]; - } - return result; - }, {}); - let html = ``; - for (let key in result) { - const date = key.split("-"); - html += `
${date[1]}
${date[0]}
`; - html += result[key] - .map((movie) => { - var img = `https://dou.img.lithub.cc/${movie.spec.type}/${movie.spec.id}.jpg` - return `
"" -
${ - movie.spec.score > 0 - ? '' + - movie.spec.score - : "" - }${ - movie.spec.year > 0 ? " · " + movie.spec.year : "" - }
- -
`; - }) - .join(""); - html += `
`; - } - document.querySelector(".db--list").innerHTML = html; - } - - _randerListTemplate() { - if (!this.subjects.length) - return (document.querySelector( - ".db--list" - ).innerHTML = `
`); - document.querySelector(".db--list").innerHTML = this.subjects - .map((item) => { - var img = `https://dou.img.lithub.cc/${item.spec.type}/${item.spec.id}.jpg` - return `
"" -
${item.faves.createTime}
-
${ - item.spec.score > 0 - ? '' + - item.spec.score - : "" - }${ - item.spec.year > 0 ? " · " + item.spec.year : "" - }
-
- `; - }) - .join(""); - } - - _handleScroll() { - window.addEventListener("scroll", () => { - var t = window.scrollY || window.pageYOffset; - // @ts-ignore - if ( - document.querySelector(".block-more").offsetTop + - // @ts-ignore - -window.innerHeight < - t && - document - .querySelector(".lds-ripple") - .classList.contains("u-hide") && - !this.finished - ) { - document - .querySelector(".lds-ripple") - .classList.remove("u-hide"); - this.paged++; - this._fetchData(); - } - }); - } - - _handleNavClick() { - this.on("click", ".db--navItem", (t) => { - if (t.target.classList.contains("current")) return; - this.genre = null; - this.type = t.target.dataset.type; - if (this.type != "book") { - this._fetchGenres(); - document - .querySelector(".db--genres") - .classList.remove("u-hide"); - } else { - document.querySelector(".db--genres").classList.add("u-hide"); - } - document.querySelector(".db--list").innerHTML = ""; - document.querySelector(".lds-ripple").classList.remove("u-hide"); - document - .querySelector(".db--navItem.current") - .classList.remove("current"); - const self = t.target; - self.classList.add("current"); - this.paged = 1; - this.finished = false; - this.subjects = null; - this._fetchData(); - }); - } - - _create() { - if (document.querySelector(".db--container")) { - if (document.querySelector(".db--navItem.current")) { - this.type = document.querySelector( - ".db--navItem.current" - ).dataset.type; - } - if (document.querySelector(".db--list").dataset.type) - this.type = document.querySelector(".db--list").dataset.type; - if (this.type == "movie") { - document - .querySelector(".db--genres") - .classList.remove("u-hide"); - } - this._fetchGenres(); - this._fetchData(); - this._handleScroll(); - this._handleNavClick(); - this._statusChange(); - } - } -} - -new HALO_DOUBAN(); diff --git a/src/main/resources/static/db.min.js b/src/main/resources/static/db.min.js index e57725c..8b09828 100644 --- a/src/main/resources/static/db.min.js +++ b/src/main/resources/static/db.min.js @@ -225,7 +225,7 @@ var HALO_DOUBAN = function () { var date = key.split("-"); html += "
".concat(date[1], "
").concat(date[0], "
"); html += result[key].map(function (movie) { - return "
".concat("", "
").concat(movie.spec.score > 0 ? '' + movie.spec.score : "").concat(movie.spec.year > 0 ? " · " + movie.spec.year : "", "
\n \n
") + return "
".concat("", "
").concat(movie.spec.score > 0 ? '' + movie.spec.score : "").concat(movie.spec.year > 0 ? " · " + movie.spec.year : "", "
\n \n
") }).join(""); html += "
" } @@ -236,7 +236,7 @@ var HALO_DOUBAN = function () { value: function _randerListTemplate() { if (!this.subjects.length) return document.querySelector(".db--list").innerHTML = "
"; document.querySelector(".db--list").innerHTML = this.subjects.map(function (item) { - return "
".concat("", "
").concat(item.faves.createTime, "
").concat(item.spec.score > 0 ? '' + item.spec.score : "").concat(item.spec.year > 0 ? " · " + item.spec.year : "", "
\n
\n ") + return "
".concat("", "
").concat(item.faves.createTime, "
").concat(item.spec.score > 0 ? '' + item.spec.score : "").concat(item.spec.year > 0 ? " · " + item.spec.year : "", "
\n
\n ") }).join("") } }, { diff --git a/src/main/resources/templates/douban.html b/src/main/resources/templates/douban.html index b698e10..b03d45b 100644 --- a/src/main/resources/templates/douban.html +++ b/src/main/resources/templates/douban.html @@ -83,7 +83,7 @@