SAAS-853 - Celery backend for SoundCloud uploads
This commit is contained in:
parent
f031d13867
commit
626489bb3b
27 changed files with 813 additions and 250 deletions
|
@ -283,7 +283,6 @@ class LibraryController extends Zend_Controller_Action
|
|||
$text = _("Upload to SoundCloud");
|
||||
}
|
||||
|
||||
// TODO: reimplement how this works
|
||||
$menu["soundcloud"]["items"]["upload"] = array("name" => $text, "icon" => "soundcloud", "url" => $baseUrl."soundcloud/upload/id/{$id}");
|
||||
}
|
||||
|
||||
|
|
|
@ -8,32 +8,19 @@ class SoundcloudController extends ThirdPartyController {
|
|||
/**
|
||||
* @var SoundcloudService
|
||||
*/
|
||||
private $_soundcloudService;
|
||||
protected $_service;
|
||||
|
||||
/**
|
||||
* @var string Application_Model_Preference service request token accessor function name
|
||||
*/
|
||||
protected $_SERVICE_TOKEN_ACCESSOR = 'setSoundCloudRequestToken';
|
||||
|
||||
/**
|
||||
* Set up SoundCloud access variables.
|
||||
*/
|
||||
public function init() {
|
||||
parent::init();
|
||||
$this->_soundcloudService = new SoundcloudService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send user to SoundCloud to authorize before being redirected
|
||||
*/
|
||||
public function authorizeAction() {
|
||||
$auth_url = $this->_soundcloudService->getAuthorizeUrl();
|
||||
header('Location: ' . $auth_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when user successfully completes SoundCloud authorization.
|
||||
* Store the returned request token for future requests.
|
||||
*/
|
||||
public function redirectAction() {
|
||||
$code = $_GET['code'];
|
||||
$this->_soundcloudService->requestNewAccessToken($code);
|
||||
header('Location: ' . $this->_baseUrl . 'Preference'); // Redirect back to the Preference page
|
||||
$this->_service = new SoundcloudService();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,36 +30,17 @@ class SoundcloudController extends ThirdPartyController {
|
|||
$request = $this->getRequest();
|
||||
$id = $request->getParam('id');
|
||||
try {
|
||||
$soundcloudLink = $this->_soundcloudService->getLinkToFile($id);
|
||||
$soundcloudLink = $this->_service->getLinkToFile($id);
|
||||
header('Location: ' . $soundcloudLink);
|
||||
} catch (Soundcloud\Exception\InvalidHttpResponseCodeException $e) {
|
||||
// If we end up here it means the track was removed from SoundCloud
|
||||
// or the foreign id in our database is incorrect, so we should just
|
||||
// get rid of the database record
|
||||
Logging::warn("Error retrieving track data from SoundCloud: " . $e->getMessage());
|
||||
$this->_soundcloudService->removeTrackReference($id);
|
||||
$this->_service->removeTrackReference($id);
|
||||
// Redirect to a 404 so the user knows something went wrong
|
||||
header('Location: ' . $this->_baseUrl . 'error/error-404'); // Redirect back to the Preference page
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload the file with the given id to SoundCloud.
|
||||
*
|
||||
* @throws Zend_Controller_Response_Exception thrown if upload fails for any reason
|
||||
*/
|
||||
public function uploadAction() {
|
||||
$request = $this->getRequest();
|
||||
$id = $request->getParam('id');
|
||||
$this->_soundcloudService->upload($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the previously saved request token from the preferences.
|
||||
*/
|
||||
public function deauthorizeAction() {
|
||||
Application_Model_Preference::setSoundCloudRequestToken("");
|
||||
header('Location: ' . $this->_baseUrl . 'Preference'); // Redirect back to the Preference page
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,16 @@ abstract class ThirdPartyController extends Zend_Controller_Action {
|
|||
*/
|
||||
protected $_baseUrl;
|
||||
|
||||
/**
|
||||
* @var ThirdPartyService third party service object
|
||||
*/
|
||||
protected $_service;
|
||||
|
||||
/**
|
||||
* @var string Application_Model_Preference service request token accessor function name
|
||||
*/
|
||||
protected $_SERVICE_TOKEN_ACCESSOR;
|
||||
|
||||
/**
|
||||
* Disable controller rendering and initialize
|
||||
*/
|
||||
|
@ -17,8 +27,8 @@ abstract class ThirdPartyController extends Zend_Controller_Action {
|
|||
$CC_CONFIG = Config::getConfig();
|
||||
$this->_baseUrl = 'http://' . $CC_CONFIG['baseUrl'] . ":" . $CC_CONFIG['basePort'] . "/";
|
||||
|
||||
$this->view->layout()->disableLayout(); // Don't inject the standard Now Playing header.
|
||||
$this->_helper->viewRenderer->setNoRender(true); // Don't use (phtml) templates
|
||||
$this->view->layout()->disableLayout(); // Don't inject the standard Now Playing header.
|
||||
$this->_helper->viewRenderer->setNoRender(true); // Don't use (phtml) templates
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,30 +36,56 @@ abstract class ThirdPartyController extends Zend_Controller_Action {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract function authorizeAction();
|
||||
public function authorizeAction() {
|
||||
$auth_url = $this->_service->getAuthorizeUrl();
|
||||
header('Location: ' . $auth_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when user successfully completes third-party authorization.
|
||||
* Store the returned request token for future requests.
|
||||
* Called when user successfully completes third-party authorization
|
||||
* Store the returned request token for future requests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract function redirectAction();
|
||||
public function redirectAction() {
|
||||
$code = $_GET['code'];
|
||||
$this->_service->requestNewAccessToken($code);
|
||||
header('Location: ' . $this->_baseUrl . 'Preference'); // Redirect back to the Preference page
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload the file with the given id to a third-party service.
|
||||
* Upload the file with the given id to a third-party service
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Zend_Controller_Response_Exception thrown if upload fails for any reason
|
||||
*/
|
||||
abstract function uploadAction();
|
||||
public function uploadAction() {
|
||||
$request = $this->getRequest();
|
||||
$id = $request->getParam('id');
|
||||
$this->_service->upload($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the previously saved request token from the preferences.
|
||||
* Clear the previously saved request token from the preferences
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract function deauthorizeAction();
|
||||
public function deauthorizeAction() {
|
||||
Application_Model_Preference::$this->_SERVICE_TOKEN_ACCESSOR("");
|
||||
header('Location: ' . $this->_baseUrl . 'Preference'); // Redirect back to the Preference page
|
||||
}
|
||||
|
||||
/**
|
||||
* Poll the task queue for completed tasks associated with this service
|
||||
* Optionally accepts a specific task name as a parameter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function pollBrokerTaskQueueAction() {
|
||||
$request = $this->getRequest();
|
||||
$taskName = $request->getParam('task');
|
||||
$this->_service->pollBrokerTaskQueue($taskName);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,9 +13,9 @@ class UpgradeController extends Zend_Controller_Action
|
|||
return;
|
||||
}
|
||||
|
||||
// Get all upgrades dynamically so we don't have to add them explicitly each time
|
||||
// Get all upgrades dynamically (in declaration order!) so we don't have to add them explicitly each time
|
||||
// TODO: explicitly sort classnames by ascending version suffix for safety
|
||||
$upgraders = getUpgrades();
|
||||
Logging::info($upgraders);
|
||||
|
||||
$didWePerformAnUpgrade = false;
|
||||
try
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
CREATE TABLE IF NOT EXISTS "third_party_track_references"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"service" VARCHAR(512) NOT NULL,
|
||||
"foreign_id" INTEGER NOT NULL,
|
||||
"service" VARCHAR(256) NOT NULL,
|
||||
"foreign_id" VARCHAR(256),
|
||||
"broker_task_id" VARCHAR(256),
|
||||
"broker_task_name" VARCHAR(256),
|
||||
"broker_task_dispatch_time" TIMESTAMP,
|
||||
"file_id" INTEGER NOT NULL,
|
||||
"status" VARCHAR(256) NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
PRIMARY KEY ("id"),
|
||||
CONSTRAINT "broker_task_id_unique" UNIQUE ("broker_task_id"),
|
||||
CONSTRAINT "foreign_id_unique" UNIQUE ("foreign_id")
|
||||
);
|
||||
|
||||
ALTER TABLE "third_party_track_references" ADD CONSTRAINT "track_reference_fkey"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue