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)); }
/** * Looks in the URL view for a symlink matching the provided * URL and if found, returns the mtime of the link target * * If the link points to /dev/null, we have a URL we were unable * to download before - if that symlink itself is older than 1 hour * we delete it and return 0. If the symlink is younger than hour, * we raise an exception and abort. Intended as mechanism to prevent * repeated attempts to download the same (non 200) URL in a short * time period * * @param String $bucket * @param String $url * @return array(time => int Unix timestamp (0 means not found), revalidate => (true|false), cache_age => int) */ public function getURLLastModified($bucket, $url) { $storage = new binarypool_storage($bucket); $symlink = binarypool_views::getDownloadedViewPath($bucket, $url); return $storage->getURLLastModified($url, $symlink); }