37 lines
1.7 KiB
Ruby
37 lines
1.7 KiB
Ruby
class RulingTemplatesController < ApplicationController
|
|
def index
|
|
store_token = params[:store_token]
|
|
site_domain = RegisteredSite.find_by(:uid => store_token).site_domain
|
|
root_domain = site_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
|
|
root_domain2 = root_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
|
|
templates = RTemplate.where(:allow_domain.in => [site_domain,root_domain,root_domain2,'',nil]).asc(:updated_at).collect do |v|
|
|
{
|
|
'install_flag' => v.installed_site_tokens.include?(store_token),
|
|
'uid' => v.uid,
|
|
'title' => v.title,
|
|
'desc' => v.description,
|
|
'images' => v.template_image_files.collect{|v| v.image_file.url}
|
|
}
|
|
end
|
|
render :json => templates.to_json
|
|
end
|
|
def get_template_zip
|
|
template_uid = params[:template_uid]
|
|
store_token = params[:store_token]
|
|
site_domain = RegisteredSite.find_by(:uid => store_token).site_domain
|
|
root_domain = site_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
|
|
root_domain2 = root_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
|
|
r_template = RTemplate.where(:allow_domain.in => [site_domain,root_domain,root_domain2,'',nil], uid: template_uid).first
|
|
if r_template.nil?
|
|
render :json => {}.to_json
|
|
else
|
|
r_template.installed_site_tokens << store_token
|
|
r_template.save
|
|
if r_template.git_url.blank?
|
|
render :json => {url: r_template.template_zip.url,type: 'zip'}.to_json
|
|
else
|
|
render :json => {url: r_template.git_url+'.git',branch: r_template.git_branch,type: 'git'}.to_json
|
|
end
|
|
end
|
|
end
|
|
end |