mirror of
https://gitee.com/lxp135/minio-plus.git
synced 2025-12-06 17:08:26 +08:00
minio-plus-extension 加入UserHolder 来存取登录用户编号,演示工程中增加拦截器实现登录用户逻辑。
This commit is contained in:
parent
f743c1f240
commit
90380c0541
@ -286,6 +286,10 @@ CREATE TABLE `file_metadata_info` (
|
||||
|
||||
# 6 使用 | Getting Started
|
||||
|
||||
## 6.1 使用 minio-plus-all-spring-boot-starter
|
||||
|
||||
## 6.2 使用 minio-plus-core-spring-boot-starter
|
||||
|
||||
# 7 代码托管 | Managed Code
|
||||
|
||||
* [https://gitee.com/lxp135/minio-plus](https://gitee.com/lxp135/minio-plus/)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<mxfile host="Electron" modified="2024-06-07T07:27:04.557Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.7.5 Chrome/114.0.5735.289 Electron/25.8.1 Safari/537.36" etag="D3NqR_juW6TF88F4hGhN" version="21.7.5" type="device" pages="7">
|
||||
<mxfile host="Electron" modified="2024-06-11T08:09:53.078Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.7.5 Chrome/114.0.5735.289 Electron/25.8.1 Safari/537.36" etag="vK7_c2ukX2-1xsmpvHLO" version="21.7.5" type="device" pages="7">
|
||||
<diagram name="文件/图片下载时序图" id="IS7WuVfpSdjpWJYDzwDI">
|
||||
<mxGraphModel dx="1372" dy="841" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<mxGraphModel dx="1100" dy="842" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
@ -109,7 +109,7 @@
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
<diagram id="xhg19-cS3vChz7J91BQU" name="文件上传时序图">
|
||||
<mxGraphModel dx="1372" dy="841" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<mxGraphModel dx="1100" dy="842" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
@ -262,15 +262,15 @@
|
||||
<mxPoint x="485" y="608" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="-wSVdkolJl0VM9dSvFRS-1" value="" style="html=1;points=[[0,0,0,0,5],[0,1,0,0,-5],[1,0,0,0,5],[1,1,0,0,-5]];perimeter=orthogonalPerimeter;outlineConnect=0;targetShapes=umlLifeline;portConstraint=eastwest;newEdgeStyle={"curved":0,"rounded":0};" vertex="1" parent="1">
|
||||
<mxCell id="-wSVdkolJl0VM9dSvFRS-1" value="" style="html=1;points=[[0,0,0,0,5],[0,1,0,0,-5],[1,0,0,0,5],[1,1,0,0,-5]];perimeter=orthogonalPerimeter;outlineConnect=0;targetShapes=umlLifeline;portConstraint=eastwest;newEdgeStyle={"curved":0,"rounded":0};" parent="1" vertex="1">
|
||||
<mxGeometry x="555" y="639" width="10" height="30" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="-wSVdkolJl0VM9dSvFRS-2" value="合并文件" style="html=1;verticalAlign=bottom;endArrow=block;curved=0;rounded=0;entryX=0;entryY=0;entryDx=0;entryDy=5;" edge="1" parent="1" target="-wSVdkolJl0VM9dSvFRS-1">
|
||||
<mxCell id="-wSVdkolJl0VM9dSvFRS-2" value="合并文件" style="html=1;verticalAlign=bottom;endArrow=block;curved=0;rounded=0;entryX=0;entryY=0;entryDx=0;entryDy=5;" parent="1" target="-wSVdkolJl0VM9dSvFRS-1" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="365" y="644" as="sourcePoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="-wSVdkolJl0VM9dSvFRS-3" value="合并文件结果" style="html=1;verticalAlign=bottom;endArrow=open;dashed=1;endSize=8;curved=0;rounded=0;exitX=0;exitY=1;exitDx=0;exitDy=-5;" edge="1" parent="1" source="-wSVdkolJl0VM9dSvFRS-1">
|
||||
<mxCell id="-wSVdkolJl0VM9dSvFRS-3" value="合并文件结果" style="html=1;verticalAlign=bottom;endArrow=open;dashed=1;endSize=8;curved=0;rounded=0;exitX=0;exitY=1;exitDx=0;exitDy=-5;" parent="1" source="-wSVdkolJl0VM9dSvFRS-1" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="365" y="664" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
@ -279,7 +279,7 @@
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
<diagram id="O2Dvrrli3WKo_xqLgD6Y" name="图片上传时序图">
|
||||
<mxGraphModel dx="1372" dy="841" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<mxGraphModel dx="1100" dy="842" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
@ -358,14 +358,14 @@
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
<diagram id="C3TxWB7rWC2Go-Cd--VL" name="文件上传活动图">
|
||||
<mxGraphModel dx="1372" dy="841" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<mxGraphModel dx="1100" dy="842" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
<mxCell id="C4ZSU_w1gQOmh6ewiK0h-1" value="" style="ellipse;html=1;shape=startState;fillColor=#000000;strokeColor=#ff0000;" parent="1" vertex="1">
|
||||
<mxGeometry x="144" y="40" width="30" height="30" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="C4ZSU_w1gQOmh6ewiK0h-2" value="" style="edgeStyle=orthogonalEdgeStyle;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;rounded=0;" parent="1" source="C4ZSU_w1gQOmh6ewiK0h-1" edge="1" target="eImii3Ch162-0qwuOzGB-1">
|
||||
<mxCell id="C4ZSU_w1gQOmh6ewiK0h-2" value="" style="edgeStyle=orthogonalEdgeStyle;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;rounded=0;" parent="1" source="C4ZSU_w1gQOmh6ewiK0h-1" target="eImii3Ch162-0qwuOzGB-1" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="159" y="130" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
@ -373,10 +373,10 @@
|
||||
<mxCell id="C4ZSU_w1gQOmh6ewiK0h-3" value="" style="ellipse;html=1;shape=endState;fillColor=#000000;strokeColor=#ff0000;" parent="1" vertex="1">
|
||||
<mxGeometry x="200" y="770" width="30" height="30" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="eImii3Ch162-0qwuOzGB-1" value="Activity" style="rounded=1;whiteSpace=wrap;html=1;arcSize=40;fontColor=#000000;fillColor=#ffffc0;strokeColor=#ff0000;" vertex="1" parent="1">
|
||||
<mxCell id="eImii3Ch162-0qwuOzGB-1" value="Activity" style="rounded=1;whiteSpace=wrap;html=1;arcSize=40;fontColor=#000000;fillColor=#ffffc0;strokeColor=#ff0000;" parent="1" vertex="1">
|
||||
<mxGeometry x="99" y="130" width="120" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="eImii3Ch162-0qwuOzGB-2" value="" style="edgeStyle=orthogonalEdgeStyle;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;rounded=0;" edge="1" source="eImii3Ch162-0qwuOzGB-1" parent="1">
|
||||
<mxCell id="eImii3Ch162-0qwuOzGB-2" value="" style="edgeStyle=orthogonalEdgeStyle;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;rounded=0;" parent="1" source="eImii3Ch162-0qwuOzGB-1" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="159" y="230" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
@ -489,72 +489,72 @@
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
<diagram id="4VlLv3Fkj26ipgTOubD9" name="开发计划">
|
||||
<mxGraphModel dx="1372" dy="841" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<mxGraphModel dx="1100" dy="842" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-2" value="minio-s3-api-official <br>自动化测试用例" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="200" y="40" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="200" y="40" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-3" value="单元测试" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-2" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-4" value="项目文档部署" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="770" y="40" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="770" y="40" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-5" value="项目官网" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-4" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-6" value="演示程序部署" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="770" y="130" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="770" y="150" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-7" value="项目官网" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-6" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-8" value="Maven Repository<br>提交中央仓库" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="40" width="160" height="60" as="geometry" />
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-8" value="Maven Repository<br>发布中央仓库流程跑通" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;fillColor=#cdeb8b;strokeColor=#36393d;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="40" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-9" value="发布" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-8" vertex="1">
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-9" value="发布(已完成)" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-8" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-13" value="minio-s3-api-custom<br>模块开发" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="10" y="40" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="10" y="40" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-14" value="功能开发" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-13" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-16" value="minio-s3-api-custom<br>自动化测试用例" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="200" y="130" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="200" y="150" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-17" value="单元测试" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-16" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-18" value="minio-plus-core<br>自动化测试用例" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="200" y="220" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="200" y="260" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-19" value="单元测试" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-18" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-20" value="使用手册" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="390" y="40" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="390" y="40" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-21" value="文档" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-20" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-22" value="开发手册" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="390" y="130" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="390" y="150" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-23" value="文档" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-22" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-24" value="新闻、介绍文章" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="390" y="220" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="390" y="260" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="SrG1LAP0XBL15DKdnUUl-25" value="文档" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="SrG1LAP0XBL15DKdnUUl-24" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="0HtNRO_DIxhBXSRWM3wU-1" value="漂亮的前端演示页面制作" style="shape=note2;boundedLbl=1;whiteSpace=wrap;html=1;size=25;verticalAlign=top;align=center;" parent="1" vertex="1">
|
||||
<mxGeometry x="10" y="130" width="160" height="60" as="geometry" />
|
||||
<mxGeometry x="10" y="150" width="160" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="0HtNRO_DIxhBXSRWM3wU-2" value="功能开发" style="resizeWidth=1;part=1;strokeColor=none;fillColor=none;align=left;spacingLeft=5;" parent="0HtNRO_DIxhBXSRWM3wU-1" vertex="1">
|
||||
<mxGeometry width="160" height="25" relative="1" as="geometry" />
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
package org.liuxp.minioplus.application.common;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.liuxp.minioplus.extension.context.UserHolder;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 登录用户拦截器
|
||||
*
|
||||
* @author contact@liuxp.me
|
||||
* @since 2024/06/11
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LoginUserInterceptor implements HandlerInterceptor {
|
||||
|
||||
/**
|
||||
* 处理登录用户信息
|
||||
*
|
||||
* @param request 请求
|
||||
* @param response 返回
|
||||
* @param handler 要执行的处理程序
|
||||
* @return 是否继续执行下一个拦截器
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, @Nonnull HttpServletResponse response, @Nonnull Object handler) {
|
||||
String userId = request.getHeader("Authorization");
|
||||
UserHolder.set(userId);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理资源
|
||||
*
|
||||
* @param request 请求
|
||||
* @param response 返回
|
||||
* @param handler 要执行的处理程序
|
||||
* @param exception 异常信息
|
||||
*/
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception exception) {
|
||||
log.debug("Project ThreadLocal 清理之前:{}", UserHolder.get());
|
||||
UserHolder.clean();
|
||||
log.debug("Project ThreadLocal 清理之之后:{}", UserHolder.get());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package org.liuxp.minioplus.application.common;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* SpringMVC配置
|
||||
* @author contact@liuxp.me
|
||||
* @since 2024/06/11
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Resource
|
||||
private LoginUserInterceptor loginUserInterceptor;
|
||||
|
||||
/**
|
||||
* 前置拦截器
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 登录用户
|
||||
registry.addInterceptor(loginUserInterceptor).addPathPatterns("/storage/**");
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,10 @@
|
||||
<script src="js/upload.js"></script>
|
||||
<body>
|
||||
<div id="app">
|
||||
<div>
|
||||
<label for="loginUser">登录用户:</label><input type="text" v-model="loginUser" id="loginUser">
|
||||
</div>
|
||||
<br>
|
||||
<input type="file" @click="clearState" id="upload">
|
||||
<button @click="checkFile">检查</button>
|
||||
<button @click="uploadFile(false)" :disabled="partList.length === 0">正常上传</button>
|
||||
@ -49,6 +53,7 @@
|
||||
partSize: null,
|
||||
fileSize: null,
|
||||
previewUrl: null,
|
||||
loginUser:'mockUser01'
|
||||
})
|
||||
/**
|
||||
* 文件检查
|
||||
@ -68,7 +73,8 @@
|
||||
fetch("/storage/upload/init", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
"Authorization":state.loginUser
|
||||
},
|
||||
body: JSON.stringify({
|
||||
fileMd5: fileMd5,
|
||||
@ -154,7 +160,8 @@
|
||||
fetch(`/storage/upload/complete/${state.uploadId}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
"Authorization":state.loginUser
|
||||
},
|
||||
body: JSON.stringify({
|
||||
partMd5List: partMd5List
|
||||
@ -182,11 +189,38 @@
|
||||
* 下载文件
|
||||
*/
|
||||
const download = () => {
|
||||
window.location.href = `/storage/download/${state.uploadId}`;
|
||||
|
||||
fetch(`/storage/download/${state.uploadId}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization":state.loginUser
|
||||
},
|
||||
redirect:'follow'
|
||||
}).then(data => {
|
||||
console.log(data);
|
||||
window.location.href = data.url;
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
// 文件预览
|
||||
// 图片预览
|
||||
const preview = () => {
|
||||
state.previewUrl = `/storage/preview/original/${state.uploadId}`;
|
||||
|
||||
fetch(`/storage/preview/${state.uploadId}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization":state.loginUser
|
||||
},
|
||||
redirect:'follow'
|
||||
}).then(data => {
|
||||
console.log(data);
|
||||
state.previewUrl = data.url;
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
}
|
||||
// 删除文件
|
||||
const remove = () => {
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
package org.liuxp.minioplus.extension.context;
|
||||
|
||||
/**
|
||||
* 用户信息助手
|
||||
* 当使用 minio-plus-extension 模块中的 controller 时,存取登录用户编号
|
||||
* @author contact@liuxp.me
|
||||
* @since 2024/06/11
|
||||
*/
|
||||
public class UserHolder {
|
||||
|
||||
/**
|
||||
* 登录用户编号
|
||||
*/
|
||||
private static final ThreadLocal<String> userThreadLocal = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 获取登录用户编号
|
||||
* @return 登录用户编号
|
||||
*/
|
||||
public static String get() {
|
||||
return userThreadLocal.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置登录用户编号
|
||||
* @param userId 登录用户编号
|
||||
*/
|
||||
public static void set(String userId) {
|
||||
userThreadLocal.set(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除登录用户编号
|
||||
*/
|
||||
public static void clean() {
|
||||
userThreadLocal.remove();
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,6 +5,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.liuxp.minioplus.api.StorageService;
|
||||
import org.liuxp.minioplus.extension.context.UserHolder;
|
||||
import org.liuxp.minioplus.extension.dto.FileCheckDTO;
|
||||
import org.liuxp.minioplus.extension.dto.FileCompleteDTO;
|
||||
import org.liuxp.minioplus.api.model.vo.CompleteResultVo;
|
||||
@ -53,7 +54,7 @@ public class StorageController {
|
||||
public Response<FileCheckResultVo> init(@RequestBody @Validated FileCheckDTO fileCheckDTO) {
|
||||
|
||||
// 取得当前登录用户信息
|
||||
String userId = "mockUser";
|
||||
String userId = UserHolder.get();
|
||||
|
||||
FileCheckResultVo resultVo = storageService.init(fileCheckDTO.getFileMd5(),fileCheckDTO.getFullFileName(),fileCheckDTO.getFileSize(),fileCheckDTO.getIsPrivate(),userId);
|
||||
|
||||
@ -72,7 +73,7 @@ public class StorageController {
|
||||
public Response<Object> complete(@PathVariable("fileKey") String fileKey, @RequestBody FileCompleteDTO fileCompleteDTO) {
|
||||
|
||||
// 取得当前登录用户信息
|
||||
String userId = "mockUser";
|
||||
String userId = UserHolder.get();
|
||||
|
||||
// 打印调试日志
|
||||
log.debug("合并文件开始fileKey="+fileKey+",partMd5List="+fileCompleteDTO.getPartMd5List());
|
||||
@ -115,7 +116,8 @@ public class StorageController {
|
||||
public String download(@PathVariable String fileKey) {
|
||||
|
||||
// 取得当前登录用户信息
|
||||
String userId = "mockUser";
|
||||
String userId = UserHolder.get();
|
||||
|
||||
// 取得文件读取路径
|
||||
return REDIRECT_PREFIX + storageService.download(fileKey, userId);
|
||||
}
|
||||
@ -126,11 +128,12 @@ public class StorageController {
|
||||
* @return 原图地址
|
||||
*/
|
||||
@ApiOperation(value = "图片预览 - 原图")
|
||||
@GetMapping("/preview/original/{fileKey}")
|
||||
@GetMapping("/image/{fileKey}")
|
||||
public String previewOriginal(@PathVariable String fileKey) {
|
||||
|
||||
// 取得当前登录用户信息
|
||||
String userId = "mockUser";
|
||||
String userId = UserHolder.get();
|
||||
|
||||
// 取得文件读取路径
|
||||
return REDIRECT_PREFIX + storageService.image(fileKey, userId);
|
||||
}
|
||||
@ -141,11 +144,12 @@ public class StorageController {
|
||||
* @return 缩略图地址
|
||||
*/
|
||||
@ApiOperation(value = "图片预览 - 缩略图")
|
||||
@GetMapping("/preview/medium/{fileKey}")
|
||||
@GetMapping("/preview/{fileKey}")
|
||||
public String previewMedium(@PathVariable String fileKey) {
|
||||
|
||||
// 取得当前登录用户信息
|
||||
String userId = "mockUser";
|
||||
String userId = UserHolder.get();
|
||||
|
||||
// 取得文件读取路径
|
||||
return REDIRECT_PREFIX + storageService.preview(fileKey, userId);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user