Removed amazon s3 signature from pypo cache file name.
Stopped pyppo from downloading amazon s3 files if it already exists in the pypo cache dir.
This commit is contained in:
parent
f775bedb49
commit
9726fb80d2
5 changed files with 45 additions and 22 deletions
|
@ -895,9 +895,11 @@ SQL;
|
|||
//row is from "file"
|
||||
$media_id = $item['file_id'];
|
||||
$storedFile = Application_Model_StoredFile::RecallById($media_id);
|
||||
$uri = $storedFile->getFilePath();
|
||||
$file = $storedFile->getPropelOrm();
|
||||
$uri = $file->getAbsoluteFilePath();
|
||||
|
||||
$object_name = null;
|
||||
if ($storedFile->getPropelOrm() instanceof CloudFile) {
|
||||
if ($file instanceof CloudFile) {
|
||||
$object_name = $storedFile->getResourceId();
|
||||
}
|
||||
$filesize = $storedFile->getFileSize();
|
||||
|
|
|
@ -491,7 +491,7 @@ SQL;
|
|||
{
|
||||
assert($this->_file);
|
||||
|
||||
return $this->_file->getAbsoluteFilePath();
|
||||
return $this->_file->getURLForTrackPreviewOrDownload();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -82,6 +82,11 @@ class CcFiles extends BaseCcFiles {
|
|||
return $info['filename'];
|
||||
}
|
||||
|
||||
public function getURLForTrackPreviewOrDownload()
|
||||
{
|
||||
return $this->getAbsoluteFilePath();
|
||||
}
|
||||
|
||||
public function getAbsoluteFilePath()
|
||||
{
|
||||
$music_dir = Application_Model_MusicDir::getDirByPK($this->getDbDirectory());
|
||||
|
|
|
@ -16,37 +16,50 @@ require_once 'Amazon_S3.php';
|
|||
class CloudFile extends BaseCloudFile
|
||||
{
|
||||
|
||||
public function getAbsoluteFilePath()
|
||||
public function getURLForTrackPreviewOrDownload()
|
||||
{
|
||||
return $this->get_s3_signed_url();
|
||||
return $this->getAbsoluteFilePath()."?".$this->getAuthenticationParams();
|
||||
}
|
||||
|
||||
private function get_s3_signed_url()
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*/
|
||||
public function getAbsoluteFilePath()
|
||||
{
|
||||
//should be longer than track length
|
||||
$expires = 120;
|
||||
$amazon_s3 = new Amazon_S3();
|
||||
$zend_s3 = $amazon_s3->getZendServiceAmazonS3();
|
||||
$resource_id = $this->getResourceId();
|
||||
$endpoint = $zend_s3->getEndpoint();
|
||||
$scheme = $endpoint->getScheme();
|
||||
$host = $endpoint->getHost();
|
||||
$s3_bucket = $amazon_s3->getBucket();
|
||||
return "$scheme://$host/$s3_bucket/".utf8_encode($resource_id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns a string of authentication paramaters to append to the cloud
|
||||
* object's URL. We need this for track preview and download because the
|
||||
* objects are privately stored on Amazon S3.
|
||||
*/
|
||||
public function getAuthenticationParams()
|
||||
{
|
||||
$expires = time()+120;
|
||||
$resource_id = $this->getResourceId();
|
||||
|
||||
$amazon_s3 = new Amazon_S3();
|
||||
$s3_bucket = $amazon_s3->getBucket();
|
||||
$s3_secret_key = $amazon_s3->getSecretKey();
|
||||
$s3_access_key = $amazon_s3->getAccessKey();
|
||||
$zend_s3 = $amazon_s3->getZendServiceAmazonS3();
|
||||
|
||||
$expires = time()+$expires;
|
||||
$string_to_sign = utf8_encode("GET\n\n\n$expires\n/$s3_bucket/$resource_id");
|
||||
// We need to urlencode the entire signature in case the hashed signature
|
||||
// has spaces. (NOTE: utf8_encode() does not work here because it turns
|
||||
// spaces into non-breaking spaces)
|
||||
$signature = urlencode(base64_encode((hash_hmac("sha1", $string_to_sign, $s3_secret_key, true))));
|
||||
|
||||
$authentication_params = "AWSAccessKeyId=$s3_access_key&Expires=$expires&Signature=$signature";
|
||||
|
||||
$endpoint = $zend_s3->getEndpoint();
|
||||
$scheme = $endpoint->getScheme();
|
||||
$host = $endpoint->getHost();
|
||||
$url = "$scheme://$host/$s3_bucket/".utf8_encode($resource_id)."?$authentication_params";
|
||||
return $url;
|
||||
return "AWSAccessKeyId=$s3_access_key&Expires=$expires&Signature=$signature";
|
||||
}
|
||||
|
||||
public function getFileSize()
|
||||
|
@ -71,7 +84,7 @@ class CloudFile extends BaseCloudFile
|
|||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, array(
|
||||
CURLOPT_URL => $this->getAbsoluteFilePath(),
|
||||
CURLOPT_URL => $this->getURLForTrackPreviewOrDownload(),
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_VERBOSE => false
|
||||
|
|
|
@ -28,8 +28,11 @@ class CloudStorageDownloader:
|
|||
except ObjectDoesNotExistError:
|
||||
logging.info("Could not find object: %s" % obj_name)
|
||||
|
||||
if os.path.isfile(dst) == False:
|
||||
logging.info('Downloading: %s to %s' % (cloud_obj.name, dst))
|
||||
cloud_obj.download(destination_path=dst)
|
||||
else:
|
||||
logging.info("Skipping download because %s already exists" % dst)
|
||||
|
||||
def read_config_file(self, config_path):
|
||||
"""Parse the application's config file located at config_path."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue