修改数据库路径;将并发控制由synchronize换成callable
This commit is contained in:
parent
fd016c7809
commit
7057b28ff0
@ -9,6 +9,8 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/GalleryManage")
|
||||
@Slf4j
|
||||
@ -77,8 +79,8 @@ public class GalleryManageController {
|
||||
}
|
||||
|
||||
@GetMapping("/onlineImage/{page}")
|
||||
public void getCacheImage(String gid, @PathVariable("page") int page, HttpServletRequest request, HttpServletResponse response){
|
||||
galleryManageService.getCachedImage(gid, page, request, response);
|
||||
public Callable<?> getCacheImage(String gid, @PathVariable("page") int page, HttpServletRequest request, HttpServletResponse response){
|
||||
return galleryManageService.getCachedImage(gid, page, request, response);
|
||||
}
|
||||
|
||||
@PostMapping("/reset")
|
||||
|
||||
@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.lion.lionwebsite.Util.CustomUtil.objectMapper;
|
||||
import static com.lion.lionwebsite.Util.GalleryUtil.*;
|
||||
@ -346,7 +347,7 @@ public class GalleryManageService {
|
||||
}
|
||||
|
||||
String[] suffixes = {".webp", ".gif"};
|
||||
public void getCachedImage(String gid, Integer page, HttpServletRequest request, HttpServletResponse response) {
|
||||
public Callable<?> getCachedImage(String gid, Integer page, HttpServletRequest request, HttpServletResponse response) {
|
||||
//检查文件夹是否存在
|
||||
File folder = new File(cachePath + gid);
|
||||
if(!folder.isDirectory())
|
||||
@ -356,7 +357,7 @@ public class GalleryManageService {
|
||||
for (String suffix : suffixes) {
|
||||
if(new File(cachePath + gid + "/" + page + suffix).exists()){
|
||||
FileDownload.export(request, response, cachePath + gid + "/" + page + suffix);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,15 +367,15 @@ public class GalleryManageService {
|
||||
try {
|
||||
log.error("未缓存gid:" + gid);
|
||||
response.sendError(404);
|
||||
return;
|
||||
return null;
|
||||
}catch (IOException ignored){
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized (this){
|
||||
return () -> {
|
||||
if(response.isCommitted()) {
|
||||
log.info("连接已关闭: gid=" + gid + " page=" + page);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
String imageUrl = null;
|
||||
@ -382,7 +383,7 @@ public class GalleryManageService {
|
||||
ImageKeyCache imageKeyCache = imageCacheMapper.selectImageKeyCacheByGidAndPage(gid, page);
|
||||
if (imageKeyCache == null) {
|
||||
CustomUtil.fourZeroFour(response);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
//获取图片地址
|
||||
@ -396,7 +397,7 @@ public class GalleryManageService {
|
||||
if (imageUrl == null) {
|
||||
CustomUtil.fourZeroFour(response);
|
||||
log.error("获取图片url失败:gid=" + gid + " page=" + page + " imageKey=" + imageKeyCache.getImgkey());
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
//下载图片,转格式并返回
|
||||
@ -408,12 +409,13 @@ public class GalleryManageService {
|
||||
log.error("下载图片失败:url" + imageUrl);
|
||||
e.printStackTrace();
|
||||
CustomUtil.fourZeroFour(response);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (!suffix.equals(".gif"))
|
||||
imagePath = GalleryUtil.convertImg(imagePath, suffix);
|
||||
FileDownload.export(request, response, imagePath);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
public String resetUndone(){
|
||||
|
||||
@ -8,10 +8,10 @@ server:
|
||||
spring:
|
||||
datasource-main:
|
||||
driver-class-name: org.sqlite.JDBC
|
||||
jdbc-url: jdbc:sqlite:/root/LionWebsite/LionWebsite.db
|
||||
jdbc-url: jdbc:sqlite:LionWebsite.db
|
||||
datasource-cache:
|
||||
driver-class-name: org.sqlite.JDBC
|
||||
jdbc-url: jdbc:sqlite:/root/LionWebsite/cache.db
|
||||
jdbc-url: jdbc:sqlite:cache.db
|
||||
mvc:
|
||||
view:
|
||||
prefix: /resources/templates/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user