protected function touch($bucket, $uri) { $storage = new binarypool_storage($bucket); $assetFile = $uri; if (!$storage->isFile($assetFile)) { $assetFile .= '/index.xml'; if (!$storage->isFile($assetFile)) { return false; } } // Get TTL from request $buckets = binarypool_config::getBuckets(); $ttl = $buckets[$bucket]['ttl']; if ($this->request->getParam('TTL')) { $newttl = intval($this->request->getParam('TTL')); if ($newttl <= $ttl) { // Don't allow higher TTL than bucket configuration $ttl = $newttl; } } // Set TTL $oldAsset = $storage->getAssetObject($assetFile); $asset = $storage->getAssetObject($assetFile); $asset->setExpiry(time() + $ttl * 24 * 60 * 60); $storage->saveAsset($asset, $assetFile); // Update views binarypool_views::updated($bucket, $assetFile, $oldAsset); $this->setResponseCode(204); return true; }
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)); }
/** * Checks if the asset file is an expired resource. */ public static function isExpired($bucket, $asset) { $storage = new binarypool_storage($bucket); $obj = $storage->getAssetObject($asset); if ($obj->getExpiry() > time()) { // Item expires in the future return false; } // Check callbacks foreach ($obj->getCallbacks() as $callback) { $status = self::getCallbackOpinion($callback); if ($status === FALSE) { // Permission not granted return false; } } return true; }
protected function upload($bucket) { $this->checkInput(); // Get params $type = $this->request->getParam('Type'); $callback = $this->request->getParam('Callback', ''); $files = $this->getFiles(); $url = $this->request->getParam('URL'); $created = true; $storage = new binarypool_storage($bucket); // 304 not modified if (0 == count($files) && !empty($url)) { $symlink = binarypool_views::getDownloadedViewPath($bucket, $url); $asset = $storage->getAssetForLink($symlink); $this->log->info("Unmodified file %s", $asset); $created = false; } else { // Save file $asset = $storage->save($type, $files); $this->log->info("Created file %s", $asset); } foreach ($files as $rendition => $file) { unlink($file['file']); } if ($callback !== '') { $storage->addCallback($asset, $callback); } $metadata = array(); $metadata['URL'] = $url; if ($created) { binarypool_views::created($bucket, $asset, $metadata); } else { $assetObj = $storage->getAssetObject($asset); binarypool_views::updated($bucket, $asset, $assetObj, $metadata); } $this->setResponseCode(201); $this->response->setHeader('Location', $asset); $this->response->setHeader('X-Asset', $asset); $xml = "<status method='post'><asset>" . htmlspecialchars($asset) . "</asset></status>"; array_push($this->data, new api_model_xml($xml)); }
/** * Load the asset file from storage. */ function testLoadAssetFileFromStorage() { $this->testAssetWithRendition90x90(); $storage = new binarypool_storage('test'); $basepath = 'test/somehashhere/'; $basepathAbs = binarypool_config::getRoot() . $basepath; $asset = $storage->getAssetObject($basepath . 'index.xml'); $this->assertEqual('test/somehashhere/', $asset->getBasePath()); $this->assertEqual($basepathAbs . 'vw_golf.jpg', $asset->getOriginal()); $this->assertEqual($basepathAbs . 'resultlist.jpg', $asset->getRendition('resultlist')); $this->assertEqual(array('resultlist' => $basepathAbs . 'resultlist.jpg'), $asset->getRenditions()); $this->assertEqual('096dfa489bc3f21df56eded2143843f135ae967e', $asset->getHash()); }