Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization of upload file interface in FsRestfulApi.java #4357

Merged
merged 5 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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