get full file url
This commit is contained in:
parent
0fa88c2c23
commit
d25c7d3aaf
|
|
@ -3,10 +3,7 @@ package com.bonus.system.api;
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RequestPart;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.bonus.common.core.constant.ServiceNameConstants;
|
import com.bonus.common.core.constant.ServiceNameConstants;
|
||||||
import com.bonus.common.core.domain.R;
|
import com.bonus.common.core.domain.R;
|
||||||
|
|
@ -45,4 +42,7 @@ public interface RemoteFileService
|
||||||
*/
|
*/
|
||||||
@PostMapping("/deleteFile")
|
@PostMapping("/deleteFile")
|
||||||
public AjaxResult deleteFile(@RequestParam("objectKey") String objectKey);
|
public AjaxResult deleteFile(@RequestParam("objectKey") String objectKey);
|
||||||
|
|
||||||
|
@GetMapping("/getFullFileUrl")
|
||||||
|
public String getFullFileUrl(@RequestParam("fileUrl") String fileUrl);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,11 @@ public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileServ
|
||||||
public AjaxResult deleteFile(String objectKey) {
|
public AjaxResult deleteFile(String objectKey) {
|
||||||
return AjaxResult.error("删除文件失败:" + throwable.getMessage());
|
return AjaxResult.error("删除文件失败:" + throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullFileUrl(String fileUrl) {
|
||||||
|
return "获取文件完整路径失败";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,11 @@ public class SysFileController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getFullFileUrl")
|
||||||
|
public String getFullFileUrl(@RequestParam String fileUrl) throws Exception {
|
||||||
|
return sysFileService.getFullFileUrl(fileUrl);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件删除
|
* 文件删除
|
||||||
* 从各个存储平台删除文件
|
* 从各个存储平台删除文件
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ public interface ISysFileService
|
||||||
*/
|
*/
|
||||||
public void downloadFile(HttpServletResponse response, String urlStr) throws Exception;
|
public void downloadFile(HttpServletResponse response, String urlStr) throws Exception;
|
||||||
|
|
||||||
|
public String getFullFileUrl(String urlStr) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,11 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullFileUrl(String urlStr) throws Exception {
|
||||||
|
return urlStr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,11 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
||||||
FileDownloadUtils.downloadFile(response, urlStr);
|
FileDownloadUtils.downloadFile(response, urlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullFileUrl(String urlStr) throws Exception {
|
||||||
|
return urlStr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,11 @@ public class MinioServiceImpl implements ISysFileService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullFileUrl(String urlStr) throws Exception {
|
||||||
|
return minioUtil.getFullFileUrl(urlStr);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,11 @@ public class MongodbServiceImpl implements ISysFileService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullFileUrl(String urlStr) throws Exception {
|
||||||
|
return urlStr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,11 @@ public class ObsServiceImpl implements ISysFileService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullFileUrl(String urlStr) throws Exception {
|
||||||
|
return urlStr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,11 @@ public class OssServiceImpl implements ISysFileService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullFileUrl(String urlStr) throws Exception {
|
||||||
|
return urlStr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
* 从给定的URL下载文件并将其保存到指定的目标位置。
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.bonus.file.utils;
|
package com.bonus.file.utils;
|
||||||
|
|
||||||
|
import com.bonus.common.core.utils.StringUtils;
|
||||||
import com.bonus.file.config.MinioConfig;
|
import com.bonus.file.config.MinioConfig;
|
||||||
import com.bonus.file.entity.FileDetails;
|
import com.bonus.file.entity.FileDetails;
|
||||||
import com.bonus.system.api.domain.SysFile;
|
import com.bonus.system.api.domain.SysFile;
|
||||||
|
|
@ -298,6 +299,18 @@ public class MinioUtil {
|
||||||
return getFileUrl(bucketName, objectName, 604800);
|
return getFileUrl(bucketName, objectName, 604800);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFullFileUrl(String fileUrl) throws Exception {
|
||||||
|
if (StringUtils.isNotEmpty(fileUrl)){
|
||||||
|
if (fileUrl.startsWith("http://")) {
|
||||||
|
return fileUrl;
|
||||||
|
} else {
|
||||||
|
return minioConfig.getEndpoint() + "/" + minioConfig.getBucketName() + "/" + fileUrl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除指定的对象
|
* 删除指定的对象
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ public class SysProfileController extends BaseController {
|
||||||
try {
|
try {
|
||||||
String username = SecurityUtils.getUsername();
|
String username = SecurityUtils.getUsername();
|
||||||
SysUser user = userService.selectUserByUserName(username);
|
SysUser user = userService.selectUserByUserName(username);
|
||||||
|
user.setAvatar(remoteFileService.getFullFileUrl(user.getAvatar()));
|
||||||
AjaxResult ajax = AjaxResult.success(user);
|
AjaxResult ajax = AjaxResult.success(user);
|
||||||
ajax.put("roleGroup", userService.selectUserRoleGroup(username));
|
ajax.put("roleGroup", userService.selectUserRoleGroup(username));
|
||||||
ajax.put("postGroup", userService.selectUserPostGroup(username));
|
ajax.put("postGroup", userService.selectUserPostGroup(username));
|
||||||
|
|
@ -152,9 +153,9 @@ public class SysProfileController extends BaseController {
|
||||||
String url = fileResult.getDataAs(SysFile.class).getUrl();
|
String url = fileResult.getDataAs(SysFile.class).getUrl();
|
||||||
if (userService.updateUserAvatar(loginUser.getUsername(), url)) {
|
if (userService.updateUserAvatar(loginUser.getUsername(), url)) {
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
ajax.put("imgUrl", url);
|
ajax.put("imgUrl", remoteFileService.getFullFileUrl(url));
|
||||||
// 更新缓存用户头像
|
// 更新缓存用户头像
|
||||||
loginUser.getSysUser().setAvatar(url);
|
loginUser.getSysUser().setAvatar(remoteFileService.getFullFileUrl(url));
|
||||||
tokenService.setLoginUser(loginUser);
|
tokenService.setLoginUser(loginUser);
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import com.bonus.common.security.annotation.PreventRepeatSubmit;
|
||||||
import com.bonus.common.security.annotation.RequiresPermissions;
|
import com.bonus.common.security.annotation.RequiresPermissions;
|
||||||
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
|
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
|
||||||
import com.bonus.common.security.utils.SecurityUtils;
|
import com.bonus.common.security.utils.SecurityUtils;
|
||||||
|
import com.bonus.system.api.RemoteFileService;
|
||||||
import com.bonus.system.api.domain.SysDept;
|
import com.bonus.system.api.domain.SysDept;
|
||||||
import com.bonus.system.api.domain.SysRole;
|
import com.bonus.system.api.domain.SysRole;
|
||||||
import com.bonus.system.api.domain.SysUser;
|
import com.bonus.system.api.domain.SysUser;
|
||||||
|
|
@ -73,6 +74,9 @@ public class SysUserController extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysLogService sysLogService;
|
private ISysLogService sysLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RemoteFileService remoteFileService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户列表
|
* 获取用户列表
|
||||||
*/
|
*/
|
||||||
|
|
@ -234,6 +238,8 @@ public class SysUserController extends BaseController {
|
||||||
public AjaxResult getInfo() {
|
public AjaxResult getInfo() {
|
||||||
try {
|
try {
|
||||||
SysUser user = userService.selectUserById(SecurityUtils.getUserId());
|
SysUser user = userService.selectUserById(SecurityUtils.getUserId());
|
||||||
|
user.setAvatar(remoteFileService.getFullFileUrl(user.getAvatar()));
|
||||||
|
user.setPhotoUrl(remoteFileService.getFullFileUrl(user.getPhotoUrl()));
|
||||||
user.setPassword(null);
|
user.setPassword(null);
|
||||||
// 角色集合
|
// 角色集合
|
||||||
Set<String> roles = permissionService.getRolePermission(user);
|
Set<String> roles = permissionService.getRolePermission(user);
|
||||||
|
|
@ -265,6 +271,7 @@ public class SysUserController extends BaseController {
|
||||||
if (StringUtils.isNotNull(userId)) {
|
if (StringUtils.isNotNull(userId)) {
|
||||||
SysUser sysUser = userService.selectUserById(userId);
|
SysUser sysUser = userService.selectUserById(userId);
|
||||||
sysUser.setPassword(null);
|
sysUser.setPassword(null);
|
||||||
|
sysUser.setPhotoUrl(remoteFileService.getFullFileUrl(sysUser.getPhotoUrl()));
|
||||||
ajax.put(AjaxResult.DATA_TAG, sysUser);
|
ajax.put(AjaxResult.DATA_TAG, sysUser);
|
||||||
ajax.put("postIds", postService.selectPostListByUserId(userId));
|
ajax.put("postIds", postService.selectPostListByUserId(userId));
|
||||||
ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
|
ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue