Massive refactor of the analyzer branch and sync it back up with the
cloud storage branch (for the last time) * Backported all the bugfixes from cc-5709-airtime-analyzer-cloud-storage * Backported missing FileStorageBackend.php * Fixed CC-6001: Track titles and artist names with slashes break audio preview * Refactored all the MediaController code, pulling out the logic into MediaService * Fixed an API key leak to guests in the Media API * Made this branch work without cloud_storage.conf (defaults to file storage) * Made ApiController's getMediaAction use the MediaService code
This commit is contained in:
parent
6d00da89db
commit
2a89e4d5a0
13 changed files with 275 additions and 179 deletions
|
@ -57,7 +57,7 @@ class CcFiles extends BaseCcFiles {
|
|||
* Retrieve a sanitized version of the file metadata, suitable for public access.
|
||||
* @param $fileId
|
||||
*/
|
||||
public static function getSantiziedFileById($fileId)
|
||||
public static function getSanitizedFileById($fileId)
|
||||
{
|
||||
$file = CcFilesQuery::create()->findPk($fileId);
|
||||
if ($file) {
|
||||
|
@ -114,7 +114,7 @@ class CcFiles extends BaseCcFiles {
|
|||
$file->setDbHidden(true);
|
||||
$file->save();
|
||||
|
||||
$callbackUrl = Application_Common_HTTPHelper::getStationUrl() . "/rest/media/" . $file->getPrimaryKey();
|
||||
$callbackUrl = Application_Common_HTTPHelper::getStationUrl() . "rest/media/" . $file->getPrimaryKey();
|
||||
|
||||
Application_Service_MediaService::processUploadedFile($callbackUrl, $relativePath, self::getOwnerId());
|
||||
return CcFiles::sanitizeResponse($file);
|
||||
|
@ -138,14 +138,11 @@ class CcFiles extends BaseCcFiles {
|
|||
{
|
||||
$file = CcFilesQuery::create()->findPk($fileId);
|
||||
|
||||
// Since we check for this value when deleting files, set it first
|
||||
$file->setDbDirectory(self::MUSIC_DIRS_STOR_PK);
|
||||
|
||||
$fileArray = self::removeBlacklistedFields($fileArray);
|
||||
$fileArray = self::stripTimeStampFromYearTag($fileArray);
|
||||
|
||||
self::validateFileArray($fileArray);
|
||||
if ($file && isset($requestData["resource_id"])) {
|
||||
if ($file && isset($fileArray["resource_id"])) {
|
||||
|
||||
$file->fromArray($fileArray, BasePeer::TYPE_FIELDNAME);
|
||||
|
||||
|
@ -155,9 +152,10 @@ class CcFiles extends BaseCcFiles {
|
|||
$fileSizeBytes = $fileArray["filesize"];
|
||||
if (!isset($fileSizeBytes) || $fileSizeBytes === false)
|
||||
{
|
||||
$file->setDbImportStatus(2)->save();
|
||||
$file->setDbImportStatus(self::IMPORT_STATUS_FAILED)->save();
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
$cloudFile = new CloudFile();
|
||||
$cloudFile->setStorageBackend($fileArray["storage_backend"]);
|
||||
$cloudFile->setResourceId($fileArray["resource_id"]);
|
||||
|
@ -172,6 +170,9 @@ class CcFiles extends BaseCcFiles {
|
|||
|
||||
} else if ($file) {
|
||||
|
||||
// Since we check for this value when deleting files, set it first
|
||||
$file->setDbDirectory(self::MUSIC_DIRS_STOR_PK);
|
||||
|
||||
$file->fromArray($fileArray, BasePeer::TYPE_FIELDNAME);
|
||||
|
||||
//Our RESTful API takes "full_path" as a field, which we then split and translate to match
|
||||
|
@ -252,6 +253,7 @@ class CcFiles extends BaseCcFiles {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static function validateFileArray(&$fileArray)
|
||||
{
|
||||
// Sanitize any wildly incorrect metadata before it goes to be validated
|
||||
|
@ -342,6 +344,42 @@ class CcFiles extends BaseCcFiles {
|
|||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file size in bytes.
|
||||
*/
|
||||
public function getFileSize()
|
||||
{
|
||||
return filesize($this->getAbsoluteFilePath());
|
||||
}
|
||||
|
||||
public function getFilename()
|
||||
{
|
||||
$info = pathinfo($this->getAbsoluteFilePath());
|
||||
return $info['filename'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file's absolute file path stored on disk.
|
||||
*/
|
||||
public function getURLForTrackPreviewOrDownload()
|
||||
{
|
||||
return $this->getAbsoluteFilePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file's absolute file path stored on disk.
|
||||
*/
|
||||
public function getAbsoluteFilePath()
|
||||
{
|
||||
$music_dir = Application_Model_MusicDir::getDirByPK($this->getDbDirectory());
|
||||
if (!$music_dir) {
|
||||
throw new Exception("Invalid music_dir for file in database.");
|
||||
}
|
||||
$directory = $music_dir->getDirectory();
|
||||
$filepath = $this->getDbFilepath();
|
||||
return Application_Common_OsPath::join($directory, $filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Strips out fields from incoming request data that should never be modified
|
||||
|
@ -421,43 +459,7 @@ class CcFiles extends BaseCcFiles {
|
|||
exec("find $path -empty -type d -delete");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file size in bytes.
|
||||
*/
|
||||
public function getFileSize()
|
||||
{
|
||||
return filesize($this->getAbsoluteFilePath());
|
||||
}
|
||||
|
||||
public function getFilename()
|
||||
{
|
||||
$info = pathinfo($this->getAbsoluteFilePath());
|
||||
return $info['filename'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file's absolute file path stored on disk.
|
||||
*/
|
||||
public function getURLForTrackPreviewOrDownload()
|
||||
{
|
||||
return $this->getAbsoluteFilePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file's absolute file path stored on disk.
|
||||
*/
|
||||
public function getAbsoluteFilePath()
|
||||
{
|
||||
$music_dir = Application_Model_MusicDir::getDirByPK($this->getDbDirectory());
|
||||
if (!$music_dir) {
|
||||
throw new Exception("Invalid music_dir for file in database.");
|
||||
}
|
||||
$directory = $music_dir->getDirectory();
|
||||
$filepath = $this->getDbFilepath();
|
||||
|
||||
return Application_Common_OsPath::join($directory, $filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the file is a regular file that can be previewed and downloaded.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue