public function viewsDir($plus = '', $real = false)
 {
     if ($real) {
         return utils::realpath("{$this->rootDir}/views{$plus}");
     } else {
         return utils::normalize("{$this->rootDir}/views{$plus}");
     }
 }
 public function id(Silex\Application $app, $identifier)
 {
     $request = new \Flow\Request();
     $path = utils::realpath(__DIR__ . "/../data/{$identifier}.json");
     if ($path === false) {
         return new Response('', Response::HTTP_NOT_FOUND, ['Content-Type' => 'text/plain']);
     }
     $content = file_get_contents($path);
     $data = json_decode($content);
     $serverFile = utils::realpath($app->tmpDir("/{$data->name}"));
     if ($serverFile === false) {
         return new Response('', Response::HTTP_NOT_FOUND, ['Content-Type' => 'text/plain']);
     }
     $response = new StreamedResponse(function () use($serverFile) {
         //$file =fopen ($serverFile, "rb") ;
         //while ( !feof ($file) ) {
         //	echo fread ($file, HttpRequest::max_chunk_size) ;
         //	flush () ;
         //}
         //fclose ($file) ;
         @readfile($serverFile);
     }, Response::HTTP_OK, ['Cache-Control' => 'private', 'Content-Type' => 'application/octet-stream', 'Content-Transfer-Encoding' => 'binary', 'Content-Length' => filesize($serverFile), 'Content-Disposition' => "attachment; filename=\"{$data->name}\""]);
     //$contentDisposition =$response->headers->makeDisposition (ResponseHeaderBag::DISPOSITION_ATTACHMENT, $data->name) ;
     //$response->headers->set ('Content-Disposition', $contentDisposition) ;
     return $response;
 }
 public function details(Silex\Application $app, $identifier)
 {
     $bucket = lmv::getDefaultBucket();
     $filename = '';
     $idData = (object) [];
     $path = $app->dataDir("/{$identifier}.json");
     try {
         if (utils::realpath($path) === false) {
             throw new \Exception();
         }
         $idData = file_get_contents($path);
         $idData = json_decode($idData);
         if (isset($idData->name)) {
             $filename = $idData->name;
         } else {
             if (isset($idData->objects) && isset($idData->objects[0]->key)) {
                 $filename = $idData->objects[0]->key;
             } else {
                 throw new \Exception();
             }
         }
     } catch (Exception $ex) {
         $filename = str_replace('/^[0-9]*\\-/', '', $identifier);
         $position = strlen($filename) - 3;
         $filename = implode('', [substr($filename, 0, $position), '.', substr($filename, $position)]);
     }
     // GET /oss/{apiversion}/buckets/{bucketkey}/objects/{objectKey}/details
     // would work as well, but since we saved it locally, use the local version
     if ($path === false) {
         $response = $lmv->checkObjectDetails($filename);
         if ($response == null) {
             return new Response('', Response::HTTP_NOT_FOUND, ['Content-Type' => 'text/plain']);
         }
         return new JsonResponse($response, Response::HTTP_OK);
     } else {
         return new JsonResponse($idData, Response::HTTP_OK);
     }
 }