/*
|
Copyright [2020] [https://www.xiaonuo.vip]
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
you may not use this file except in compliance with the License.
|
You may obtain a copy of the License at
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
Unless required by applicable law or agreed to in writing, software
|
distributed under the License is distributed on an "AS IS" BASIS,
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
See the License for the specific language governing permissions and
|
limitations under the License.
|
|
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
|
1.请不要删除和修改根目录下的LICENSE文件。
|
2.请不要删除和修改Snowy源码头部的版权声明。
|
3.请保留源码和相关描述文件的项目出处,作者声明等。
|
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
|
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
|
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
*/
|
package vip.xiaonuo.modular.xmlFeed;
|
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.StrUtil;
|
import com.rometools.rome.feed.rss.*;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
import vip.xiaonuo.core.annotion.BusinessLog;
|
import vip.xiaonuo.core.consts.MyConstant;
|
import vip.xiaonuo.core.context.constant.ConstantContextHolder;
|
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
|
import vip.xiaonuo.modular.blogarticle.entity.BlogArticle;
|
import vip.xiaonuo.modular.blogarticle.service.BlogArticleService;
|
import vip.xiaonuo.sys.modular.file.service.SysFileInfoService;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* blog文章控制器 (提供给外部blog系统查询)
|
*
|
* @author inleft
|
* @date 2024-05-18 09:23:00
|
*/
|
@RestController
|
@RequestMapping
|
@Slf4j
|
public class BlogFeedController {
|
|
@Resource
|
private BlogArticleService blogArticleService;
|
|
|
@Resource
|
private SysFileInfoService fileInfoService;
|
|
|
/**
|
* 获取订阅列表,返回最新的10条
|
*
|
* @author inleft
|
* @date 2024-05-18 09:23:00
|
*/
|
@GetMapping("/feed")
|
@BusinessLog(title = "获取订阅列表", opType = LogAnnotionOpTypeEnum.QUERY)
|
public Channel queryBlogArticleList() {
|
|
|
Map<String, Object> param = new HashMap<>(16);
|
param.put("pageNo", 0);
|
param.put("pageSize", 10);
|
|
param.put("faceExcludeFile", MyConstant.faceExcludeFile);
|
String blogSourcePrefix = ConstantContextHolder.getBlogSourcePrefix();
|
|
|
Channel channel = new Channel();
|
channel.setFeedType("rss_2.0");
|
channel.setTitle("inleft");
|
channel.setDescription("在你左边,听风及雨");
|
channel.setLink("http://blog.inleft.com");
|
channel.setUri("http://blog.inleft.com");
|
channel.setGenerator("inleft");
|
|
Image image = new Image();
|
image.setUrl("http://t.inleft.com/share/media_photo/xigong.png");
|
image.setTitle("inleft");
|
image.setHeight(32);
|
image.setWidth(32);
|
channel.setImage(image);
|
|
//更新明细
|
|
Date now = DateUtil.date();
|
//空类型查询条件,排除笔记系列,按更新时间倒序
|
//含有类型查询,按发布时间倒序
|
List<Item> resList = blogArticleService.searchList(param).stream().map(e -> {
|
|
Source source = new Source();
|
if (StrUtil.isNotEmpty(e.getCoverFileURL())) {
|
if (!e.getCoverFileURL().startsWith("http")) {
|
//补上访问参数
|
source.setUrl(blogSourcePrefix + e.getCoverFileURL());
|
source.setValue(blogSourcePrefix + e.getCoverFileURL());
|
}
|
}else {
|
source.setUrl("http://t.inleft.com/share/media_photo/1.jpg");
|
source.setValue("http://t.inleft.com/share/media_photo/1.jpg");
|
}
|
|
Category category = new com.rometools.rome.feed.rss.Category();
|
category.setValue(e.getArticleTypeName());
|
|
|
Description descr = new Description();
|
descr.setValue(e.getIntroduce());
|
|
Item item = new Item();
|
item.setAuthor("inleft");
|
|
item.setUri("http://blog.inleft.com");
|
|
item.setComments("http://blog.inleft.com/mdDetail?id=" + e.getId());
|
|
item.setTitle(e.getTitle());
|
item.setLink("http://blog.inleft.com/mdDetail?id=" + e.getId());
|
item.setDescription(descr);
|
item.setCategories(Collections.singletonList(category));
|
item.setSource(source);
|
item.setPubDate(e.getUpdateDate());
|
|
//前端根据条件标注小红点(发布时间小于更新时间,且在7天内)
|
/*if (e.getPublishDate().before(e.getUpdateDate())
|
&& DateUtil.between(e.getUpdateDate(), now, DateUnit.DAY) <= 7) {
|
e.setIsAnyUpdate(MyConstant.Yes);
|
item.setTitle(e.getTitle()+"(最近翻新)");
|
}*/
|
|
return item;
|
}).collect(Collectors.toList());
|
|
|
//最后更新时间
|
BlogArticle lastUpdateBlog = blogArticleService.lambdaQuery().orderByDesc(BlogArticle::getUpdateDate).last(MyConstant.limit).one();
|
if (lastUpdateBlog != null && lastUpdateBlog.getUpdateDate() != null) {
|
channel.setLastBuildDate(lastUpdateBlog.getUpdateDate());
|
}
|
channel.setPubDate(now);
|
|
channel.setItems(resList);
|
|
return channel;
|
}
|
|
}
|