CC-5709: Airtime Analyzer
* Added session auth to the Media API (if you're logged in) * Started reworking our Plupload interaction with the server to be less awkward. * Basic uploading works with the Add Media page again, but messages aren't dispatched to airtime_analyzer yet (coming next...)
This commit is contained in:
parent
6d7117f670
commit
e6cbbdff33
|
@ -65,7 +65,7 @@ class LoginController extends Zend_Controller_Action
|
||||||
|
|
||||||
Application_Model_LoginAttempts::resetAttempts($_SERVER['REMOTE_ADDR']);
|
Application_Model_LoginAttempts::resetAttempts($_SERVER['REMOTE_ADDR']);
|
||||||
Application_Model_Subjects::resetLoginAttempts($username);
|
Application_Model_Subjects::resetLoginAttempts($username);
|
||||||
|
|
||||||
$tempSess = new Zend_Session_Namespace("referrer");
|
$tempSess = new Zend_Session_Namespace("referrer");
|
||||||
$tempSess->referrer = 'login';
|
$tempSess->referrer = 'login';
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ class PluploadController extends Zend_Controller_Action
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
||||||
$ajaxContext->addActionContext('upload', 'json')
|
$ajaxContext->addActionContext('upload', 'json')
|
||||||
->addActionContext('copyfile', 'json')
|
->addActionContext('uploadFinished', 'json')
|
||||||
->initContext();
|
->initContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,4 +76,12 @@ class Application_Model_RabbitMq
|
||||||
|
|
||||||
self::sendMessage($exchange, $data);
|
self::sendMessage($exchange, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function SendMessageToAnalyzer()
|
||||||
|
{
|
||||||
|
$exchange = 'airtime-uploads';
|
||||||
|
//$data = json_encode($md);
|
||||||
|
//TODO: Finish me
|
||||||
|
//self::sendMessage($exchange, $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
|
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
if (!$this->verifyApiKey()) {
|
if (!$this->verifyApiKey() && !$this->verifySession()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
|
|
||||||
public function getAction()
|
public function getAction()
|
||||||
{
|
{
|
||||||
if (!$this->verifyApiKey()) {
|
if (!$this->verifyApiKey() && !$this->verifySession()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
@ -42,6 +42,8 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
|
|
||||||
$file = CcFilesQuery::create()->findPk($id);
|
$file = CcFilesQuery::create()->findPk($id);
|
||||||
if ($file) {
|
if ($file) {
|
||||||
|
//TODO: Strip or sanitize the JSON output
|
||||||
|
|
||||||
$this->getResponse()
|
$this->getResponse()
|
||||||
->setHttpResponseCode(200)
|
->setHttpResponseCode(200)
|
||||||
->appendBody(json_encode($file->toArray(BasePeer::TYPE_FIELDNAME)));
|
->appendBody(json_encode($file->toArray(BasePeer::TYPE_FIELDNAME)));
|
||||||
|
@ -52,7 +54,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
|
|
||||||
public function postAction()
|
public function postAction()
|
||||||
{
|
{
|
||||||
if (!$this->verifyApiKey()) {
|
if (!$this->verifyApiKey() && !$this->verifySession()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//If we do get an ID on a POST, then that doesn't make any sense
|
//If we do get an ID on a POST, then that doesn't make any sense
|
||||||
|
@ -60,10 +62,13 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
if ($id = $this->_getParam('id', false)) {
|
if ($id = $this->_getParam('id', false)) {
|
||||||
$resp = $this->getResponse();
|
$resp = $this->getResponse();
|
||||||
$resp->setHttpResponseCode(400);
|
$resp->setHttpResponseCode(400);
|
||||||
$resp->appendBody("ERROR: ID should not be specified when using POST. POST is only used for show creation, and an ID will be chosen by Airtime");
|
$resp->appendBody("ERROR: ID should not be specified when using POST. POST is only used for file creation, and an ID will be chosen by Airtime");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->processUpload();
|
||||||
|
|
||||||
|
//TODO: Strip or sanitize the JSON output
|
||||||
$file = new CcFiles();
|
$file = new CcFiles();
|
||||||
$file->fromArray($this->getRequest()->getPost());
|
$file->fromArray($this->getRequest()->getPost());
|
||||||
$file->save();
|
$file->save();
|
||||||
|
@ -75,7 +80,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
|
|
||||||
public function putAction()
|
public function putAction()
|
||||||
{
|
{
|
||||||
if (!$this->verifyApiKey()) {
|
if (!$this->verifyApiKey() && !$this->verifySession()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
@ -86,6 +91,8 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
$file = CcFilesQuery::create()->findPk($id);
|
$file = CcFilesQuery::create()->findPk($id);
|
||||||
if ($file)
|
if ($file)
|
||||||
{
|
{
|
||||||
|
//TODO: Strip or sanitize the JSON output
|
||||||
|
|
||||||
$file->fromArray(json_decode($this->getRequest()->getRawBody(), true), BasePeer::TYPE_FIELDNAME);
|
$file->fromArray(json_decode($this->getRequest()->getRawBody(), true), BasePeer::TYPE_FIELDNAME);
|
||||||
$file->save();
|
$file->save();
|
||||||
$this->getResponse()
|
$this->getResponse()
|
||||||
|
@ -98,7 +105,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
|
|
||||||
public function deleteAction()
|
public function deleteAction()
|
||||||
{
|
{
|
||||||
if (!$this->verifyApiKey()) {
|
if (!$this->verifyApiKey() && !$this->verifySession()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
@ -107,6 +114,8 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
}
|
}
|
||||||
$file = CcFilesQuery::create()->findPk($id);
|
$file = CcFilesQuery::create()->findPk($id);
|
||||||
if ($file) {
|
if ($file) {
|
||||||
|
$storedFile = Application_Model_StoredFile($file);
|
||||||
|
$storedFile->delete(); //TODO: This checks your session permissions... Make it work without a session?
|
||||||
$file->delete();
|
$file->delete();
|
||||||
$this->getResponse()
|
$this->getResponse()
|
||||||
->setHttpResponseCode(204);
|
->setHttpResponseCode(204);
|
||||||
|
@ -148,6 +157,20 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function verifySession()
|
||||||
|
{
|
||||||
|
$auth = Zend_Auth::getInstance();
|
||||||
|
if ($auth->hasIdentity())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Token checking stub code. We'd need to change LoginController.php to generate a token too, but
|
||||||
|
//but luckily all the token code already exists and works.
|
||||||
|
//$auth = new Application_Model_Auth();
|
||||||
|
//$auth->checkToken(Application_Model_Preference::getUserId(), $token);
|
||||||
|
}
|
||||||
|
|
||||||
private function fileNotFoundResponse()
|
private function fileNotFoundResponse()
|
||||||
{
|
{
|
||||||
|
@ -155,4 +178,14 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
$resp->setHttpResponseCode(404);
|
$resp->setHttpResponseCode(404);
|
||||||
$resp->appendBody("ERROR: Media not found.");
|
$resp->appendBody("ERROR: Media not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function processUpload()
|
||||||
|
{
|
||||||
|
$upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
|
||||||
|
$tempFilePath = Application_Model_StoredFile::uploadFile($upload_dir);
|
||||||
|
$tempFileName = basename($tempFilePath);
|
||||||
|
|
||||||
|
//TODO: Dispatch a message to airtime_analyzer through RabbitMQ!
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,8 +5,9 @@ $(document).ready(function() {
|
||||||
$("#plupload_files").pluploadQueue({
|
$("#plupload_files").pluploadQueue({
|
||||||
// General settings
|
// General settings
|
||||||
runtimes : 'gears, html5, html4',
|
runtimes : 'gears, html5, html4',
|
||||||
url : baseUrl+'Plupload/upload/format/json',
|
//url : baseUrl+'Plupload/upload/format/json',
|
||||||
chunk_size : '5mb',
|
url : baseUrl+'rest/media',
|
||||||
|
//chunk_size : '5mb', //Disabling chunking since we're using the File Upload REST API now
|
||||||
unique_names : 'true',
|
unique_names : 'true',
|
||||||
multiple_queues : 'true',
|
multiple_queues : 'true',
|
||||||
filters : [
|
filters : [
|
||||||
|
@ -17,16 +18,21 @@ $(document).ready(function() {
|
||||||
uploader = $("#plupload_files").pluploadQueue();
|
uploader = $("#plupload_files").pluploadQueue();
|
||||||
|
|
||||||
uploader.bind('FileUploaded', function(up, file, json) {
|
uploader.bind('FileUploaded', function(up, file, json) {
|
||||||
|
|
||||||
|
/*
|
||||||
var j = jQuery.parseJSON(json.response);
|
var j = jQuery.parseJSON(json.response);
|
||||||
|
|
||||||
if(j.error !== undefined) {
|
console.log(json.response);
|
||||||
|
if (j.error !== undefined) {
|
||||||
var row = $("<tr/>")
|
var row = $("<tr/>")
|
||||||
.append('<td>' + file.name +'</td>')
|
.append('<td>' + file.name +'</td>')
|
||||||
.append('<td>' + j.error.message + '</td>');
|
.append('<td>' + j.error.message + '</td>');
|
||||||
|
|
||||||
$("#plupload_error").find("table").append(row);
|
$("#plupload_error").find("table").append(row);
|
||||||
$("#plupload_error table").css("display", "inline-table");
|
$("#plupload_error table").css("display", "inline-table");
|
||||||
}else{
|
} else {
|
||||||
|
//FIXME: This should just update something in the GUI, not communicate with the backend -- Albert
|
||||||
|
/*
|
||||||
var tempFileName = j.tempfilepath;
|
var tempFileName = j.tempfilepath;
|
||||||
$.get(baseUrl+'Plupload/copyfile/format/json/name/'+
|
$.get(baseUrl+'Plupload/copyfile/format/json/name/'+
|
||||||
encodeURIComponent(file.name)+'/tempname/' +
|
encodeURIComponent(file.name)+'/tempname/' +
|
||||||
|
@ -35,12 +41,12 @@ $(document).ready(function() {
|
||||||
var row = $("<tr/>")
|
var row = $("<tr/>")
|
||||||
.append('<td>' + file.name +'</td>')
|
.append('<td>' + file.name +'</td>')
|
||||||
.append('<td>' + jr.error.message + '</td>');
|
.append('<td>' + jr.error.message + '</td>');
|
||||||
|
|
||||||
$("#plupload_error").find("table").append(row);
|
$("#plupload_error").find("table").append(row);
|
||||||
$("#plupload_error table").css("display", "inline-table");
|
$("#plupload_error table").css("display", "inline-table");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}*/
|
||||||
});
|
});
|
||||||
|
|
||||||
var uploadProgress = false;
|
var uploadProgress = false;
|
||||||
|
|
Loading…
Reference in New Issue