Make puzzle response accept no fileName and sourceCode

This commit is contained in:
Francois G 2023-04-11 18:29:27 +02:00
parent b954c518ec
commit a975b355b2

View file

@ -38,7 +38,11 @@ public class PuzzleResponse implements Response {
@Route(path = "^\\/puzzleResponse\\/([0-9]+)$", type = POST, needLogin = true)
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception{
ReceivedResponse received = new ReceivedResponse(matcher, reader);
saveSourceCode(received, databaseRepo.getPlayer(user.getId()));
if (received.getResponse() == null) {
HttpUtil.responseHeaders(writer, 400, "Access-Control-Allow-Origin: *");
return;
}
//saveSourceCode(received, databaseRepo.getPlayer(user.getId()));
JSONObject responseJSON = new JSONObject();
Puzzle currentPuzzle = databaseRepo.getPuzzle(received.getPuzzleId());
@ -87,9 +91,13 @@ class ReceivedResponse {
puzzleId = Integer.parseInt(matcher.group(1));
List<String> multiPartData = HttpUtil.readMultiPartData(reader);
this.response = multiPartData.get(0).getBytes();
this.fileName = multiPartData.get(1);
this.sourceCode = multiPartData.get(2).getBytes();
if (multiPartData != null && multiPartData.size() > 0) {
this.response = multiPartData.get(0).getBytes();
if (multiPartData.size() == 3) {
this.fileName = multiPartData.get(1);
this.sourceCode = multiPartData.get(2).getBytes();
}
}
}
public int getPuzzleId() {