Commit 33d2dda1 authored by Leo Iannacone's avatar Leo Iannacone

clean code with handlers .. use just one for generic cases

parent 9e0e02c6
...@@ -137,54 +137,42 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) { ...@@ -137,54 +137,42 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
}) })
} }
function __file_newcontent(event_name, socket, data) {
if(! utils.check_data_file(data))
return
data.file.content = null
socket.emit(event_name, data)
}
function __handler_get_distributions (socket, data) {
event_name = 'distributions'
__watch_path_onsocket(event_name,socket, data, config.debomatic.path, __send_distributions)
__send_distributions(event_name, socket, data)
}
function __handler_get_package_files_list (socket, data) {
event_name = 'package_files_list'
package_path = utils.get_package_path(data)
__watch_path_onsocket(event_name, socket, data, package_path, __send_package_files_list)
__send_package_files_list(event_name, socket, data)
}
function __handler_get_distribution_packages (socket, data) { function __generic_handler(event_name, socket, data, watch_path, callback) {
event_name = 'distribution_packages' __watch_path_onsocket(event_name, socket, data, config.debomatic.path, callback)
distribution_path = path.join(config.debomatic.path, data.distribution.name, 'pool') callback(event_name, socket, data)
__watch_path_onsocket(event_name, socket, data, distribution_path, __send_distribution_packages)
__send_distribution_packages(event_name, socket, data)
} }
function __handler_get_file (socket, data) { function __handler_get_file (socket, data) {
file_path = utils.get_file_path(data) file_path = utils.get_file_path(data)
__watch_path_onsocket('file_newcontent', socket, data, file_path, __file_newcontent) __watch_path_onsocket('file_newcontent', socket, data, file_path, __handler_file_newcontent)
__send_file('file', socket, data) __send_file('file', socket, data)
} }
function __handler_file_newcontent(event_name, socket, data) {
if(! utils.check_data_file(data))
return
data.file.content = null
socket.emit(event_name, data)
}
Client = function (socket) { Client = function (socket) {
__handler_get_distributions(socket); __generic_handler('distributions', socket, null, config.debomatic.path, __send_distributions)
// send distribution packages
socket.on('get_distribution_packages', function (data) { socket.on('get_distribution_packages', function (data) {
if (! utils.check_data_distribution(data)) if (! utils.check_data_distribution(data))
return return
__handler_get_distribution_packages(socket, data); distribution_path = path.join(config.debomatic.path, data.distribution.name, 'pool')
__generic_handler('distribution_packages', socket, data, distribution_path, __send_distribution_packages)
}) })
socket.on('get_package_files_list', function(data) { socket.on('get_package_files_list', function(data) {
if (! utils.check_data_package(data)) if (! utils.check_data_package(data))
return return
__handler_get_package_files_list(socket, data) package_path = utils.get_package_path(data)
__generic_handler('package_files_list', socket, data, package_path, __send_package_files_list)
}) })
socket.on('get_file', function (data){ socket.on('get_file', function (data){
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment