From ecb072b84cccde687adedd2cf68dc9f188f2b1cd Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 28 Jul 2014 15:17:46 -0400 Subject: [PATCH] CC-5896: Store cloud files in separate table, inherited from cc_files Fixed broken metadata display on Library page Fixed broken download/preview option from Library page --- .../application/controllers/ApiController.php | 26 ++++++++++++------- .../controllers/LibraryController.php | 2 +- .../rest/controllers/MediaController.php | 3 +++ .../cloud_storage_uploader.py | 3 +++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 3f0806285..13f7f9746 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -83,8 +83,10 @@ class ApiController extends Zend_Controller_Action if ($media != null) { // Make sure we don't have some wrong result beecause of caching clearstatcache(); + if ($media->getPropelOrm()->isValidFile()) { - $filename = $media->getPropelOrm()->getFilename(); + //$filename = $media->getPropelOrm()->getFilename(); + $filename = $media->getPropelOrm()->getDbFilepath(); //Download user left clicks a track and selects Download. if ("true" == $this->_getParam('download')) { @@ -94,11 +96,13 @@ class ApiController extends Zend_Controller_Action //to the browser what name the file should be saved as. header('Content-Disposition: attachment; filename="'.$filename.'"'); } else { - //user clicks play button for track and downloads it. + //user clicks play button for track preview header('Content-Disposition: inline; filename="'.$filename.'"'); + $this->_redirect($media->getFilePath()); } - $this->_redirect($media->getFilePath()); + $this->smartReadFile($media); + exit; } else { header ("HTTP/1.1 404 Not Found"); } @@ -119,12 +123,13 @@ class ApiController extends Zend_Controller_Action * @link https://groups.google.com/d/msg/jplayer/nSM2UmnSKKA/Hu76jDZS4xcJ * @link http://php.net/manual/en/function.readfile.php#86244 */ - public function smartReadFile($location, $mimeType = 'audio/mp3') + public function smartReadFile($media) { - $size= filesize($location); - $time= date('r', filemtime($location)); + $filepath = $media->getFilePath(); + $size= $media->getFileSize(); + $mimeType = $media->getPropelOrm()->getDbMime(); - $fm = @fopen($location, 'rb'); + $fm = @fopen($filepath, 'rb'); if (!$fm) { header ("HTTP/1.1 505 Internal server error"); @@ -157,19 +162,22 @@ class ApiController extends Zend_Controller_Action header("Content-Range: bytes $begin-$end/$size"); } header("Content-Transfer-Encoding: binary"); - header("Last-Modified: $time"); //We can have multiple levels of output buffering. Need to //keep looping until all have been disabled!!! //http://www.php.net/manual/en/function.ob-end-flush.php while (@ob_end_flush()); - $cur = $begin; + /*$cur = $begin; fseek($fm, $begin, 0); while (!feof($fm) && $cur <= $end && (connection_status() == 0)) { echo fread($fm, min(1024 * 16, ($end - $cur) + 1)); $cur += 1024 * 16; + }*/ + + while(!feof($fm)) { + echo fread($fm, 1024 * 8); } } diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 41ab24eaa..bcb44e04d 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -481,7 +481,7 @@ class LibraryController extends Zend_Controller_Action $md = $file->getMetadata(); foreach ($md as $key => $value) { - if ($key == 'MDATA_KEY_DIRECTORY') { + if ($key == 'MDATA_KEY_DIRECTORY' && !is_null($value)) { $musicDir = Application_Model_MusicDir::getDirByPK($value); $md['MDATA_KEY_FILEPATH'] = Application_Common_OsPath::join($musicDir->getDirectory(), $md['MDATA_KEY_FILEPATH']); } diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index 6cb72062a..7c57b58d7 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -226,6 +226,9 @@ class Rest_MediaController extends Zend_Rest_Controller //file is stored in the cloud if (isset($requestData["resource_id"])) { + //store the original filename + $file->setDbFilepath($requestData["filename"]); + $fileSizeBytes = $requestData["filesize"]; $cloudFile = new CloudFile(); $cloudFile->setResourceId($requestData["resource_id"]); diff --git a/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py b/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py index 70a352852..3113d2937 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py @@ -41,6 +41,9 @@ class CloudStorageUploader: except OSError: logging.info("Could not remove %s from organize directory" % audio_file_path) + '''pass original filename to Airtime so we can store it in the db''' + metadata["filename"] = file_base_name + metadata["resource_id"] = object_name return metadata