Skip to content

Commit

Permalink
Optimization of upload file interface in FsRestfulApi.java (#4357)
Browse files Browse the repository at this point in the history
  • Loading branch information
binbinCheng committed Mar 14, 2023
1 parent 2c5abd7 commit 1d9c9a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion linkis-dist/package/conf/linkis.properties
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ linkis.session.redis.port=6379
# redis password
linkis.session.redis.password=test123
# redis sso switch
linkis.session.redis.cache.enabled=false
linkis.session.redis.cache.enabled=false
wds.linkis.workspace.filesystem.owner.check=true
wds.linkis.workspace.filesystem.path.check=true
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ public Message upload(
FileSystem fileSystem = fsService.getFileSystem(userName, fsPath);
for (MultipartFile p : files) {
String fileName = p.getOriginalFilename();
WorkspaceUtil.charCheckFileName(fileName);
FsPath fsPathNew = new FsPath(fsPath.getPath() + "/" + fileName);
WorkspaceUtil.fileAndDirNameSpecialCharCheck(fsPathNew.getPath());
fileSystem.createNewFile(fsPathNew);
try (InputStream is = p.getInputStream();
OutputStream outputStream = fileSystem.write(fsPathNew, true)) {
Expand Down Expand Up @@ -442,7 +442,7 @@ public void download(
// downloaded(判断目录,目录不能下载)
FileSystem fileSystem = fsService.getFileSystem(userName, fsPath);
if (!fileSystem.exists(fsPath)) {
throw WorkspaceExceptionManager.createException(8011, path);
throw WorkspaceExceptionManager.createException(80011, path);
}
inputStream = fileSystem.read(fsPath);
byte[] buffer = new byte[1024];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,18 @@ public static String suffixTuning(String path) {

public static void fileAndDirNameSpecialCharCheck(String path) throws WorkSpaceException {
String name = new File(path).getName();
int i = name.lastIndexOf(".");
charCheckFileName(name);
}

public static void charCheckFileName(String fileName) throws WorkSpaceException {
int i = fileName.lastIndexOf(".");
if (i != -1) {
name = name.substring(0, i);
fileName = fileName.substring(0, i);
}
// Only support numbers, uppercase letters, underscores, Chinese(只支持数字,字母大小写,下划线,中文)
String specialRegEx = "^[\\w\\u4e00-\\u9fa5]{1,200}$";
Pattern specialPattern = Pattern.compile(specialRegEx);
if (!specialPattern.matcher(name).find()) {
if (!specialPattern.matcher(fileName).find()) {
WorkspaceExceptionManager.createException(80028);
}
}
Expand Down

0 comments on commit 1d9c9a3

Please sign in to comment.