jam-cloud/web/app/controllers/artifacts_controller.rb

94 lines
2.9 KiB
Ruby
Raw Permalink Normal View History

class ArtifactsController < ApiController
respond_to :json
2013-01-30 03:36:19 +00:00
# retrieve all available client downloads
def client_downloads
# jamblaster specifies this params[:type]
is_jamblaster = params[:type] && params[:serialno]
2016-07-09 11:06:54 +00:00
if is_jamblaster
# check and see if there is a build just for this JB
2017-01-06 12:43:38 +00:00
clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}", params[:serialno]).order(:product)
if clients.count == 0
# if not, then fine, give back the default environment
2017-01-06 12:43:38 +00:00
clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}", ArtifactUpdate::DEFAULT_ENVIRONMENT).order(:product)
2016-07-09 11:06:54 +00:00
end
else
if params[:type]
clients = ArtifactUpdate.where("product like ? and environment = '#{ArtifactUpdate::DEFAULT_ENVIRONMENT}'", "%" + params[:type] + "%").order(:product)
else
clients = ArtifactUpdate.where("product like '%JamClient%' and environment = '#{ArtifactUpdate::DEFAULT_ENVIRONMENT}'").order(:product)
end
end
if is_jamblaster && params[:serialno]
Jamblaster.bootstrap(params[:serialno])
end
2016-07-09 11:06:54 +00:00
#Parameters: {"serialno"=>"NCA-001-160602-00084", "version"=>"dev-20161120-153542", "type"=>"jamblaster"}
#Parameters: {"serialno"=>"NCA-001-160602-00084", "version"=>"dev-20161120-153542", "type"=>"jamblasterclient"}
result = {}
clients.each do |client|
url = client.determine_url
# jamblaster specifies this params[:type]
if is_jamblaster
result[params[:type]] = { :uri => url, :size => client.size, :version => client.version, :md5 => client.sha1}
else
result[client.product] = { :uri => url, :size => client.size, :version => client.version, :md5 => client.sha1}
end
end
render :json => result, :status => :ok
end
def healthcheck
render :json => {}
end
2013-06-26 14:54:58 +00:00
2013-01-30 03:36:19 +00:00
def versioncheck
# the reported client version
#client_version = params[:ver]
2013-01-30 03:36:19 +00:00
# the name of the client, i.e.JamClient
2013-01-30 03:36:19 +00:00
product = params[:product]
# the os (Win32/MacOSX/Unix)
os = params[:os]
product = "#{product}/#{os}"
logger.debug "version check from #{product}"
2013-01-31 05:43:26 +00:00
2013-01-30 03:36:19 +00:00
unless ArtifactUpdate::PRODUCTS.include? product
render :json => { :errors => { :product => ['not a valid product'] } }, :status => :unprocessable_entity
2013-01-30 03:36:19 +00:00
return
end
@artifact = ArtifactUpdate.find_by_product_and_environment(product, ArtifactUpdate::DEFAULT_ENVIRONMENT)
if @artifact.nil?
render :json => {}, :status => :ok
2013-01-30 03:36:19 +00:00
else
url = @artifact.determine_url
2020-12-03 16:34:59 +00:00
# client can't deal with https
if url.start_with?('https://')
url = url.gsub('https://' ,'http://')
end
render :json => { "version" => @artifact.version, "uri" => url, "sha1" => @artifact.sha1, "size" => @artifact.size }, :status => :ok
2013-01-30 03:36:19 +00:00
end
end
end