漫画图片防封功能增强

This commit is contained in:
xiongxiaoyang 2019-11-28 15:43:22 +08:00
parent 53d169360f
commit 7bf7db85e9
4 changed files with 136 additions and 97 deletions

View File

@ -20,7 +20,8 @@
<div class="form-group">
<label class="col-sm-3 control-label">封面:</label>
<div class="col-sm-8">
<img title="点击选择图片" id="picImage" style="cursor:pointer;width: 100px;height: 100px" src="/img/webuploader.png"/>
<img title="点击选择图片" id="picImage" style="cursor:pointer;width: 100px;height: 100px"
src="/img/webuploader.png"/>
<input id="picUrl" name="picUrl" class="form-control"
type="hidden">

View File

@ -10,7 +10,7 @@
</parent>
<groupId>xyz.zinglizingli</groupId>
<artifactId>novel-front</artifactId>
<version>2.0.1</version>
<version>2.0.2.beta</version>
<name>novel-front</name>
<description>小说精品楼-前台web网站</description>

View File

@ -3,6 +3,7 @@ package xyz.zinglizingli.common.filter;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@ -15,7 +16,7 @@ import xyz.zinglizingli.common.utils.SpringUtil;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.*;
import java.net.URLDecoder;
import java.util.*;
import java.util.regex.Matcher;
@ -152,7 +153,6 @@ public class SearchFilter implements Filter {
}
String queryString = req.getQueryString();
if (queryString != null && queryString.length() > 0 && !queryString.contains("bsh_bid=")) {
queryString = "?" + URLDecoder.decode(req.getQueryString());
@ -162,9 +162,44 @@ public class SearchFilter implements Filter {
if (forObject == null) {
String postFix = requestURI.substring(requestURI.lastIndexOf(".") + 1);
if (picPostFix.contains(postFix)) {
// 对服务端请求返回的输入流byte[]采用何种编码转换成字符串String
restTemplate = RestTemplateUtil.getInstance("iso-8859-1");//请求图片
resp.setContentType("image/apng");
}
if (requestURI.startsWith("/manhua/images/")) {
HttpHeaders headers = new HttpHeaders();
headers.add("Referer","https://www.dmzj.com");
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
String realUrl = "https://images.dmzj.com/" + requestURI.substring(15);
ResponseEntity<Resource> resEntity = restTemplate.exchange(realUrl, HttpMethod.GET, requestEntity, Resource.class);
InputStream input = resEntity.getBody().getInputStream();
OutputStream out = resp.getOutputStream();
byte[] b = new byte[4096];
for (int n; (n = input.read(b)) != -1;) {
out.write(b, 0, n);
}
input.close();
out.close();
return;
ResponseEntity<String> forEntity = restTemplate.getForEntity("https://www.dmzj.com/"+requestURI.substring(8), String.class);
// 对服务端请求返回的输入流byte[]采用何种编码转换成字符串String
} else if(requestURI.startsWith("/manhua/statics/")){
String realPath = "https://static.dmzj.com/"+requestURI.substring(16);
ResponseEntity<String> forEntity = restTemplate.getForEntity(realPath, String.class);
forObject = forEntity.getBody();
forObject = forObject.replaceAll("https://images.dmzj.com/", "/manhua/images/");
}else {
String realPath = "https://www.dmzj.com/" + requestURI.substring(8);
ResponseEntity<String> forEntity = restTemplate.getForEntity(realPath, String.class);
forObject = forEntity.getBody();
// forObject = new String(forObject.getBytes("ISO-8859-1"),"utf-8");
@ -180,6 +215,8 @@ public class SearchFilter implements Filter {
forObject = forObject.replaceAll("<script type=\"text/javascript\">var cnzz_protocol =[^<]+</script>", "");
forObject = forObject.replaceAll("globalNav.js", "");
forObject = forObject.replaceAll("TSB.js", "");
forObject = forObject.replaceAll("https://images.dmzj.com/", "/manhua/images/");
forObject = forObject.replaceAll("https://static.dmzj.com/", "/manhua/statics/");
forObject = forObject + "<script>var browser={\n" +
" versions:function(){\n" +
" var u = window.navigator.userAgent;\n" +
@ -276,6 +313,7 @@ public class SearchFilter implements Filter {
//
// }
}
}
} else {
@ -317,7 +355,6 @@ public class SearchFilter implements Filter {
}
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
if (e instanceof HttpClientErrorException && (((HttpClientErrorException) e).getStatusCode() == HttpStatus.NOT_FOUND)) {
@ -333,6 +370,7 @@ public class SearchFilter implements Filter {
//resp.setCharacterEncoding("utf-8");
}
resp.getWriter().print(forObject);
return;
}

View File

@ -3,12 +3,12 @@ server:
spring:
datasource:
# url: jdbc:mysql://148.70.59.92:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
# username: xiongxiaoyang
# password: Lzslov123!
url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: books
password: books
# url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
# username: root
# password: test123456
cache:
ehcache:
config: classpath:ehcache.xml