Skip to content

Commit 01e0fbf

Browse files
committed
1. feat: optimize folder operation prompt messages
2. feat: check field type for multiform data parsing
1 parent f6bcfd5 commit 01e0fbf

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

server/api-service/openblocks-sdk/src/main/java/com/openblocks/sdk/exception/BizError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public enum BizError {
130130
CURRENT_EDITION_NOT_SUPPORT_FOR_THIS_FEATURE(400, 6252),
131131

132132
// folder 6301 - 6350
133-
FOLDER_DELETE_NO_PERMISSION(500, 6301),
133+
FOLDER_OPERATE_NO_PERMISSION(500, 6301),
134134
FOLDER_NOT_EXIST(500, 6302),
135135
FOLDER_NAME_CONFLICT(500, 6303),
136136
ILLEGAL_FOLDER_PERMISSION_ID(500, 6304),

server/api-service/openblocks-sdk/src/main/java/com/openblocks/sdk/plugin/restapi/DataUtils.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.google.common.collect.Streams;
4646
import com.google.gson.JsonSyntaxException;
4747
import com.openblocks.sdk.exception.PluginException;
48+
import com.openblocks.sdk.exception.ServerException;
4849
import com.openblocks.sdk.models.Property;
4950
import com.openblocks.sdk.models.RestBodyFormFileData;
5051
import com.openblocks.sdk.util.ExceptionUtils;
@@ -155,11 +156,8 @@ public String parseFormData(List<Property> bodyFormData, boolean encodeParamsTog
155156
return;
156157
}
157158

158-
try {
159-
populateMultiformFileData(bodyBuilder, property);
160-
} catch (Exception e) {
161-
throw ExceptionUtils.wrapException(DATASOURCE_ARGUMENT_ERROR, "CONTENT_PARSE_ERROR", e);
162-
}
159+
populateMultiformFileData(bodyBuilder, property);
160+
163161
});
164162

165163
return BodyInserters.fromMultipartData(bodyBuilder.build())
@@ -172,7 +170,12 @@ private void populateMultiformFileData(MultipartBodyBuilder bodyBuilder, Propert
172170
.forEach(multipartFormData -> {
173171
String name = multipartFormData.getName();
174172
String data = multipartFormData.getData();
175-
byte[] decodedValue = Base64.getDecoder().decode(data);
173+
byte[] decodedValue;
174+
try {
175+
decodedValue = Base64.getDecoder().decode(data);
176+
} catch (Exception e) {
177+
throw ExceptionUtils.wrapException(DATASOURCE_ARGUMENT_ERROR, "FAIL_TO_PARSE_BASE64_STRING", e);
178+
}
176179
bodyBuilder.part(property.getKey(), decodedValue)
177180
.filename(name);
178181
});
@@ -182,7 +185,7 @@ private List<MultipartFormData> parseMultipartFormDataList(Property property) {
182185
if (property instanceof RestBodyFormFileData restBodyFormFileData) {
183186
return restBodyFormFileData.getFileData();
184187
}
185-
throw new PluginException(DATASOURCE_ARGUMENT_ERROR, "CONTENT_PARSE_ERROR");
188+
throw new ServerException("invalid data type for MultipartForm");
186189
}
187190

188191
public static List<MultipartFormData> convertToMultiformFileValue(String fileValue, Map<String, Object> paramMap) {
@@ -198,7 +201,8 @@ public static List<MultipartFormData> convertToMultiformFileValue(String fileVal
198201
.map(DataUtils::parseMultipartFormData)
199202
.toList();
200203
}
201-
} catch (Throwable ignored) {
204+
} catch (Throwable e) {
205+
throw ExceptionUtils.wrapException(DATASOURCE_ARGUMENT_ERROR, "CONTENT_PARSE_ERROR", e);
202206
// ignore
203207
}
204208
throw new PluginException(DATASOURCE_ARGUMENT_ERROR, "CONTENT_PARSE_ERROR");
@@ -207,8 +211,17 @@ public static List<MultipartFormData> convertToMultiformFileValue(String fileVal
207211
@Nonnull
208212
private static MultipartFormData parseMultipartFormData(JsonNode jsonObject) {
209213
MultipartFormData result = new MultipartFormData();
210-
result.setData(jsonObject.get("data").asText());
211-
result.setName(jsonObject.get("name").asText());
214+
JsonNode data = jsonObject.get("data");
215+
if (!data.isTextual()) {
216+
throw new PluginException(DATASOURCE_ARGUMENT_ERROR, "MULTIFORM_DATA_IS_NOT_STRING");
217+
}
218+
result.setData(data.asText());
219+
220+
JsonNode name = jsonObject.get("name");
221+
if (!name.isTextual()) {
222+
throw new PluginException(DATASOURCE_ARGUMENT_ERROR, "MULTIFORM_NAME_IS_NOT_STRING");
223+
}
224+
result.setName(name.asText());
212225
return result;
213226
}
214227

server/api-service/openblocks-sdk/src/main/resources/locale_en.properties

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ EXCEED_QUERY_RESPONSE_SIZE=Sorry, it exceeds query response limit size, please c
5959
LIBRARY_QUERY_AND_ORG_NOT_MATCH=Query library does not match the workspace.
6060
LIBRARY_QUERY_NOT_FOUND=Sorry, query library has no such query, please check again.
6161
INVALID_USER_STATUS=Sorry, the user status is illegal: {0}.
62-
FOLDER_DELETE_NO_PERMISSION=Oops! It appears you don''t have the permission to delete the folder.
62+
FOLDER_OPERATE_NO_PERMISSION=Oops! It appears you don''t have operation permissions of the folder.
6363
FOLDER_NOT_EXIST=The folder does not exist, please check again.
6464
FOLDER_NAME_CONFLICT=Sorry, there is already a folder with the same name as the folder name you specified, please use a different name.
6565
INVALID_PARAMETER_PLZ_CHECK=Sorry, an invalid parameter was passed, please check: {0}.
@@ -176,7 +176,10 @@ INVALID_RESTAPI=Failed to parse REST API query configuration.
176176
GET_MONGODB_STRUCTURE_ERROR=Failed to get MongoDB structure.
177177
MONGODB_URI_EMPTY=MongoDB''s connection URI is empty.
178178
MONGODB_URI_EXTRACT_ERROR=Failed to resolve MongoDB connection URI.
179-
CONTENT_PARSE_ERROR=Fail to resolve multipart data, requiring array or object type.
179+
CONTENT_PARSE_ERROR=Resolve upload data failed, it requires format {data:base64 string, name:string} or an array of it
180+
MULTIFORM_DATA_IS_NOT_STRING=Resolve upload data failed, data field is not a valid base64 string
181+
MULTIFORM_NAME_IS_NOT_STRING=Resolve upload data failed, name field is not a valid string
182+
FAIL_TO_PARSE_BASE64_STRING=Fail to decode data in Base64 format: {0}
180183
PS_BIND_ERROR=PreparedStatement binding exception: {0}, parameter type {1}.
181184
MONGODB_EXECUTE_ERROR=MongoDB query execution error, MongoDB status code: {0}.
182185
REQUEST_ERROR=Request failed: {0} {1}.

server/api-service/openblocks-server/src/main/java/com/openblocks/api/home/FolderApiService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.openblocks.api.home;
22

33
import static com.openblocks.infra.util.MonoUtils.emptyIfNull;
4-
import static com.openblocks.sdk.exception.BizError.FOLDER_DELETE_NO_PERMISSION;
4+
import static com.openblocks.sdk.exception.BizError.FOLDER_OPERATE_NO_PERMISSION;
55
import static com.openblocks.sdk.exception.BizError.FOLDER_NOT_EXIST;
66
import static com.openblocks.sdk.exception.BizError.ILLEGAL_FOLDER_PERMISSION_ID;
77
import static com.openblocks.sdk.util.ExceptionUtils.ofError;
@@ -341,7 +341,7 @@ private Mono<OrgMember> checkManagePermission(String folderId) {
341341
}
342342
return isCreator(folderId)
343343
.flatMap(isCreator -> isCreator ? Mono.just(orgMember)
344-
: ofError(FOLDER_DELETE_NO_PERMISSION, "FOLDER_DELETE_NO_PERMISSION"));
344+
: ofError(FOLDER_OPERATE_NO_PERMISSION, "FOLDER_OPERATE_NO_PERMISSION"));
345345
});
346346
}
347347

0 commit comments

Comments
 (0)