public function __construct($env) { utils::log('WEB Extract Application running'); parent::__construct($env); $app = $this; // Override these values in resources/config/prod.php file //$app ['var_dir'] =$this->rootDir . '/var' ; //$app ['locale'] ='fr' ; //$app ['http_cache.cache_dir'] =$app->share (function (Application $app) { // return ($app ['var_dir'] . '/http') ; //}) ; //$app ['monolog.options'] =[ // 'monolog.logfile' => $app['var_dir'].'/logs/app.log', // 'monolog.name' => 'app', // 'monolog.level' => 300, // = Logger::WARNING //] ; //$app ['security.users'] =array( 'alice' => array ( 'ROLE_USER', 'password' ) ) ; lmv::tokenObject(); //$app->register (new HttpCacheServiceProvider ()) ; $app->register(new SessionServiceProvider()); //$app->register (new ValidatorServiceProvider ()) ; //$app->register (new FormServiceProvider ()) ; //$app->register (new UrlGeneratorServiceProvider ()) ; //$app->register (new DoctrineServiceProvider ()) ; //$app->register (new SecurityServiceProvider (), array ( // 'security.firewalls' => array ( // 'admin' => array ( // 'pattern' => '^/', // 'form' => array ( // 'login_path' => '/login', // ), // 'logout' => true, // 'anonymous' => true, // 'users' => $app ['security.users'], // ), // ), //)) ; //$app ['security.encoder.digest'] =$app->share (function ($app) { // return (new PlaintextPasswordEncoder ()) ; //}) ; //$app ['security.utils'] =$app->share (function ($app) { // return (new AuthenticationUtils ($app ['request_stack'])) ; //}) ; //$app->register (new TranslationServiceProvider ()) ; //$app ['translator'] =$app->share($app->extend ('translator', function ($translator, $app) { // $translator->addLoader ('yaml', new YamlFileLoader ()) ; // $translator->addResource ('yaml', $this->rootDir.'/resources/translations/fr.yml', 'fr') ; // return ($translator) ; //})) ; //$app->register (new MonologServiceProvider (), $app ['monolog.options']) ; $app->register(new TwigServiceProvider(), array('twig.path' => array($this->rootDir . '/views'))); //$app ['twig'] = $app->share ($app->extend ('twig', function ($twig, $app) { // $twig->addFunction (new \Twig_SimpleFunction ('asset', function ($asset) use ($app) { // $base = $app['request_stack']->getCurrentRequest ()->getBasePath () ; // return (sprintf ($base . '/' . $asset, ltrim ($asset, '/'))) ; // })) ; // return ($twig) ; //})) ; //$app->mount ('', new ControllerProvider ()) ; $app->mount('/api', new LmvFile()); $app->mount('/api/projects', new LmvProjects()); $app->mount('/api/results', new LmvResults()); $app->get('/', function () use($app) { return $app['twig']->render('index.html.twig', []); }); $app->get('/explore/{identifier}', function ($identifier) use($app) { $bucket = lmv::getDefaultBucket(); $zipExist = $app->extractDir("/{$identifier}.zip", true) !== false; $path = $app->dataDir("/{$identifier}.resultdb.json"); $content = file_get_contents($path); if ($content === false) { $app->abort(Response::HTTP_NOT_ACCEPTABLE, "DB record not present"); return; } $data = json_decode($content); return $app['twig']->render('explore.twig', ['bucket' => $bucket, 'extracted' => $zipExist ? 'true' : 'false', 'urn' => $data->urn, 'accessToken' => lmv::bearer(), 'root' => $identifier]); }); }
public function thumbnail($urn, $width = null, $height = null) { $encodedURN = base64_encode($urn); $config = lmv::config(); $endpoint = sprintf($config['getThumbnailsEndPoint'], $encodedURN); $query = []; if ($width !== null) { $query['width'] = $width; } if ($height !== null) { $query['height'] = $height; } Unirest\Request::verifyPeer(false); $response = Unirest\Request::get($endpoint, array('Authorization' => 'Bearer ' . lmv::bearer()), $query); if ($response->code != lmv::HTTP_OK) { utils::log('thumbnail fail ' . $response->code); return null; } return $response->raw_body; }
protected function DownloadFileAndSaveItemToDisk($item) { try { Unirest\Request::verifyPeer(false); $response = Unirest\Request::get($item, array('Authorization' => 'Bearer ' . lmv::bearer()), null); //$filename =basename ($item) ; $fullpath = $this->lmv->dataDir("/{$this->identifier}/" . utils::postStr('/viewers/', $item)); $filepath = dirname($fullpath); if ($response->code != Response::HTTP_OK) { if ($response->code == Response::HTTP_NOT_FOUND || $response->code == Response::HTTP_GATEWAY_TIMEOUT) { utils::log("Error {$response->code} - {$item} <ignoring>"); utils::log("Download failed for {$fullpath}"); return (object) array('urn' => $item, 'name' => utils::postStr('/data/', $fullpath), 'size' => 0, 'dl' => 0, 'error' => $response->code); } utils::log("Download failed for {$urn}"); throw new \Exception($response->code); } $filesystem = new Filesystem(); $filesystem->mkdir($filepath); $this->mgr->dlProgressIntermediate((object) array('urn' => $item, 'name' => utils::postStr('/data/', $fullpath), 'size' => strlen($response->raw_body), 'dl' => strlen($response->raw_body))); if (file_put_contents($fullpath, $response->raw_body) === false) { throw new \Exception("file_put_contents ({$fullpath})"); } return (object) array('urn' => $item, 'name' => utils::postStr('/data/', $fullpath), 'size' => strlen($response->raw_body), 'dl' => strlen($response->raw_body)); } catch (Exception $err) { utils::log('DownloadFileAndSaveItemToDisk exception ' . $err->getMessage()); utils::log("Save to disk failed for {$item}"); throw $err; } }