public function Execute($db, $params)
 {
     $asset = null;
     $assetID = null;
     if (isset($params["ID"]) && UUID::TryParse($params["ID"], $assetID)) {
         log_message('debug', "xGetAsset asset: {$assetID}");
         $assets = new SQLAssets($db);
         $asset = $assets->GetAsset($assetID);
     }
     $response = array();
     if (!empty($asset)) {
         $response['Success'] = TRUE;
         $response['SHA256'] = $asset->SHA256;
         $response['Last-Modified'] = gmdate(DATE_RFC850, $asset->CreationDate);
         $response['CreatorID'] = $asset->CreatorID;
         $response['ContentType'] = $asset->ContentType;
         $response['ContentLength'] = $asset->ContentLength;
         $response['EncodedData'] = base64_encode($asset->Data);
         $response['Temporary'] = $asset->Temporary;
     } else {
         log_message('info', "Asset {$assetID} not found");
         $response['Success'] = FALSE;
         $response['Message'] = "Asset {$assetID} not found";
     }
     header("Content-Type: application/json", true);
     echo json_encode($response);
     exit;
 }
 public function Execute($db, $asset)
 {
     $headrequest = stripos($_SERVER['REQUEST_METHOD'], 'HEAD') !== FALSE;
     $assetid = $asset->ID;
     log_message('debug', "GetAsset asset: {$assetid}");
     $assets = new SQLAssets($db);
     //$assets = new MongoAssets($db);
     //$assets = new FSAssets($db);
     if ($headrequest) {
         $request_type = "Meta";
         $asset = $assets->GetAssetMetadata($asset->ID);
     } else {
         $request_type = "Full";
         $asset = $assets->GetAsset($asset->ID);
     }
     log_message('debug', "GetAsset requested {$request_type} information");
     if ($asset) {
         // TODO: Enforce this once we support one or more auth methods
         $asset->Public = true;
         if ($asset->Public) {
             header("ETag: " . $asset->SHA256, true);
             header("Last-Modified: " . gmdate(DATE_RFC850, $asset->CreationDate), true);
             header("X-Asset-Creator-Id: " . $asset->CreatorID, true);
             header("Content-Type: " . $asset->ContentType, true);
             header("Content-Length: " . $asset->ContentLength, true);
             if (!$headrequest) {
                 echo $asset->Data;
             }
             exit;
         } else {
             log_message('debug', "Access forbidden to private asset " . $asset->ID);
             header("HTTP/1.1 403 Forbidden");
             echo 'Access forbidden';
             exit;
         }
     } else {
         header("HTTP/1.1 404 Not Found");
         echo 'Asset not found';
         exit;
     }
 }