Archived
Integration of module_app workflow
This commit is contained in:
1 parent
65349796d0
commit
dac6348402
8 files changed
+71
-8
No files matched your search
@@ -43,7 +43,12 @@ class Admin::PurchasesController < ApplicationController
|
||||
temp_file.write response.body
|
||||
temp_file.rewind
|
||||
zip_name = response['content-disposition'].split('filename=')[1].gsub(/[\\\"]|.zip/, '') rescue ''
|
||||
unzip_design(temp_file, zip_name)
|
||||
case purchase._type
|
||||
when 'Pdesign'
|
||||
unzip_design(temp_file, zip_name)
|
||||
when 'PModuleApp'
|
||||
unzip_module_app(temp_file, zip_name)
|
||||
end
|
||||
temp_file.close
|
||||
temp_file.unlink
|
||||
end
|
||||
@@ -113,6 +118,59 @@ class Admin::PurchasesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def unzip_module_app(file, zip_name)
|
||||
destination = "#{Rails.root}/vendor/plugins"
|
||||
Zip::ZipFile.open(file) do |zip_file|
|
||||
encrypted = {}
|
||||
['encrypted_data', 'encrypted_key', 'encrypted_iv'].each do |e|
|
||||
encrypted.merge!(e => zip_file.read(e))
|
||||
end
|
||||
orig_file = decrypt_data(encrypted['encrypted_data'], encrypted['encrypted_key'], encrypted['encrypted_iv'])
|
||||
|
||||
temp_file = Tempfile.new("temp_file_zip")
|
||||
temp_file.binmode
|
||||
temp_file.write orig_file
|
||||
temp_file.rewind
|
||||
|
||||
Zip::ZipFile.open(temp_file) { |orig_zip|
|
||||
module_app = ModuleApp.new.from_json(orig_zip.read("#{zip_name}/#{zip_name}.json"))
|
||||
orig_zip.remove("#{zip_name}/#{zip_name}.json")
|
||||
|
||||
orig_zip.each do |orig|
|
||||
inner_temp_file = Tempfile.new("inner_temp_file_zip")
|
||||
inner_temp_file.binmode
|
||||
inner_temp_file.write orig_zip.read(orig)
|
||||
inner_temp_file.rewind
|
||||
|
||||
Zip::ZipFile.open(inner_temp_file) {|inner_zip|
|
||||
inner_zip.each do |f|
|
||||
if (f.to_s=~/^#{zip_name}\/*/)
|
||||
f_path = File.join(destination, f.name)
|
||||
FileUtils.mkdir_p(File.dirname(f_path))
|
||||
inner_zip.extract(f, f_path) unless File.exist?(f_path)
|
||||
end
|
||||
end
|
||||
}
|
||||
inner_temp_file.close
|
||||
inner_temp_file.unlink
|
||||
end
|
||||
|
||||
module_app.save
|
||||
|
||||
log = Logger.new(STDOUT)
|
||||
log.level = Logger::WARN
|
||||
log.warn("App unzip procress is finished,please restart the server to apply effect")
|
||||
}
|
||||
|
||||
temp_file.close
|
||||
temp_file.unlink
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def build_file(orig_zip, zip_name, dir, object, type = nil)
|
||||
title = object.file_filename
|
||||
temp = File.new(dir + '/' + title, 'w+')
|
||||
|
||||
Reference in new issue
Block a user