protected function execute() { $uri = $this->request->getPath(); $storage = new binarypool_storage($this->bucket); // Access control if (!$storage->fileExists($uri)) { throw new binarypool_exception(115, 404, "File not found: " . $uri); } if (!$storage->isDir($uri)) { throw new binarypool_exception(115, 404, "File not found: " . $uri); } // List all assets matching the view $xml = '<status method="view">'; $xml .= '<bucket>' . htmlspecialchars($this->bucket) . '</bucket>'; // Remove leading slash and bucket name $dir = substr($uri, 2 + strlen($this->bucket)); $files = $storage->listDir($dir); foreach ($files as $file) { $asset = $storage->getAssetObject($file); $xml .= '<file id="' . htmlspecialchars($asset->getHash()) . '">'; $xml .= htmlspecialchars($asset->getBasePath()); $xml .= '</file>'; } $xml .= '</status>'; array_push($this->data, new api_model_xml($xml)); }
/** * Get the path from the URI and implement access control. */ protected function getPath() { $uri = $this->getUri(); $storage = new binarypool_storage($this->bucket); // Access control if (!$storage->fileExists($uri)) { throw new binarypool_exception(115, 404, "File not found: " . $uri); } if ($storage->isDir($uri)) { $uri .= '/index.xml'; } if (!$storage->isFile($uri)) { throw new binarypool_exception(115, 404, "File not found: " . $uri); } return ltrim($uri, '/'); }
protected function execute() { $hash = $this->route['hash']; $uri = $this->request->getPath(); $storage = new binarypool_storage($this->bucket); $asset = $storage->getAssetBySha1($hash); if (!$storage->fileExists($asset)) { throw new binarypool_exception(115, 404, "File does not exist: {$uri}"); } $this->setResponseCode(302); $this->response->setHeader('X-Asset', $asset); $this->response->setHeader('Content-Type', 'text/xml'); $this->response->setContentLengthOutput(false); $storage->sendFile($asset); $this->response->send(); $this->ignoreView = true; }