🐛 fixed

This commit is contained in:
毛毛虫 2022-01-21 15:49:53 +08:00
parent 644ba31d1c
commit 12ccb9b7d0
3 changed files with 13 additions and 14 deletions

3
.gitignore vendored
View File

@ -35,4 +35,5 @@ build/
index index
userDic userDic
/src/main/resources/application.yml
*.yml

10
pom.xml
View File

@ -296,16 +296,6 @@
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<!--打包过程中跳过测试-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!--true跳过测试-->
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>

View File

@ -251,6 +251,17 @@ public class UploadController {
TokenUser tokenUser = getTokenUser(request); TokenUser tokenUser = getTokenUser(request);
String url = linkToImageUrlDTO.getUrl(); String url = linkToImageUrlDTO.getUrl();
Map data = new HashMap(2);
if (StringUtils.isBlank(url)) {
data.put("message", "文件为空!");
return GlobalResultGenerator.genSuccessResult(data);
}
if (url.contains(Utils.getProperty("resource.file-path"))) {
data.put("originalURL", url);
data.put("url", url);
return GlobalResultGenerator.genSuccessResult(data);
}
URL link = new URL(url); URL link = new URL(url);
HttpURLConnection conn = (HttpURLConnection) link.openConnection(); HttpURLConnection conn = (HttpURLConnection) link.openConnection();
//设置超时间为3秒 //设置超时间为3秒
@ -258,7 +269,6 @@ public class UploadController {
//防止屏蔽程序抓取而返回403错误 //防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36"); conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36");
conn.setRequestProperty("referer", ""); conn.setRequestProperty("referer", "");
Map data = new HashMap(2);
//得到输入流 //得到输入流
try (InputStream inputStream = conn.getInputStream()) { try (InputStream inputStream = conn.getInputStream()) {
//获取自己数组 //获取自己数组
@ -308,8 +318,6 @@ public class UploadController {
data.put("message", "上传失败"); data.put("message", "上传失败");
return GlobalResultGenerator.genSuccessResult(data); return GlobalResultGenerator.genSuccessResult(data);
} }
} }
} }