Merge branch 'cc-5709-airtime-analyzer' of github.com:sourcefabric/Airtime into cc-5709-airtime-analyzer
This commit is contained in:
commit
ace03edd2e
|
@ -23,5 +23,15 @@ class Rest_Bootstrap extends Zend_Application_Module_Bootstrap
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$router->addRoute('download', $downloadRoute);
|
$router->addRoute('download', $downloadRoute);
|
||||||
|
|
||||||
|
$clearLibraryRoute = new Zend_Controller_Router_Route(
|
||||||
|
'rest/media/clear',
|
||||||
|
array(
|
||||||
|
'controller' => 'media',
|
||||||
|
'action' => 'clear',
|
||||||
|
'module' => 'rest'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$router->addRoute('clear', $clearLibraryRoute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,42 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
$this->fileNotFoundResponse();
|
$this->fileNotFoundResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function clearAction()
|
||||||
|
{
|
||||||
|
//TODO:: make this not accessible via public api??
|
||||||
|
if (!$this->verifyAuth(true, true))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//set file_exists flag to false for every file
|
||||||
|
$con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
|
||||||
|
$selectCriteria = new Criteria();
|
||||||
|
$selectCriteria->add(CcFilesPeer::FILE_EXISTS, true);
|
||||||
|
$updateCriteria = new Criteria();
|
||||||
|
$updateCriteria->add(CcFilesPeer::FILE_EXISTS, false);
|
||||||
|
BasePeer::doUpdate($selectCriteria, $updateCriteria, $con);
|
||||||
|
|
||||||
|
$path = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."/srv/airtime/stor/imported/*" : "/srv/airtime/stor/imported/*";
|
||||||
|
exec("rm -rf $path");
|
||||||
|
|
||||||
|
//update disk_usage value in cc_pref
|
||||||
|
$musicDir = CcMusicDirsQuery::create()
|
||||||
|
->filterByType('stor')
|
||||||
|
->filterByExists(true)
|
||||||
|
->findOne();
|
||||||
|
$storPath = $musicDir->getDirectory();
|
||||||
|
|
||||||
|
$freeSpace = disk_free_space($storPath);
|
||||||
|
$totalSpace = disk_total_space($storPath);
|
||||||
|
|
||||||
|
Application_Model_Preference::setDiskUsage($totalSpace - $freeSpace);
|
||||||
|
|
||||||
|
$this->getResponse()
|
||||||
|
->setHttpResponseCode(200)
|
||||||
|
->appendBody("Library has been cleared");
|
||||||
|
}
|
||||||
|
|
||||||
public function getAction()
|
public function getAction()
|
||||||
{
|
{
|
||||||
|
@ -136,7 +172,21 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
$file->save();
|
$file->save();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
/* If full_path is set, the post request came from ftp.
|
||||||
|
* Users are allowed to upload folders via ftp. If this is the case
|
||||||
|
* we need to include the folder name with the file name, otherwise
|
||||||
|
* files won't get removed from the organize folder.
|
||||||
|
*/
|
||||||
|
if (isset($whiteList["full_path"])) {
|
||||||
|
$fullPath = $whiteList["full_path"];
|
||||||
|
$basePath = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."/srv/airtime/stor/organize/" : "/srv/airtime/stor/organize/";
|
||||||
|
//$relativePath is the folder name(if one) + track name, that was uploaded via ftp
|
||||||
|
$relativePath = substr($fullPath, strlen($basePath)-1);
|
||||||
|
} else {
|
||||||
|
$relativePath = $_FILES["file"]["name"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$file->fromArray($whiteList);
|
$file->fromArray($whiteList);
|
||||||
$file->setDbOwnerId($this->getOwnerId());
|
$file->setDbOwnerId($this->getOwnerId());
|
||||||
$now = new DateTime("now", new DateTimeZone("UTC"));
|
$now = new DateTime("now", new DateTimeZone("UTC"));
|
||||||
|
@ -146,9 +196,9 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
$file->save();
|
$file->save();
|
||||||
|
|
||||||
$callbackUrl = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getRequestUri() . "/" . $file->getPrimaryKey();
|
$callbackUrl = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getRequestUri() . "/" . $file->getPrimaryKey();
|
||||||
|
|
||||||
$this->processUploadedFile($callbackUrl, $_FILES["file"]["name"], $this->getOwnerId());
|
$this->processUploadedFile($callbackUrl, $relativePath, $this->getOwnerId());
|
||||||
|
|
||||||
$this->getResponse()
|
$this->getResponse()
|
||||||
->setHttpResponseCode(201)
|
->setHttpResponseCode(201)
|
||||||
->appendBody(json_encode($this->sanitizeResponse($file)));
|
->appendBody(json_encode($this->sanitizeResponse($file)));
|
||||||
|
@ -201,6 +251,10 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
$now = new DateTime("now", new DateTimeZone("UTC"));
|
$now = new DateTime("now", new DateTimeZone("UTC"));
|
||||||
$file->setDbMtime($now);
|
$file->setDbMtime($now);
|
||||||
$file->save();
|
$file->save();
|
||||||
|
|
||||||
|
$this->removeEmptySubFolders(
|
||||||
|
isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."/srv/airtime/stor/organize/" : "/srv/airtime/stor/organize/");
|
||||||
|
|
||||||
$this->getResponse()
|
$this->getResponse()
|
||||||
->setHttpResponseCode(200)
|
->setHttpResponseCode(200)
|
||||||
->appendBody(json_encode($this->sanitizeResponse($file)));
|
->appendBody(json_encode($this->sanitizeResponse($file)));
|
||||||
|
@ -365,14 +419,11 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
Logging::error($e->getMessage());
|
Logging::error($e->getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging::info($newTempFilePath);
|
|
||||||
//Logging::info("Old temp file path: " . $tempFilePath);
|
|
||||||
|
|
||||||
//Dispatch a message to airtime_analyzer through RabbitMQ,
|
//Dispatch a message to airtime_analyzer through RabbitMQ,
|
||||||
//notifying it that there's a new upload to process!
|
//notifying it that there's a new upload to process!
|
||||||
Application_Model_RabbitMq::SendMessageToAnalyzer($newTempFilePath,
|
Application_Model_RabbitMq::SendMessageToAnalyzer($newTempFilePath,
|
||||||
$importedStorageDirectory, $originalFilename,
|
$importedStorageDirectory, basename($originalFilename),
|
||||||
$callbackUrl, $apiKey);
|
$callbackUrl, $apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,5 +481,10 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function removeEmptySubFolders($path)
|
||||||
|
{
|
||||||
|
exec("find $path -empty -type d -delete");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ post_file() {
|
||||||
|
|
||||||
api_key=$(awk -F "= " '/api_key/ {print $2}' $instance_conf_path)
|
api_key=$(awk -F "= " '/api_key/ {print $2}' $instance_conf_path)
|
||||||
|
|
||||||
until curl --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}" -F "name=${filename}"
|
until curl --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}" -F "full_path=${file_path}"
|
||||||
do
|
do
|
||||||
retry_count=$[$retry_count+1]
|
retry_count=$[$retry_count+1]
|
||||||
if [ $retry_count -ge $max_retry ]; then
|
if [ $retry_count -ge $max_retry ]; then
|
||||||
|
|
Loading…
Reference in New Issue