cc-2182: convert back to restful design

-initial commit
This commit is contained in:
martin 2011-05-02 15:33:32 -04:00
parent b3beab1dbd
commit 9e01e389ea
5 changed files with 17 additions and 39 deletions

View File

@ -11,48 +11,24 @@ define('AIRTIME_COPYRIGHT_DATE', '2010-2011');
define('AIRTIME_REST_VERSION', '1.1');
global $CC_CONFIG;
$values = load_airtime_config();
$CC_CONFIG = array(
// Name of the web server user
'webServerUser' => $values['general']['web_server_user'],
'rabbitmq' => $values['rabbitmq'],
'baseFilesDir' => $values['general']['base_files_dir'],
// main directory for storing binary media files
'storageDir' => $values['general']['base_files_dir']."/stor",
// Database config
'dsn' => array(
'username' => $values['database']['dbuser'],
'password' => $values['database']['dbpass'],
'hostspec' => $values['database']['host'],
'phptype' => 'pgsql',
'database' => $values['database']['dbname']),
// prefix for table names in the database
'tblNamePrefix' => 'cc_',
/* ================================================ storage configuration */
'apiKey' => array($values['general']['api_key']),
'apiPath' => '/api/',
'soundcloud-client-id' => '2CLCxcSXYzx7QhhPVHN4A',
'soundcloud-client-secret' => 'pZ7beWmF06epXLHVUP1ufOg2oEnIt9XhE8l8xt0bBs',
'soundcloud-connection-retries' => $values['soundcloud']['connection_retries'],
'soundcloud-connection-wait' => $values['soundcloud']['time_between_retries'],
"rootDir" => __DIR__."/../..",
'pearPath' => dirname(__FILE__).'/../../library/pear',
'zendPath' => dirname(__FILE__).'/../../library/Zend',
'phingPath' => dirname(__FILE__).'/../../library/phing',
'phingPath' => dirname(__FILE__).'/../../library/phing'
);
$CC_CONFIG = Config::loadConfig($CC_CONFIG);
// Add database table names
$CC_CONFIG['playListTable'] = $CC_CONFIG['tblNamePrefix'].'playlist';
$CC_CONFIG['playListContentsTable'] = $CC_CONFIG['tblNamePrefix'].'playlistcontents';
@ -83,20 +59,17 @@ set_include_path('.'.PATH_SEPARATOR.$CC_CONFIG['pearPath']
.PATH_SEPARATOR.$CC_CONFIG['zendPath']
.PATH_SEPARATOR.$old_include_path);
function load_airtime_config(){
$ini_array = parse_ini_file('/etc/airtime/airtime.conf', true);
return $ini_array;
}
class Config {
public static function reload_config() {
global $CC_CONFIG;
public static function loadConfig($CC_CONFIG) {
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
// Name of the web server user
$CC_CONFIG['webServerUser'] = $values['general']['web_server_user'];
$CC_CONFIG['rabbitmq'] = $values['rabbitmq'];
$CC_CONFIG['baseUrl'] = $values['general']['base_url'];
$CC_CONFIG['basePort'] = $values['general']['base_port'];
$CC_CONFIG['baseFilesDir'] = $values['general']['base_files_dir'];
// main directory for storing binary media files
$CC_CONFIG['storageDir'] = $values['general']['base_files_dir']."/stor";
@ -111,5 +84,7 @@ class Config {
$CC_CONFIG['soundcloud-connection-retries'] = $values['soundcloud']['connection_retries'];
$CC_CONFIG['soundcloud-connection-wait'] = $values['soundcloud']['time_between_retries'];
return $CC_CONFIG;
}
}

View File

@ -1513,7 +1513,8 @@ class StoredFile {
public function getFileUrl()
{
global $CC_CONFIG;
return $this->gunid.".".$this->getFileExtension();
return "http://$CC_CONFIG[baseUrl]:$CC_CONFIG[basePort]/".$this->gunid.".".$this->getFileExtension();
//return $CC_CONFIG["base_url"]..$this->gunid.".".$this->getFileExtension();
}
/**

View File

@ -16,6 +16,8 @@ api_key = AAA
web_server_user = www-data
airtime_dir = x
base_files_dir = x
base_url = localhost
base_port = 80
[soundcloud]
connection_retries = 3

View File

@ -61,7 +61,7 @@ AirtimeInstall::InstallBinaries();
echo "* Initializing INI files".PHP_EOL;
AirtimeIni::UpdateIniFiles();
Config::reload_config();
Config::loadConfig();
echo "* Creating default storage directory".PHP_EOL;
AirtimeInstall::InstallStorageDirectory();

View File

@ -220,9 +220,9 @@ class AirTimeApiClient(ApiClientInterface):
logger = logging.getLogger()
try:
src = "http://%s:%s/%s/%s" % \
(self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["get_media_url"])
src = src.replace("%%file%%", uri)
#src = "http://%s:%s/%s/%s" % \
#(self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["get_media_url"])
src = uri
logger.info("try to download from %s to %s", src, dst)
src = src.replace("%%api_key%%", self.config["api_key"])
# check if file exists already before downloading again