diff --git a/airtime_mvc/application/controllers/AudiopreviewController.php b/airtime_mvc/application/controllers/AudiopreviewController.php index e90c34a39..7f7b7b68d 100644 --- a/airtime_mvc/application/controllers/AudiopreviewController.php +++ b/airtime_mvc/application/controllers/AudiopreviewController.php @@ -48,6 +48,7 @@ class AudiopreviewController extends Zend_Controller_Action if ($type == "audioclip") { $media = Application_Model_StoredFile::RecallById($audioFileID); $uri = $baseUrl."api/get-media/file/".$audioFileID; + //$uri = $media->getPropelOrm()->downloadFile(); $mime = $media->getPropelOrm()->getDbMime(); } elseif ($type == "stream") { $webstream = CcWebstreamQuery::create()->findPk($audioFileID); diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 96cbf6e89..ba836cb82 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -191,7 +191,6 @@ class LibraryController extends Zend_Controller_Action $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); if ($type === "audioclip") { - $file = Application_Model_StoredFile::RecallById($id); $menu["play"]["mime"] = $file->getPropelOrm()->getDbMime(); @@ -216,7 +215,11 @@ class LibraryController extends Zend_Controller_Action $menu["edit"] = array("name"=> _("Edit Metadata"), "icon" => "edit", "url" => $baseUrl."library/edit-file-md/id/{$id}"); } - $url = $file->getRelativeFileUrl($baseUrl).'/download/true'; + // It's important that we always return the parent id (cc_files id) + // and not the cloud_file id (if applicable) for track download. + // Our application logic (StoredFile.php) will determine if the track + // is a cloud_file and handle it appropriately. + $url = $baseUrl."api/get-media/file/".$id.".".$file->getFileExtension().'/download/true'; $menu["download"] = array("name" => _("Download"), "icon" => "download", "url" => $url); } elseif ($type === "playlist" || $type === "block") { if ($type === 'playlist') { diff --git a/airtime_mvc/application/models/airtime/CloudFile.php b/airtime_mvc/application/models/airtime/CloudFile.php index d64d8f6e0..ab7dfadaa 100644 --- a/airtime_mvc/application/models/airtime/CloudFile.php +++ b/airtime_mvc/application/models/airtime/CloudFile.php @@ -1,6 +1,6 @@ getResourceId()); + return $this->get_s3_signed_url( + $CC_CONFIG['cloud_storage']['api_key'], + $CC_CONFIG['cloud_storage']['api_key_secret'], + $CC_CONFIG['cloud_storage']['bucket']); + } + + private function get_s3_signed_url($s3_key, $s3_key_secret, $bucket) + { + //should be longer than track length + $expires = 120; + $resource = $this->getResourceId(); + + $expires = time()+$expires; + $string_to_sign = "GET\n\n\n{$expires}\n/{$bucket}/{$resource}"; + $signature = base64_encode((hash_hmac("sha1", utf8_encode($string_to_sign), $s3_key_secret, TRUE))); + + $authentication_params = "AWSAccessKeyId={$s3_key}&Expires={$expires}&Signature={$signature}"; + + $s3 = new Zend_Service_Amazon_S3($s3_key, $s3_key_secret); + $endpoint = $s3->getEndpoint(); + $scheme = $endpoint->getScheme(); + $host = $endpoint->getHost(); + + $url = "{$scheme}://{$host}/{$bucket}/".urlencode($resource)."?{$authentication_params}"; + Logging::info($url); + return $url; } public function getFileSize() @@ -61,8 +86,7 @@ class CloudFile extends BaseCloudFile public function deletePhysicalFile() { $CC_CONFIG = Config::getConfig(); - //$pathToScript = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."cloud_storage_deleter.py" : "/home/denise/airtime/cloud_storage_deleter.py"; - + $provider = escapeshellarg($CC_CONFIG["cloud_storage"]["provider"]); $bucket = escapeshellarg($CC_CONFIG["cloud_storage"]["bucket"]); $apiKey = escapeshellarg($CC_CONFIG["cloud_storage"]["api_key"]); @@ -92,4 +116,16 @@ class CloudFile extends BaseCloudFile CcFilesQuery::create()->findPk($this->getCcFileId())->delete(); parent::delete(); } + + public function downloadFile() + { + $CC_CONFIG = Config::getConfig(); + + $s3 = new Zend_Service_Amazon_S3($CC_CONFIG['cloud_storage']['api_key'], $CC_CONFIG['cloud_storage']['api_key_secret']); + //$fileObj = $s3->getObject($CC_CONFIG['cloud_storage']['bucket']."/".$this->getResourceId()); + + $response_stream = $s3->getObjectStream($CC_CONFIG['cloud_storage']['bucket']."/".$this->getResourceId()); + copy($response_stream->getStreamName(), "/tmp/".$this->getResourceId()); + Logging::info($response_stream); + } } diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index 37a7ae6ff..15c8cb451 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -236,6 +236,7 @@ class Rest_MediaController extends Zend_Rest_Controller $cloudFile->save(); //file is stored locally + //we should get rid of this since we're removing local file storage } else if (isset($requestData["full_path"])) { $fileSizeBytes = filesize($requestData["full_path"]); if ($fileSizeBytes === false) diff --git a/airtime_mvc/build/airtime.conf b/airtime_mvc/build/airtime.conf index 7495bd9f3..517a81122 100644 --- a/airtime_mvc/build/airtime.conf +++ b/airtime_mvc/build/airtime.conf @@ -30,3 +30,10 @@ monit_password = airtime [soundcloud] connection_retries = 3 time_between_retries = 60 + +[cloud_storage] +provider = +endpoint = +bucket = +api_key = +api_key_secret = \ No newline at end of file diff --git a/install_minimal/include/airtime-install.php b/install_minimal/include/airtime-install.php index db01fdcf9..481983a0f 100644 --- a/install_minimal/include/airtime-install.php +++ b/install_minimal/include/airtime-install.php @@ -59,7 +59,7 @@ if ($overwrite) { if (!$iniExists){ require_once(AirtimeInstall::GetAirtimeSrcDir().'/application/configs/conf.php'); $CC_CONFIG = Config::getConfig(); - require_once 'propel/runtime/lib/Propel.php'; + require_once 'vendor/propel/propel1/runtime/lib/Propel.php'; Propel::init(AirtimeInstall::GetAirtimeSrcDir()."/application/configs/airtime-conf-production.php"); } diff --git a/python_apps/pypo/cloud_storage_downloader.py b/python_apps/pypo/cloud_storage_downloader.py index 09182cac6..01a9a1ee7 100644 --- a/python_apps/pypo/cloud_storage_downloader.py +++ b/python_apps/pypo/cloud_storage_downloader.py @@ -1,6 +1,7 @@ import os import logging import ConfigParser +import sys from libcloud.storage.types import Provider, ObjectDoesNotExistError from libcloud.storage.providers import get_driver @@ -37,9 +38,9 @@ class CloudStorageDownloader: config.readfp(open(config_path)) except IOError as e: print "Failed to open config file at " + config_path + ": " + e.strerror - exit(-1) + sys.exit() except Exception: print e.strerror - exit(-1) + sys.exit() return config