Skip to content

Commit

Permalink
Require the size parameter. Optional params are confusing. And be
Browse files Browse the repository at this point in the history
robust in the face of a missing data file (movies and albums lack
resize, albums lack full size, some albums don't have a thumb if they
have no contents, etc)
  • Loading branch information
bharat committed Aug 8, 2010
1 parent cc43c37 commit b7700d1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions modules/gallery/helpers/data_rest.php
Expand Up @@ -23,7 +23,11 @@ static function get($request) {
access::required("view", $item);

$p = $request->params;
switch (isset($p->size) ? $p->size : "full") {
if (!isset($p->size) || !in_array($p->size, array("thumb", "resize", "full"))) {
throw new Rest_Exception("Bad Request", 400, array("errors" => array("size" => "invalid")));
}

switch ($p->size) {
case "thumb":
$entity = array(
"width" => $item->thumb_width,
Expand All @@ -38,7 +42,6 @@ static function get($request) {
"path" => $item->resize_path());
break;

default:
case "full":
$entity = array(
"width" => $item->width,
Expand All @@ -47,8 +50,13 @@ static function get($request) {
break;
}

$entity["size"] = filesize($entity["path"]);
$entity["contents"] = file_get_contents($entity["path"]);
if (file_exists($entity["path"]) && is_file($entity["path"])) {
$entity["size"] = filesize($entity["path"]);
$entity["contents"] = file_get_contents($entity["path"]);
} else {
$entity["size"] = null;
$entity["contents"] = null;
}
unset($entity["path"]);

$result = array(
Expand Down

0 comments on commit b7700d1

Please sign in to comment.