fix: 小说封面图修改

This commit is contained in:
xiongxiaoyang 2025-04-21 21:47:01 +08:00
parent 0e156c04b4
commit 3f009dc1f9
5 changed files with 55 additions and 28 deletions

View File

@ -69,4 +69,8 @@ public interface CacheKey {
* 测试爬虫规则缓存 * 测试爬虫规则缓存
*/ */
String BOOK_TEST_PARSE = "testParse"; String BOOK_TEST_PARSE = "testParse";
/**
* AI生成图片
* */
String AI_GEN_PIC = "aiGenPic";
} }

View File

@ -238,6 +238,14 @@ public class AuthorController extends BaseController {
} }
/**
* 查询AI生成图片
*/
@GetMapping("queryAiGenPic")
public RestResult<String> queryAiGenPic(@RequestParam("bookId") Long bookId) {
return RestResult.ok(bookService.queryAiGenPic(bookId));
}
/** /**
* AI扩写 * AI扩写
*/ */

View File

@ -290,4 +290,9 @@ public interface BookService {
* @param authorId * @param authorId
*/ */
void updateBookPic(Long bookId, String bookPic, Long authorId); void updateBookPic(Long bookId, String bookPic, Long authorId);
/**
* 查询AI生成图片
*/
String queryAiGenPic(Long bookId);
} }

View File

@ -559,6 +559,7 @@ public class BookServiceImpl implements BookService {
.where(id, isEqualTo(book.getId())) .where(id, isEqualTo(book.getId()))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
cacheService.set(CacheKey.AI_GEN_PIC + book.getId(), picUrl, 60 * 60);
}); });
} }
} }
@ -882,5 +883,10 @@ public class BookServiceImpl implements BookService {
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }
@Override
public String queryAiGenPic(Long bookId) {
return cacheService.get(CacheKey.AI_GEN_PIC + bookId);
}
} }

View File

@ -51,8 +51,7 @@
</div> </div>
<div class="my_r"> <div class="my_r">
<div id="noContentDiv"> <div id="noContentDiv">
<div class="tc" style="margin-top: 200px"><a href="/author/book_add.html" class="btn_red">创建作品</a> <div class="tc" style="margin-top: 200px"><a href="/author/book_add.html" class="btn_red">创建作品</a></div>
</div>
</div> </div>
<div class="my_bookshelf" id="hasContentDiv" style="display: none"> <div class="my_bookshelf" id="hasContentDiv" style="display: none">
@ -143,13 +142,12 @@
<script src="/javascript/common.js" type="text/javascript"></script> <script src="/javascript/common.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript"> <script language="javascript" type="text/javascript">
var searchCount = 0; var coverUpdateInterval;
var timeout;
search(1, 5); search(1, 5);
function search(curr, limit) { function search(curr, limit) {
searchCount++; clearInterval(coverUpdateInterval);
clearTimeout(timeout);
$.ajax({ $.ajax({
type: "get", type: "get",
url: "/author/listBookByPage", url: "/author/listBookByPage",
@ -159,7 +157,25 @@
if (data.code == 200) { if (data.code == 200) {
var bookList = data.data.list; var bookList = data.data.list;
if (bookList.length > 0) { if (bookList.length > 0) {
var aiPicGenerating = bookList[0].picUrl == '/images/default.gif' if(curr == 1 && bookList[0].picUrl == '/images/default.gif'){
coverUpdateInterval = setInterval(function(){
$.ajax({
type: "get",
url: "/author/queryAiGenPic",
data: {'bookId': bookList[0].id},
dataType: "json",
success: function (data) {
if(data.code == 200 && data.data){
$("#cover"+bookList[0].id).attr("src", data.data);
clearInterval(coverUpdateInterval);
}
}
});
}, 3000);
setTimeout(() => {
clearInterval(coverUpdateInterval);
}, 10000);
}
$("#hasContentDiv").css("display", "block"); $("#hasContentDiv").css("display", "block");
$("#noContentDiv").css("display", "none"); $("#noContentDiv").css("display", "none");
var bookListHtml = ""; var bookListHtml = "";
@ -171,15 +187,12 @@
" </td>\n" +*/ " </td>\n" +*/
" <td style=\"position: relative\" class=\"goread\">\n" + " <td style=\"position: relative\" class=\"goread\">\n" +
"<input class=\"opacity\" onchange=\"picChange('" + book.id + "'," + i + ")\"\n" + "<input class=\"opacity\" onchange=\"picChange('" + book.id + "')\"\n" +
" type=\"file\" id=\"file" + i + "\" name=\"file\"\n" + " type=\"file\" id=\"file" + book.id + "\" name=\"file\"\n" +
" title=\"点击上传图片\"\n" + " title=\"点击上传图片\"\n" +
" style=\"z-index: 100;cursor: pointer;left: 30px; top: 0px; width: 60px; height: 80px; opacity: 0; position: absolute; \"\n" + " style=\"z-index: 100;cursor: pointer;left: 30px; top: 0px; width: 60px; height: 80px; opacity: 0; position: absolute; \"\n" +
" />" + " />" +
"<img width='50' height='70' src='" + book.picUrl + "'/><br/>" + "<img id=\"cover" + book.id + "\" width='50' height='70' src='" + book.picUrl + "'/><br/>" + " " + book.bookName + "</td>\n" +
" " + book.bookName + "</td>\n" +
" <td class=\"goread\" >" " <td class=\"goread\" >"
+ book.catName + "</td>\n" + + book.catName + "</td>\n" +
@ -231,12 +244,6 @@
}); });
}); });
if (curr === 1 && aiPicGenerating && searchCount < 10) {
timeout = setTimeout(function () {
search(curr, limit);
}, 3000);
}
} }
@ -288,19 +295,20 @@
} }
function picChange(bookId, i) { function picChange(bookId) {
var file = $("#file" + i).val(); //文件名称 var file = $("#file" + bookId).val(); //文件名称
if (file != "") { if (file != "") {
if (checkPicUpload($("#file" + i)[0])) { if (checkPicUpload($("#file" + bookId)[0])) {
$.ajaxFileUpload({ $.ajaxFileUpload({
url: "/file/picUpload", //用于文件上传的服务器端请求地址 url: "/file/picUpload", //用于文件上传的服务器端请求地址
secureuri: false, //是否需要安全协议一般设置为false secureuri: false, //是否需要安全协议一般设置为false
fileElementId: "file" + i, //文件上传域的ID fileElementId: "file" + bookId, //文件上传域的ID
dataType: "json", //返回值类型 一般设置为json dataType: "json", //返回值类型 一般设置为json
type: "post", type: "post",
success: function (data) { //服务器成功响应处理函数 success: function (data) { //服务器成功响应处理函数
if (data.code == 200) { if (data.code == 200) {
let picUrl = data.data;
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/author/updateBookPic", url: "/author/updateBookPic",
@ -308,17 +316,13 @@
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (data.code == 200) { if (data.code == 200) {
$("#cover"+bookId).attr("src", picUrl);
location.reload();
} else { } else {
lock = false;
layer.alert(data.msg); layer.alert(data.msg);
} }
}, },
error: function () { error: function () {
lock = false;
layer.alert('网络异常'); layer.alert('网络异常');
} }
}) })