More refactoring: Allow files to be imported from disk directly
This commit is contained in:
parent
2a89e4d5a0
commit
84f0f135ef
4 changed files with 137 additions and 134 deletions
|
@ -4,38 +4,30 @@ require_once('ProxyStorageBackend.php');
|
|||
|
||||
class Application_Service_MediaService
|
||||
{
|
||||
public static function processUploadedFile($callbackUrl, $originalFilename, $ownerId)
|
||||
/** Move (or copy) a file to the stor/organize directory and send it off to the
|
||||
analyzer to be processed.
|
||||
* @param $callbackUrl
|
||||
* @param $filePath string Path to the local file to import to the library
|
||||
* @param $originalFilename string The original filename, if you want it to be preserved after import.
|
||||
* @param $ownerId string The ID of the user that will own the file inside Airtime.
|
||||
* @param $copyFile bool True if you want to copy the file to the "organize" directory, false if you want to move it (default)
|
||||
* @return Ambigous
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function importFileToLibrary($callbackUrl, $filePath, $originalFilename, $ownerId, $copyFile)
|
||||
{
|
||||
$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...
|
||||
|
||||
$importedStorageDirectory = "";
|
||||
if ($CC_CONFIG["current_backend"] == "file") {
|
||||
$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;
|
||||
}
|
||||
//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::moveFileToStor($filePath, $originalFilename, $copyFile);
|
||||
|
||||
//Dispatch a message to airtime_analyzer through RabbitMQ,
|
||||
//notifying it that there's a new upload to process!
|
||||
|
@ -45,6 +37,8 @@ class Application_Service_MediaService
|
|||
$callbackUrl, $apiKey,
|
||||
$CC_CONFIG["current_backend"],
|
||||
$storageBackend->getFilePrefix());
|
||||
|
||||
return $newTempFilePath;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue