33 lines
1.4 KiB
Ruby
33 lines
1.4 KiB
Ruby
class RulingTemplatesController < ApplicationController
|
|
def index
|
|
store_token = params[:store_token]
|
|
site_domain = RegisteredSite.find_by(:uid => store_token).site_domain.sub(/(?:(?!\.).)*\./,'') rescue ''
|
|
templates = RTemplate.where(allow_domain: site_domain,:git_url.ne=> '').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.sub(/(?:(?!\.).)*\./,'') rescue ''
|
|
r_template = RTemplate.where(allow_domain: site_domain, 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,branch: r_template.git_branch,type: 'git'}.to_json
|
|
end
|
|
end
|
|
end
|
|
end |