Skip to content

Commit

Permalink
asset.php: when param list is supplied, return list of files
Browse files Browse the repository at this point in the history
  • Loading branch information
plepe committed Feb 5, 2018
1 parent 757d7d7 commit eb19615
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions asset.php
Expand Up @@ -19,16 +19,29 @@
$_REQUEST['dir'] = '.';
}

$tmpfile = tempnam('/tmp', 'osb-asset-');
$contents = $repo->file_get_contents("{$_REQUEST['dir']}/{$_REQUEST['file']}");
if (array_key_exists('list', $_REQUEST)) {
$contents = array();
foreach ($repo->scandir($_REQUEST['dir']) as $f) {
if (substr($f, 0, 1) !== '.') {
$contents[] = array('name' => $f);
}
}

if ($contents === false) {
Header("HTTP/1.1 401 Permission denied");
exit(0);
$mime_type = 'application/json; charset=utf-8';
$contents = json_encode($contents);
}
else {
$tmpfile = tempnam('/tmp', 'osb-asset-');
$contents = $repo->file_get_contents("{$_REQUEST['dir']}/{$_REQUEST['file']}");

if ($contents === false) {
Header("HTTP/1.1 401 Permission denied");
exit(0);
}

file_put_contents($tmpfile, $contents);
$mime_type = mime_content_type($tmpfile);
file_put_contents($tmpfile, $contents);
$mime_type = mime_content_type($tmpfile);
}

Header("Content-Type: {$mime_type}; charset=utf-8");
print $contents;

0 comments on commit eb19615

Please sign in to comment.