ソースを参照

!185 移除文件上传的token校验
Merge pull request !185 from blue/v_3.0.0

blue 1 ヶ月 前
コミット
2c96499601

+ 1 - 3
README.md

@@ -23,7 +23,6 @@
 - 框架和组件版本全面升级: jdk17、springboot3.3、node18等
 - 部分界面,功能、性能优化
 
-
 #### 在线体验
 
 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/qgq5cvgmavallqnl
+商业版源码授权: https://www.yuque.com/u1475064/imk5n2/qtezcg32q1d0dr29
 
 #### 项目结构
 | 模块          | 功能                               |

+ 1 - 1
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) {
         registry.addInterceptor(xssInterceptor).addPathPatterns("/**").excludePathPatterns("/error");
         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");
     }
 

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

@@ -26,7 +26,7 @@ public class FileController {
     @PostMapping("/image/upload")
     public Result<UploadImageVO> uploadImage(@RequestParam("file") MultipartFile file,
         @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")

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

+ 1 - 33
im-uniapp/components/file-upload/file-upload.vue

@@ -17,10 +17,7 @@ export default {
 			fileMap: new Map(),
 			option: {
 				url: UNI_APP.BASE_URL + '/file/upload',
-				name: 'file',
-				header: {
-					accessToken: uni.getStorageSync('loginInfo').accessToken
-				}
+				name: 'file'
 			}
 		}
 	},
@@ -59,17 +56,6 @@ export default {
 			if (res.code == 200) {
 				// 上传成功
 				this.onOk(file, res);
-			} else if (res.code == 401) {
-				// token已过期,重新获取token
-				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 {
 				// 上传失败
 				this.onError(file, res);
@@ -95,24 +81,6 @@ export default {
 			this.fileMap.delete(file.path);
 			this.$refs.lsjUpload.clear(file.name);
 			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);
-					}
-				})
-			})
 		}
 	}
 

+ 1 - 8
im-uniapp/components/image-upload/image-upload.vue

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