From cfde488bdd0163986087c880e0a2762645f8c14c Mon Sep 17 00:00:00 2001 From: inleft <inleft@qq.com> Date: Mon, 21 Feb 2022 15:35:35 +0800 Subject: [PATCH] 资源获取修正 --- snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/controller/BlogArticleOutsideController.java | 38 ++++++++++++++++++++++++++++++-------- 1 files changed, 30 insertions(+), 8 deletions(-) diff --git a/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/controller/BlogArticleOutsideController.java b/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/controller/BlogArticleOutsideController.java index fb3b319..0889227 100644 --- a/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/controller/BlogArticleOutsideController.java +++ b/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/controller/BlogArticleOutsideController.java @@ -44,6 +44,8 @@ import vip.xiaonuo.modular.blogarticle.param.BlogArticleQueryDto; import vip.xiaonuo.modular.blogarticle.param.BlogArticleVo; import vip.xiaonuo.modular.blogarticle.service.BlogArticleService; +import vip.xiaonuo.sys.modular.file.entity.SysFileInfo; +import vip.xiaonuo.sys.modular.file.service.SysFileInfoService; import javax.annotation.Resource; import java.util.HashMap; @@ -64,6 +66,10 @@ @Resource private BlogArticleService blogArticleService; + + @Resource + private SysFileInfoService fileInfoService; + /** * 查询blog文章 * @@ -78,16 +84,20 @@ Map<String, Object> param = new HashMap<>(16); param.put("pageNo", PageUtil.getStart(queryDto.getPageNo() - 1, queryDto.getPageSize())); param.put("pageSize", queryDto.getPageSize()); - String fileUploadPathForLinux = ConstantContextHolder.getDefaultFileUploadPathForLinux(); + param.put("typeId", queryDto.getTypeId()); - List<BlogArticleVo> resList = blogArticleService.searchMediaList(param).stream().map(e -> { - if (StrUtil.isNotEmpty(e.getArticleFileURL())) { - e.setArticleFileURL(fileUploadPathForLinux + e.getArticleFileURL()); + String blogSourcePrefix = ConstantContextHolder.getBlogSourcePrefix(); + List<BlogArticleVo> resList = blogArticleService.searchList(param).stream().map(e -> { + if (StrUtil.isNotEmpty(e.getCoverFileURL())) { + if (!e.getCoverFileURL().startsWith("http")) { + //补上访问参数 + e.setCoverFileURL(blogSourcePrefix + e.getCoverFileURL()); + } } return e; }).collect(Collectors.toList()); - long count = blogArticleService.searchMediaListCount(param); + long count = blogArticleService.searchListCount(param); Page<BlogArticleVo> queryPage = new Page<>(queryDto.getPageNo(), queryDto.getPageSize()); queryPage.setRecords(resList); @@ -119,7 +129,7 @@ if (!SecureUtil.md5(find.getAuthPassword()).equals(queryDto.getAuthWord())) { throw new BlogException(BlogExceptionEnum.article_auth_pass_error); } - }else if(find.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)){ + } else if (find.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)) { throw new BlogException(BlogExceptionEnum.article_auth_private_error); } @@ -128,14 +138,26 @@ BeanUtil.copyProperties(find, vo); if (queryDto.getId() % 2 == 0) { - vo.setArticleFileURL("http://t.inleft.com/share/book/blog/es_index.md"); + String tempURL = this.getBlogSourceURL(find.getArticleFileId()); + if (StrUtil.isEmpty(tempURL)) + throw new BlogException(BlogExceptionEnum.article_file_lose); + + vo.setArticleFileURL(tempURL); } else { vo.setArticleFileURL("http://t.inleft.com/share/book/blog/es-search.md"); } - return new SuccessResponseData(vo); } + private String getBlogSourceURL(Long fileId) { + SysFileInfo sysFileInfo = fileInfoService.getById(fileId); + if (sysFileInfo == null) { + return null; + } else { + String blogSourcePrefix = ConstantContextHolder.getBlogSourcePrefix(); + return blogSourcePrefix + sysFileInfo.getFileBucket() + sysFileInfo.getFileObjectName(); + } + } } -- Gitblit v1.9.1