some refactoring of store url object

This commit is contained in:
Saurabh Bhatia 2014-02-17 11:33:18 +08:00
parent bf532bfea9
commit b47bd031f2
2 changed files with 10 additions and 19 deletions

View File

@ -1,6 +1,5 @@
class Admin::ModuleStoreController < OrbitBackendController class Admin::ModuleStoreController < OrbitBackendController
before_filter :check_central_server_connection, :only => [:get_extensions] before_filter :check_central_server_connection, :only => [:get_extensions]
@@store = STORE_CONFIG[:store_settings]["url"]
def index def index
@extensions = get_extensions @extensions = get_extensions

View File

@ -3,24 +3,22 @@ require 'uri'
require 'fileutils' require 'fileutils'
require 'zip/zip' require 'zip/zip'
class Admin::TemplateStoreController < OrbitBackendController class Admin::TemplateStoreController < OrbitBackendController
before_filter :check_central_server_connection, :only => [:get_extensions] before_filter :check_central_server_connection, :only => [:get_templates]
before_filter :set_store
@@store_domain = STORE_CONFIG[:store_settings]["url"]
def index def index
@store_url = @@store_domain
@design_ids = Design.all.map{|d| d.template_store_id} @design_ids = Design.all.map{|d| d.template_store_id}
@templates = get_templates.parsed_response @templates = get_templates.parsed_response
render :layout => false render :layout => false
end end
def show def show
@store = @@store_domain
@design_ids = Design.all.map{|d| d.template_store_id} @design_ids = Design.all.map{|d| d.template_store_id}
@template = get_template(params[:id]).parsed_response rescue nil @template = get_template(params[:id]).parsed_response rescue nil
end end
def download_theme def download_theme
url = @@store_domain + params["url"] url = @store_url + params["url"]
url_base = url.split('/')[2] url_base = url.split('/')[2]
url_path = '/'+url.split('/')[3..-1].join('/') url_path = '/'+url.split('/')[3..-1].join('/')
Net::HTTP.start(url_base) do |http| Net::HTTP.start(url_base) do |http|
@ -32,7 +30,7 @@ class Admin::TemplateStoreController < OrbitBackendController
end end
upload_package("#{params['slug']}.zip", params["id"]) upload_package("#{params['slug']}.zip", params["id"])
File.delete("public/#{params['slug']}.zip") File.delete("public/#{params['slug']}.zip")
render :json => {"success"=>true,"url"=>@@store_domain + params["url"]}.to_json render :json => {"success"=>true,"url"=>@store_url + params["url"]}.to_json
end end
protected protected
@ -93,20 +91,14 @@ class Admin::TemplateStoreController < OrbitBackendController
def get_template(id) def get_template(id)
store_session.get_template(id) store_session.get_template(id)
# uri = URI.parse("#{@@store_domain}/api/templates/#{id}")
# http = Net::HTTP.new(uri.host, uri.port)
# request = Net::HTTP::Get.new(uri.request_uri)
# response = http.request(request)
# response.body
end end
def get_templates def get_templates
extensions = store_session.templates store_session.templates
# uri = URI.parse("#{@@store_domain}/api/templates") end
# http = Net::HTTP.new(uri.host, uri.port)
# request = Net::HTTP::Get.new(uri.request_uri) def set_store
# response = http.request(request) @store_url = STORE_CONFIG[:store_settings]["url"]
# response.body
end end
end end