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;
 }
Exemplo n.º 2
0
 public function Execute($db, $asset)
 {
     $assets = new SQLAssets($db);
     //$assets = new MongoAssets($db);
     if ($assets->RemoveAsset($asset->ID)) {
         header("HTTP/1.1 204 No Content");
         exit;
     } else {
         header("HTTP/1.1 404 Not Found");
         echo 'Asset not found';
         exit;
     }
 }
 public function Execute($db, $params)
 {
     $asset = null;
     $assetID = null;
     $response = array();
     if (isset($params["EncodedData"]) && isset($params["ContentType"])) {
         log_message('debug', "xAddAsset asset");
         // Build the asset structure from the parameters
         $asset = new Asset();
         if (!isset($params["AssetID"]) || !UUID::TryParse($params["AssetID"], $asset->ID)) {
             $asset->ID = UUID::Random();
         }
         if (!isset($params["CreatorID"]) || !UUID::TryParse($params["CreatorID"], $asset->CreatorID)) {
             $asset->CreatorID = UUID::Zero;
         }
         $asset->Data = base64_decode($params["EncodedData"]);
         $asset->SHA256 = hash("sha256", $asset->Data);
         $asset->ContentLength = strlen($asset->Data);
         $asset->ContentType = $params["ContentType"];
         $asset->Temporary = !empty($params["Temporary"]);
         $asset->Public = !empty($params["Public"]);
         $assets = new SQLAssets($db);
         $created = false;
         if ($assets->AddAsset($asset, $created)) {
             $response['Success'] = TRUE;
             $response['AssetID'] = $asset->ID;
             $response['Status'] = $created ? "created" : "updated";
         } else {
             log_message('warn', 'failed to create asset');
             $response['Success'] = FALSE;
             $response['Message'] = 'failed to create the asset';
         }
     } else {
         $response['Success'] = FALSE;
         $response['Message'] = 'missing required parameters';
     }
     log_message('debug', sprintf("[AddAsset] result %s", json_encode($response)));
     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;
     }
 }
Exemplo n.º 5
0
 public function Execute($db, $asset)
 {
     $assets = new SQLAssets($db);
     //$assets = new MongoAssets($db);
     $created = false;
     if ($assets->AddAsset($asset, $created)) {
         if ($created) {
             $status = "Created";
         } else {
             $status = "Updated";
         }
         log_message('debug', "AddClass Succesfully {$status} " . $asset->ID);
         header("Content-Type: application/json", true);
         echo '{ "Success": true, "AssetID": "' . $asset->ID . '", "Status": "' . $status . '" }';
         exit;
     } else {
         header("Content-Type: application/json", true);
         echo '{ "Message": "Unable to store asset" }';
         exit;
     }
 }
 public function Execute($db, $params)
 {
     $response = array();
     $assetID = null;
     if (!isset($params["AssetID"]) || !UUID::TryParse($params["AssetID"], $assetID)) {
         $response['Success'] = FALSE;
         $response['Message'] = 'missing required parameters';
     } else {
         $assets = new SQLAssets($db);
         //$assets = new MongoAssets($db);
         //$assets = new FSAssets($db);
         if ($assets->RemoveAsset($assetID)) {
             $response['Success'] = TRUE;
         } else {
             $response['Success'] = FALSE;
             $response['Message'] = 'failed to remove the asset';
         }
     }
     header("Content-Type: application/json", true);
     echo json_encode($response);
     exit;
 }