| | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.io.IORuntimeException; |
| | | import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient; |
| | | import cn.iocoder.yudao.module.infra.framework.file.core.utils.FilePathUtils; |
| | | |
| | | import java.io.File; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_PATH_INVALID; |
| | | |
| | | /** |
| | | * 本地文件客户端 |
| | |
| | | } |
| | | |
| | | private String getFilePath(String path) { |
| | | return config.getBasePath() + File.separator + path; |
| | | FilePathUtils.validatePath(path); |
| | | Path basePath = Paths.get(config.getBasePath()).toAbsolutePath().normalize(); |
| | | Path filePath = basePath.resolve(path).normalize(); |
| | | if (!filePath.startsWith(basePath)) { |
| | | throw exception(FILE_PATH_INVALID); |
| | | } |
| | | return filePath.toString(); |
| | | } |
| | | |
| | | } |