public function uri(Silex\Application $app, Request $request) { $bodyParams = json_decode($request->getContent()); $uri = $bodyParams->uri; $identifier = $bodyParams->identifier; $original_filename = $bodyParams->name ?: str_replace('/.*\\//', '', str_replace('/[\\?#].*$/', '', urldecode($uri))); Unirest\Request::verifyPeer(false); //$response =Unirest\Request::head ($uri, [], null) ; $http = new \ADN\Extract\HttpRequest($uri, [], null, null); $response = $http->head(); if (!$request || $response->code != Response::HTTP_OK) { return new Response('', $response->code, ['Content-Type' => 'text/plain']); } $length = utils::findKey($response->headers, 'Content-Length') ?: -1; $data = (object) array('key' => $identifier, 'name' => $original_filename, 'uri' => $uri, 'size' => $length, 'bytesRead' => 0, 'bytesPosted' => 0); $path = utils::normalize(__DIR__ . "/../data/{$identifier}.json"); if (file_put_contents($path, json_encode($data)) === false) { return new Response('', Response::HTTP_INTERNAL_SERVER_ERROR, ['Content-Type' => 'text/plain']); } $result = utils::executeScript("/dl.php lmv:dl {$identifier}"); if ($result === false) { return new Response('', Response::HTTP_INTERNAL_SERVER_ERROR, ['Content-Type' => 'text/plain']); } $data = (object) array('status' => $identifier); return new JsonResponse($data, Response::HTTP_OK); }
public function project(Silex\Application $app, Request $request, $identifier) { $bucket = lmv::getDefaultBucket(); $lmv = new lmv($bucket); $urn = $lmv->getURN($identifier); if ($urn == '') { return new Response('', Response::HTTP_NOT_FOUND, ['Content-Type' => 'text/plain']); } $path = $app->extractDir("/{$identifier}.zip", true); if ($path) { return new Response('', Response::HTTP_OK, ['Content-Type' => 'text/plain']); } $lock = $app->dataDir("/{$identifier}.lock"); $email = $request->query->get('email'); if (realpath($lock)) { if (!empty($email)) { $data = json_decode(file_get_contents($lock)); $data->emails[] = $email; if (file_put_contents($lock, json_encode($data)) === false) { utils::log("Could not create lock file - {$lock}"); } } return new Response('', Response::HTTP_OK, ['Content-Type' => 'text/plain']); } else { $list = !empty($email) ? [$email] : []; $data = (object) array('progress' => 0, 'emails' => $list); if (file_put_contents($lock, json_encode($data)) === false) { utils::log("Could not create lock file - {$lock}"); } } $result = utils::executeScript("/extract.php lmv:extractor {$identifier}", true); if ($result === false) { return new Response('', Response::HTTP_INTERNAL_SERVER_ERROR, ['Content-Type' => 'text/plain']); } return new Response('ok', Response::HTTP_OK, ['Content-Type' => 'text/plain']); }
public function submitProject(Silex\Application $app, Request $request) { $bucket = lmv::getDefaultBucket(); $policy = 'transient'; $connections = json_decode($request->getContent()); utils::log("master: {$connections->uniqueIdentifier}"); // Save parameters for the translate process $path = $app->dataDir("/{$connections->uniqueIdentifier}.dependencies.json"); if (file_put_contents($path, json_encode($connections)) === false) { utils::log('ERROR: project dependencies not saved :('); return new Response('', Response::HTTP_NOT_FOUND, ['Content-Type' => 'text/plain']); } $result = utils::executeScript("/translate.php lmv:translator {$connections->uniqueIdentifier}", true); if ($result === false) { return new Response('', Response::HTTP_INTERNAL_SERVER_ERROR, ['Content-Type' => 'text/plain']); } // We submitted, no clue if it was successful or if it will fail. $response = (object) array('status' => 'submitted'); return new JsonResponse($response, Response::HTTP_OK); //- 202 Accepted }