fix:异常优化及下载上传异步处理

This commit is contained in:
yanqs 2024-08-20 14:40:54 +08:00
parent 2cbce1a574
commit 0a51d7e5e8
5 changed files with 18 additions and 11 deletions

View File

@ -8,8 +8,7 @@ EXPOSE 24803
WORKDIR /app
# 创建 bin 目录
RUN mkdir -p bin \
&& mkdir -p config \
RUN mkdir -p config \
&& mkdir -p lib \
&& mkdir -p log

View File

@ -6,7 +6,7 @@
<groupId>com.bcrjl.rss</groupId>
<artifactId>rss-reader</artifactId>
<version>0.4.0</version>
<version>0.4.2</version>
<name>RSS订阅阅读器</name>
<properties>

View File

@ -40,7 +40,7 @@ public class FileMonitor {
"## 配置订阅频率\n" +
"refresh = 5\n" +
"## 保存微博图片\n" +
"saveWeiBoImages=false" +
"saveWeiBoImages=false\n" +
"## 保存微博视频\n" +
"saveWeiBoVideo=true\n" +
"## 上传图片到AList\n" +

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
@ -90,7 +91,12 @@ public class RssJob {
if (CollUtil.isNotEmpty(list)) {
Setting setting = new Setting(CONFIG_PATH, CharsetUtil.CHARSET_UTF_8, true);
Setting emailSetting = setting.getSetting(SET_MAIL);
saveWeiBoImagesOrUpdateAList(list);
ThreadUtil.execAsync(new Runnable() {
@Override
public void run() {
saveWeiBoImagesOrUpdateAList(list);
}
});
if (emailSetting.getBool(MAIL_CONFIG_ENABLE) && emailSetting.getBool("sendUpdate")) {
// 如果邮箱开启且发送更新邮件开启 则推送通知
StringBuffer stringBuffer = new StringBuffer();
@ -141,8 +147,8 @@ public class RssJob {
if(CollUtil.isNotEmpty(videoList)){
videoList.forEach(videoObj -> {
String fileName = HtmlUtils.getFileName(videoObj);
HttpResponse weiBoImagesHttpRequest = HtmlUtils.getWeiBoVideoHttpRequest(videoObj);
byte[] bytes = weiBoImagesHttpRequest.bodyBytes();
HttpResponse weiBoVideoHttpRequest = HtmlUtils.getWeiBoVideoHttpRequest(videoObj);
byte[] bytes = weiBoVideoHttpRequest.bodyBytes();
FileUtil.writeBytes(bytes, new File(VIDEO_PATH + fileName));
if (uploadAList) {
AListUtils.uploadFile(bytes, fileName);

View File

@ -46,7 +46,10 @@ class HtmlUtilsTest {
*/
@Test
void getWeiBoImagesHttpRequest() {
String url="https://f.video.weibocdn.com/o0/Eglhl42Glx08hlnyHMZa01041200fr9J0E010.mp4?label=mp4_720p&template=720x1280.24.0&ori=0&ps=1CwnkDw1GXwCQx&Expires=1724122135&ssig=KmPchkXSzw&KID=unistore,video";
HttpResponse weiBoVideoHttpRequest = HtmlUtils.getWeiBoVideoHttpRequest(url);
byte[] bytes = weiBoVideoHttpRequest.bodyBytes();
FileUtil.writeBytes(bytes, new File(IMAGES_PATH + "Eglhl42Glx08hlnyHMZa01041200fr9J0E010.mp4"));
}
/**
@ -54,14 +57,13 @@ class HtmlUtilsTest {
*/
@Test
void getWeiBoVideosHttpRequest() {
String url = "https://f.video.weibocdn.com/o0/KjwJ3CYwlx08hlyj0a8001041200ah0h0E010.mp4" +
"?label=mp4_720p&amp;template=720x960.24.0&amp;ori=0&amp;ps=1CwnkDw1GXwCQx&amp;Expires=1724122135&amp;ssig=Gd1gjIz05D&amp;KID=unistore,video";
String url="https://f.video.weibocdn.com/o0/Eglhl42Glx08hlnyHMZa01041200fr9J0E010.mp4?label=mp4_720p&template=720x1280.24.0&ori=0&ps=1CwnkDw1GXwCQx&Expires=1724122135&ssig=KmPchkXSzw&KID=unistore,video";
HttpRequest request = HttpRequest.get(url)
.header(Header.REFERER, "https://weibo.com/")
.header(Header.USER_AGENT, USER_AGENT)
.timeout(20000);
HttpResponse httpResponse = request.executeAsync();
byte[] bytes = httpResponse.bodyBytes();
FileUtil.writeBytes(bytes, new File(IMAGES_PATH + "KjwJ3CYwlx08hlyj0a8001041200ah0h0E010.mp4"));
FileUtil.writeBytes(bytes, new File(IMAGES_PATH + "Eglhl42Glx08hlnyHMZa01041200fr9J0E010.mp4"));
}
}