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
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue