Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
8970af67da |
32
README.md
32
README.md
|
|
@ -6,8 +6,7 @@ RSS阅读器,基于Java SpringBoot搭建。
|
|||
|
||||
1. RSS订阅功能;
|
||||
2. 邮件推送;
|
||||
3. 微博图片保存;
|
||||
4. 微博图片上传AList;
|
||||
3. 微博图片、视频保存;
|
||||
|
||||
## 部署运行
|
||||
|
||||
|
|
@ -28,21 +27,28 @@ bcrjl/rss-reader:latest
|
|||
|
||||
### 映射目录说明
|
||||
|
||||
| 本地目录 | 容器目录 | 说明 |
|
||||
|----------| --- |-------|
|
||||
| ./config | /app/config | 配置文件 |
|
||||
| ./log | /app/log | 运行日志 |
|
||||
| ./images | /app/images | 下载的图片 |
|
||||
| ./video | /app/video | 下载的视频 |
|
||||
| 本地目录 | 容器目录 | 说明 |
|
||||
|----------|-------------|-----------------|
|
||||
| ./config | /app/config | 配置文件 |
|
||||
| ./log | /app/log | 运行日志 |
|
||||
| ./images | /app/images | 下载的图片 |
|
||||
| ./video | /app/video | 下载的视频 |
|
||||
|
||||
## FAQ
|
||||
|
||||
### 1.AList上传异常
|
||||
|
||||
配置错误,请检查`config.setting`配置文件中的`aListUrl`配置,结尾不能带`/`
|
||||
待更新
|
||||
|
||||
## TODO
|
||||
|
||||
1. 订阅请求增加代理配置
|
||||
2推送渠道:企业微信、钉钉等
|
||||
3...
|
||||
2. 推送渠道:企业微信、钉钉等
|
||||
3. ..
|
||||
|
||||
## 更新说明
|
||||
|
||||
### v0.4.0
|
||||
|
||||
1. RSS订阅功能;
|
||||
2. 邮件推送;
|
||||
3. 微博图片保存;
|
||||
4. 微博图片上传AList;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,10 @@
|
|||
[system]
|
||||
## 配置订阅频率
|
||||
refresh=5
|
||||
refresh=1
|
||||
## 保存微博图片
|
||||
saveWeiBoImages=true
|
||||
## 保存微博视频
|
||||
saveWeiBoVideo=true
|
||||
## 上传图片到AList
|
||||
uploadAList=false
|
||||
## AList Url
|
||||
aListUrl=
|
||||
## AList 账号
|
||||
aListUser=
|
||||
## AList 密码
|
||||
aListPass=
|
||||
## AList 上传路径
|
||||
aListUploadPath=
|
||||
[mail]
|
||||
## 启用邮件推送
|
||||
enable=false
|
||||
|
|
|
|||
2
pom.xml
2
pom.xml
|
|
@ -20,7 +20,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<!-- 统一依赖管理 -->
|
||||
<spring.boot.version>2.7.18</spring.boot.version>
|
||||
<sa-token.version>1.38.0</sa-token.version>
|
||||
<sa-token.version>1.44.0</sa-token.version>
|
||||
<lombok.version>1.18.34</lombok.version>
|
||||
<hutool.version>5.8.29</hutool.version>
|
||||
<javax.mail.version>1.6.2</javax.mail.version>
|
||||
|
|
|
|||
|
|
@ -42,26 +42,6 @@ public interface AppConstant {
|
|||
*/
|
||||
String SAVE_WEIBO_VIDEO = "saveWeiBoVideo";
|
||||
|
||||
/**
|
||||
* 上传图片到AList
|
||||
*/
|
||||
String UPLOAD_ALIST = "uploadAList";
|
||||
|
||||
/**
|
||||
* AList Url
|
||||
*/
|
||||
String ALIST_URL = "aListUrl";
|
||||
/**
|
||||
* AList 账号
|
||||
*/
|
||||
String ALIST_USER = "aListUser";
|
||||
/**
|
||||
* AList 密码
|
||||
*/
|
||||
String ALIST_PASS = "aListPass";
|
||||
|
||||
String ALIST_UPLOAD_PATH = "aListUploadPath";
|
||||
|
||||
Integer MAIL_CONFIG_SIZE = 7;
|
||||
|
||||
String MAIL_CONFIG_ENABLE = "enable";
|
||||
|
|
|
|||
|
|
@ -1,107 +0,0 @@
|
|||
package com.bcrjl.rss.common.util;
|
||||
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.setting.Setting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.bcrjl.rss.common.constant.AppConstant.*;
|
||||
|
||||
/**
|
||||
* AList工具类
|
||||
*
|
||||
* @author yanqs
|
||||
*/
|
||||
@Slf4j
|
||||
public class AListUtils {
|
||||
|
||||
/**
|
||||
* AList 登录获取 Token 接口路径
|
||||
*/
|
||||
private static final String TOKEN_URL = "/api/auth/login";
|
||||
|
||||
/**
|
||||
* 上传流 接口路径
|
||||
*/
|
||||
private static final String UPLOAD_URL = "/api/fs/put";
|
||||
|
||||
/**
|
||||
* 创建本地缓存
|
||||
*/
|
||||
private static TimedCache<String, String> timedCache = CacheUtil.newTimedCache(86400000);
|
||||
|
||||
/**
|
||||
* 获取AList Token
|
||||
*
|
||||
* @return token
|
||||
*/
|
||||
private static String getToken() {
|
||||
try {
|
||||
String alistToken = timedCache.get("alist_token");
|
||||
if (StrUtil.isNotEmpty(alistToken)) {
|
||||
return alistToken;
|
||||
} else {
|
||||
Setting setting = new Setting(CONFIG_PATH, CharsetUtil.CHARSET_UTF_8, true);
|
||||
Setting systemSetting = setting.getSetting(SET_SYSTEM);
|
||||
Map<String, String> params = new HashMap<>(INIT_MAP);
|
||||
params.put("username", systemSetting.get(ALIST_USER));
|
||||
params.put("password", systemSetting.get(ALIST_PASS));
|
||||
String aListUrl = systemSetting.get(ALIST_URL);
|
||||
String body = HttpRequest.post(aListUrl + TOKEN_URL)
|
||||
.header(Header.CONTENT_TYPE, ContentType.JSON.getValue())
|
||||
.body(JSONUtil.toJsonStr(params))
|
||||
.execute().body();
|
||||
String token = JSONUtil.parseObj(body).getJSONObject("data").getStr("token");
|
||||
timedCache.put("alist_token", token);
|
||||
return token;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取AList Token异常:", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param fileByte 文件字节
|
||||
* @param fileName 文件名
|
||||
*/
|
||||
public static void uploadFile(byte[] fileByte, String fileName) {
|
||||
try {
|
||||
String time = DateUtil.format(new Date(), "yyyyMMdd");
|
||||
Setting setting = new Setting(CONFIG_PATH, CharsetUtil.CHARSET_UTF_8, true);
|
||||
Setting systemSetting = setting.getSetting(SET_SYSTEM);
|
||||
String aListUrl = systemSetting.get(ALIST_URL);
|
||||
String uploadPath = systemSetting.get(ALIST_UPLOAD_PATH);
|
||||
HttpResponse httpResponse = HttpRequest.put(aListUrl + UPLOAD_URL)
|
||||
.header(Header.AUTHORIZATION, getToken())
|
||||
.header(Header.CONTENT_TYPE, ContentType.MULTIPART.getValue())
|
||||
.header("File-Path", uploadPath + "/" + time + "/" + fileName)
|
||||
.body(fileByte)
|
||||
.execute();
|
||||
if (httpResponse.isOk()) {
|
||||
String message = JSONUtil.parseObj(httpResponse.body()).getStr("message");
|
||||
if (!"success".equals(message)) {
|
||||
log.info("AList上传失败:{}", message);
|
||||
}
|
||||
} else {
|
||||
log.info("AList上传失败,响应状态码:{}", httpResponse.getStatus());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("AList上传文件异常:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -43,16 +43,6 @@ public class FileMonitor {
|
|||
"saveWeiBoImages=false\n" +
|
||||
"## 保存微博视频\n" +
|
||||
"saveWeiBoVideo=true\n" +
|
||||
"## 上传图片到AList\n" +
|
||||
"uploadAList=false\n" +
|
||||
"## AList Url\n" +
|
||||
"aListUrl=\n" +
|
||||
"## AList 账号\n" +
|
||||
"aListUser=\n" +
|
||||
"## AList 密码\n" +
|
||||
"aListPass=\n" +
|
||||
"## AList 上传路径\n" +
|
||||
"aListUploadPath=\n" +
|
||||
"[mail]\n" +
|
||||
"## 启用邮件推送\n" +
|
||||
"enable=false\n" +
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import cn.hutool.http.HttpResponse;
|
|||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.setting.Setting;
|
||||
import com.bcrjl.rss.common.util.AListUtils;
|
||||
import com.bcrjl.rss.common.util.HtmlUtils;
|
||||
import com.bcrjl.rss.common.util.MailUtils;
|
||||
import com.bcrjl.rss.common.util.RssUtils;
|
||||
|
|
@ -115,14 +114,13 @@ public class RssJob {
|
|||
}
|
||||
|
||||
/**
|
||||
* 保存微博图片到本地且上传AList
|
||||
* 保存微博图片到本地
|
||||
*/
|
||||
private void saveWeiBoImagesOrUpdateAList(List<RssEntity> list) {
|
||||
Setting setting = new Setting(CONFIG_PATH, CharsetUtil.CHARSET_UTF_8, true);
|
||||
Setting systemSetting = setting.getSetting(SET_SYSTEM);
|
||||
boolean saveImages = Boolean.parseBoolean(systemSetting.get(SAVE_WEIBO_IMAGES));
|
||||
boolean saveVideo = Boolean.valueOf(systemSetting.get(SAVE_WEIBO_VIDEO));
|
||||
boolean uploadAList = Boolean.valueOf(systemSetting.get(UPLOAD_ALIST));
|
||||
if (saveImages) {
|
||||
// 保存图片
|
||||
list.forEach(obj -> {
|
||||
|
|
@ -133,26 +131,20 @@ public class RssJob {
|
|||
HttpResponse weiBoImagesHttpRequest = HtmlUtils.getWeiBoImagesHttpRequest(fileName);
|
||||
byte[] bytes = weiBoImagesHttpRequest.bodyBytes();
|
||||
FileUtil.writeBytes(bytes, new File(IMAGES_PATH + fileName));
|
||||
if (uploadAList) {
|
||||
AListUtils.uploadFile(bytes, fileName);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
if(saveVideo){
|
||||
if (saveVideo) {
|
||||
// 保存视频
|
||||
list.forEach(obj -> {
|
||||
List<String> videoList = HtmlUtils.extractVideoUrls(obj.getDescription());
|
||||
if(CollUtil.isNotEmpty(videoList)){
|
||||
if (CollUtil.isNotEmpty(videoList)) {
|
||||
videoList.forEach(videoObj -> {
|
||||
String fileName = HtmlUtils.getFileName(videoObj);
|
||||
HttpResponse weiBoVideoHttpRequest = HtmlUtils.getWeiBoVideoHttpRequest(videoObj);
|
||||
byte[] bytes = weiBoVideoHttpRequest.bodyBytes();
|
||||
FileUtil.writeBytes(bytes, new File(VIDEO_PATH + fileName));
|
||||
if (uploadAList) {
|
||||
AListUtils.uploadFile(bytes, fileName);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue