Pull the logic for Media REST API out of the controller
This commit is contained in:
parent
487ab9bd99
commit
0177e40083
5 changed files with 482 additions and 335 deletions
41
airtime_mvc/application/services/MediaService.php
Normal file
41
airtime_mvc/application/services/MediaService.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
class Application_Service_MediaService
|
||||
{
|
||||
public static function processUploadedFile($callbackUrl, $originalFilename, $ownerId)
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$apiKey = $CC_CONFIG["apiKey"][0];
|
||||
|
||||
$tempFilePath = $_FILES['file']['tmp_name'];
|
||||
$tempFileName = basename($tempFilePath);
|
||||
|
||||
//Only accept files with a file extension that we support.
|
||||
$fileExtension = pathinfo($originalFilename, PATHINFO_EXTENSION);
|
||||
if (!in_array(strtolower($fileExtension), explode(",", "ogg,mp3,oga,flac,wav,m4a,mp4,opus"))) {
|
||||
@unlink($tempFilePath);
|
||||
throw new Exception("Bad file extension.");
|
||||
}
|
||||
|
||||
//TODO: Remove uploadFileAction from ApiController.php **IMPORTANT** - It's used by the recorder daemon...
|
||||
|
||||
$storDir = Application_Model_MusicDir::getStorDir();
|
||||
$importedStorageDirectory = $storDir->getDirectory() . "/imported/" . $ownerId;
|
||||
|
||||
try {
|
||||
//Copy the temporary file over to the "organize" folder so that it's off our webserver
|
||||
//and accessible by airtime_analyzer which could be running on a different machine.
|
||||
$newTempFilePath = Application_Model_StoredFile::copyFileToStor($tempFilePath, $originalFilename);
|
||||
} catch (Exception $e) {
|
||||
@unlink($tempFilePath);
|
||||
Logging::error($e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
//Dispatch a message to airtime_analyzer through RabbitMQ,
|
||||
//notifying it that there's a new upload to process!
|
||||
Application_Model_RabbitMq::SendMessageToAnalyzer($newTempFilePath,
|
||||
$importedStorageDirectory, basename($originalFilename),
|
||||
$callbackUrl, $apiKey);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue