Skip to content

Commit feda6a1

Browse files
committed
Changed compileAction so that it can handle request from the codebender website and other clients as well.
1 parent f80495b commit feda6a1

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

Symfony/src/Codebender/ApiBundle/Controller/DefaultController.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,55 @@ public function compileAction($auth_key, $version)
3333

3434
if ($auth_key !== $this->container->getParameter('auth_key'))
3535
{
36-
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid authorization key.")));
36+
return new Response(json_encode(array("success" => false, "message" => "Invalid authorization key.")));
3737
}
3838

3939
if ($version !== $this->container->getParameter('version'))
4040
{
41-
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid api version.")));
41+
return new Response(json_encode(array("success" => false, "message" => "Invalid api version.")));
4242
}
4343

44+
$request = $this->getRequest()->getContent();
4445
if (empty($request))
4546
{
46-
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid input.")));
47+
return new Response(json_encode(array("success" => false, "message" => "Invalid input.")));
4748
}
4849

49-
$request = $this->getRequest()->getContent();
50-
5150
$contents = json_decode($request, true);
5251

5352
$apihandler = $this->get('codebender_api.handler');
5453

5554
$files = $contents["files"];
5655

56+
$this->checkForUserProject($files);
57+
5758
$userlibs = array();
59+
5860
if (array_key_exists('libraries', $contents))
5961
$userlibs = $contents['libraries'];
6062

61-
$headersArr = $this->checkHeaders($files, $userlibs);
63+
$parsedLibs = $this->checkHeaders($files, $userlibs);
6264

63-
$contents['files'][] = array('filename' => 'user_null.txt', 'content' => '');
64-
$contents['files'][] = array('filename' => 'null.txt', 'content' => '');
65+
$contents["libraries"] = $parsedLibs['libraries'];
6566

66-
$contents["libraries"] = $headersArr['libraries'];
6767
$request_content = json_encode($contents);
6868

6969
// perform the actual post to the compiler
7070
$data = $apihandler->post_raw_data($this->container->getParameter('compiler'), $request_content);
7171

72-
return new Response($data);
72+
$decoded = json_decode($data, true);
73+
if ($decoded == null)
74+
{
75+
return new Response(json_encode(array("success" => false, "message"=> "Failed to get compiler response.")));
76+
}
77+
78+
if ($decoded["success"] === false && !array_key_exists("step", $decoded))
79+
$decoded["step"] = "unknown";
80+
81+
unset($parsedLibs['libraries']);
82+
$decoded['additionalCode'] = $parsedLibs;
83+
84+
return new Response(json_encode($decoded));
7385
}
7486

7587
/**

0 commit comments

Comments
 (0)