Browse Source

移除文件上传的token校验

master
xsx 2 months ago
parent
commit
b20a71b508
  1. 4
      README.md
  2. 2
      im-platform/src/main/java/com/bx/implatform/config/MvcConfig.java
  3. 2
      im-platform/src/main/java/com/bx/implatform/controller/FileController.java
  4. 7
      im-platform/src/main/java/com/bx/implatform/service/impl/FileServiceImpl.java
  5. 34
      im-uniapp/components/file-upload/file-upload.vue
  6. 9
      im-uniapp/components/image-upload/image-upload.vue

4
README.md

@ -23,7 +23,6 @@
- 框架和组件版本全面升级: jdk17、springboot3.3、node18等 - 框架和组件版本全面升级: jdk17、springboot3.3、node18等
- 部分界面,功能、性能优化 - 部分界面,功能、性能优化
#### 在线体验 #### 在线体验
web端:https://www.boxim.online web端:https://www.boxim.online
@ -48,8 +47,7 @@ https://www.yuque.com/u1475064/imk5n2/qtezcg32q1d0dr29#SbvXq
#### 付费服务 #### 付费服务
商业版源码: https://www.yuque.com/u1475064/imk5n2/qtezcg32q1d0dr29 商业版源码授权: https://www.yuque.com/u1475064/imk5n2/qtezcg32q1d0dr29
环境搭建: https://www.yuque.com/u1475064/imk5n2/qgq5cvgmavallqnl
#### 项目结构 #### 项目结构
| 模块 | 功能 | | 模块 | 功能 |

2
im-platform/src/main/java/com/bx/implatform/config/MvcConfig.java

@ -21,7 +21,7 @@ public class MvcConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(xssInterceptor).addPathPatterns("/**").excludePathPatterns("/error"); registry.addInterceptor(xssInterceptor).addPathPatterns("/**").excludePathPatterns("/error");
registry.addInterceptor(authInterceptor).addPathPatterns("/**") registry.addInterceptor(authInterceptor).addPathPatterns("/**")
.excludePathPatterns("/login", "/logout", "/register", "/refreshToken", "/swagger/**", "/v3/api-docs/**", .excludePathPatterns("/login", "/logout", "/register", "/refreshToken","/*/upload", "/swagger/**", "/v3/api-docs/**",
"/swagger-resources/**", "/swagger-ui.html", "/swagger-ui/**", "/doc.html"); "/swagger-resources/**", "/swagger-ui.html", "/swagger-ui/**", "/doc.html");
} }

2
im-platform/src/main/java/com/bx/implatform/controller/FileController.java

@ -26,7 +26,7 @@ public class FileController {
@PostMapping("/image/upload") @PostMapping("/image/upload")
public Result<UploadImageVO> uploadImage(@RequestParam("file") MultipartFile file, public Result<UploadImageVO> uploadImage(@RequestParam("file") MultipartFile file,
@RequestParam(defaultValue = "true") Boolean isPermanent, @RequestParam(defaultValue = "50") Long thumbSize) { @RequestParam(defaultValue = "true") Boolean isPermanent, @RequestParam(defaultValue = "50") Long thumbSize) {
return ResultUtils.success(fileService.uploadImage(file, isPermanent,thumbSize)); return ResultUtils.success(fileService.uploadImage(file, isPermanent, thumbSize));
} }
@Operation(summary = "上传文件", description = "上传文件,上传后返回文件url") @Operation(summary = "上传文件", description = "上传文件,上传后返回文件url")

7
im-platform/src/main/java/com/bx/implatform/service/impl/FileServiceImpl.java

@ -12,7 +12,6 @@ import com.bx.implatform.enums.ResultCode;
import com.bx.implatform.exception.GlobalException; import com.bx.implatform.exception.GlobalException;
import com.bx.implatform.mapper.FileInfoMapper; import com.bx.implatform.mapper.FileInfoMapper;
import com.bx.implatform.service.FileService; import com.bx.implatform.service.FileService;
import com.bx.implatform.session.SessionContext;
import com.bx.implatform.thirdparty.MinioService; import com.bx.implatform.thirdparty.MinioService;
import com.bx.implatform.util.FileUtil; import com.bx.implatform.util.FileUtil;
import com.bx.implatform.util.ImageUtil; import com.bx.implatform.util.ImageUtil;
@ -59,7 +58,6 @@ public class FileServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> imple
@Override @Override
public String uploadFile(MultipartFile file) { public String uploadFile(MultipartFile file) {
try { try {
Long userId = SessionContext.getSession().getUserId();
// 文件名长度校验 // 文件名长度校验
checkFileNameLength(file); checkFileNameLength(file);
// 大小校验 // 大小校验
@ -84,7 +82,7 @@ public class FileServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> imple
String url = generUrl(FileType.FILE, fileName); String url = generUrl(FileType.FILE, fileName);
// 保存文件 // 保存文件
saveFileInfo(file, md5, url); saveFileInfo(file, md5, url);
log.info("文件文件成功,用户id:{},url:{}", userId, url); log.info("文件文件成功,url:{}", url);
return url; return url;
} catch (IOException e) { } catch (IOException e) {
log.error("上传图片失败,{}", e.getMessage(), e); log.error("上传图片失败,{}", e.getMessage(), e);
@ -96,7 +94,6 @@ public class FileServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> imple
@Override @Override
public UploadImageVO uploadImage(MultipartFile file, Boolean isPermanent,Long thumbSize) { public UploadImageVO uploadImage(MultipartFile file, Boolean isPermanent,Long thumbSize) {
try { try {
Long userId = SessionContext.getSession().getUserId();
// 文件名长度校验 // 文件名长度校验
checkFileNameLength(file); checkFileNameLength(file);
// 大小校验 // 大小校验
@ -150,7 +147,7 @@ public class FileServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> imple
// 保存文件信息,由于缩略图不允许删除,此时原图也不允许删除 // 保存文件信息,由于缩略图不允许删除,此时原图也不允许删除
saveImageFileInfo(file, md5, vo.getOriginUrl(), vo.getThumbUrl(), true); saveImageFileInfo(file, md5, vo.getOriginUrl(), vo.getThumbUrl(), true);
} }
log.info("文件图片成功,用户id:{},url:{}", userId, vo.getOriginUrl()); log.info("文件图片成功,url:{}", vo.getOriginUrl());
return vo; return vo;
} catch (IOException e) { } catch (IOException e) {
log.error("上传图片失败,{}", e.getMessage(), e); log.error("上传图片失败,{}", e.getMessage(), e);

34
im-uniapp/components/file-upload/file-upload.vue

@ -17,10 +17,7 @@ export default {
fileMap: new Map(), fileMap: new Map(),
option: { option: {
url: UNI_APP.BASE_URL + '/file/upload', url: UNI_APP.BASE_URL + '/file/upload',
name: 'file', name: 'file'
header: {
accessToken: uni.getStorageSync('loginInfo').accessToken
}
} }
} }
}, },
@ -59,17 +56,6 @@ export default {
if (res.code == 200) { if (res.code == 200) {
// //
this.onOk(file, res); this.onOk(file, res);
} else if (res.code == 401) {
// tokentoken
this.refreshToken().then((res) => {
let newToken = res.data.accessToken;
this.option.header.accessToken = newToken;
this.$refs.lsjUpload.setData(this.option);
//
this.$refs.lsjUpload.upload(file.name);
}).catch(() => {
this.onError(file, res);
})
} else { } else {
// //
this.onError(file, res); this.onError(file, res);
@ -95,24 +81,6 @@ export default {
this.fileMap.delete(file.path); this.fileMap.delete(file.path);
this.$refs.lsjUpload.clear(file.name); this.$refs.lsjUpload.clear(file.name);
this.onError && this.onError(file, res); this.onError && this.onError(file, res);
},
refreshToken() {
return new Promise((resolve, reject) => {
let loginInfo = uni.getStorageSync('loginInfo')
uni.request({
method: 'PUT',
url: UNI_APP.BASE_URL + '/refreshToken',
header: {
refreshToken: loginInfo.refreshToken
},
success: (res) => {
resolve(res.data);
},
fail: (res) => {
reject(res);
}
})
})
} }
} }

9
im-uniapp/components/image-upload/image-upload.vue

@ -10,11 +10,7 @@ import UNI_APP from '@/.env.js'
export default { export default {
name: "image-upload", name: "image-upload",
data() { data() {
return { return {}
uploadHeaders: {
"accessToken": uni.getStorageSync('loginInfo').accessToken
}
}
}, },
props: { props: {
maxCount: { maxCount: {
@ -70,9 +66,6 @@ export default {
let action = `/image/upload?isPermanent=${this.isPermanent}&thumbSize=${this.thumbSize}` let action = `/image/upload?isPermanent=${this.isPermanent}&thumbSize=${this.thumbSize}`
uni.uploadFile({ uni.uploadFile({
url: UNI_APP.BASE_URL + action, url: UNI_APP.BASE_URL + action,
header: {
accessToken: uni.getStorageSync("loginInfo").accessToken
},
filePath: file.path, // filePath: file.path, //
name: 'file', name: 'file',
success: (res) => { success: (res) => {

Loading…
Cancel
Save