mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
ruby: Layout/ExtraSpacing correct
This commit is contained in:
@ -78,9 +78,9 @@ class HomeController < ApplicationController
|
|||||||
|
|
||||||
DocumentHelper.create_meta(file_name, user.id, user.name, nil)
|
DocumentHelper.create_meta(file_name, user.id, user.name, nil)
|
||||||
|
|
||||||
render plain: '{ "filename": "' + file_name + '", "documentType": "' + document_type + '"}' # write a new file name to the response
|
render plain: '{ "filename": "' + file_name + '", "documentType": "' + document_type + '"}' # write a new file name to the response
|
||||||
rescue => ex
|
rescue => ex
|
||||||
render plain: '{ "error": "' + ex.message + '"}' # write an error message to the response
|
render plain: '{ "error": "' + ex.message + '"}' # write an error message to the response
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -101,9 +101,9 @@ class HomeController < ApplicationController
|
|||||||
extension = File.extname(file_name).downcase
|
extension = File.extname(file_name).downcase
|
||||||
internal_extension = 'ooxml'
|
internal_extension = 'ooxml'
|
||||||
|
|
||||||
if DocumentHelper.convert_exts.include? (extension) # check if the file with such an extension can be converted
|
if DocumentHelper.convert_exts.include? (extension) # check if the file with such an extension can be converted
|
||||||
key = ServiceConverter.generate_revision_id(file_uri) # generate document key
|
key = ServiceConverter.generate_revision_id(file_uri) # generate document key
|
||||||
percent, new_file_uri, new_file_type = ServiceConverter.get_converted_data(file_uri, extension.delete('.'), internal_extension.delete('.'), key, true, file_pass, lang) # get the url and file type of the converted file and the conversion percentage
|
percent, new_file_uri, new_file_type = ServiceConverter.get_converted_data(file_uri, extension.delete('.'), internal_extension.delete('.'), key, true, file_pass, lang) # get the url and file type of the converted file and the conversion percentage
|
||||||
|
|
||||||
# if the conversion isn't completed, write file name and step values to the response
|
# if the conversion isn't completed, write file name and step values to the response
|
||||||
if percent != 100
|
if percent != 100
|
||||||
@ -114,12 +114,12 @@ class HomeController < ApplicationController
|
|||||||
# get the correct file name if such a name already exists
|
# get the correct file name if such a name already exists
|
||||||
correct_name = DocumentHelper.get_correct_name(File.basename(file_name, extension) + "." + new_file_type, nil)
|
correct_name = DocumentHelper.get_correct_name(File.basename(file_name, extension) + "." + new_file_type, nil)
|
||||||
|
|
||||||
uri = URI.parse(new_file_uri) # create the request url
|
uri = URI.parse(new_file_uri) # create the request url
|
||||||
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
||||||
|
|
||||||
DocumentHelper.verify_ssl(new_file_uri, http)
|
DocumentHelper.verify_ssl(new_file_uri, http)
|
||||||
|
|
||||||
req = Net::HTTP::Get.new(uri.request_uri) # create the get requets
|
req = Net::HTTP::Get.new(uri.request_uri) # create the get requets
|
||||||
res = http.request(req)
|
res = http.request(req)
|
||||||
data = res.body
|
data = res.body
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ class HomeController < ApplicationController
|
|||||||
file_name = correct_name
|
file_name = correct_name
|
||||||
user = Users.get_user(params[:userId])
|
user = Users.get_user(params[:userId])
|
||||||
|
|
||||||
DocumentHelper.create_meta(file_name, user.id, user.name, nil) # create meta data of the new file
|
DocumentHelper.create_meta(file_name, user.id, user.name, nil) # create meta data of the new file
|
||||||
end
|
end
|
||||||
|
|
||||||
render plain: '{ "filename" : "' + file_name + '"}'
|
render plain: '{ "filename" : "' + file_name + '"}'
|
||||||
@ -190,9 +190,9 @@ class HomeController < ApplicationController
|
|||||||
|
|
||||||
# tracking file changes
|
# tracking file changes
|
||||||
def track
|
def track
|
||||||
file_data = TrackHelper.read_body(request) # read the request body
|
file_data = TrackHelper.read_body(request) # read the request body
|
||||||
if file_data == nil || file_data.empty?
|
if file_data == nil || file_data.empty?
|
||||||
render plain: '{"error":1}' # an error occurs if the file is empty
|
render plain: '{"error":1}' # an error occurs if the file is empty
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -201,23 +201,23 @@ class HomeController < ApplicationController
|
|||||||
user_address = params[:userAddress]
|
user_address = params[:userAddress]
|
||||||
file_name = File.basename(params[:fileName])
|
file_name = File.basename(params[:fileName])
|
||||||
|
|
||||||
if status == 1 # editing
|
if status == 1 # editing
|
||||||
if file_data['actions'][0]['type'] == 0 # finished edit
|
if file_data['actions'][0]['type'] == 0 # finished edit
|
||||||
user = file_data['actions'][0]['userid'] # get the user id
|
user = file_data['actions'][0]['userid'] # get the user id
|
||||||
if !file_data['users'].index(user)
|
if !file_data['users'].index(user)
|
||||||
json_data = TrackHelper.command_request("forcesave", file_data['key']) # call the forcesave command
|
json_data = TrackHelper.command_request("forcesave", file_data['key']) # call the forcesave command
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if status == 2 || status == 3 # MustSave, Corrupted
|
if status == 2 || status == 3 # MustSave, Corrupted
|
||||||
saved = TrackHelper.process_save(file_data, file_name, user_address) # save file
|
saved = TrackHelper.process_save(file_data, file_name, user_address) # save file
|
||||||
render plain: '{"error":' + saved.to_s + '}'
|
render plain: '{"error":' + saved.to_s + '}'
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if status == 6 || status == 7 # MustForceave, CorruptedForcesave
|
if status == 6 || status == 7 # MustForceave, CorruptedForcesave
|
||||||
saved = TrackHelper.process_force_save(file_data, file_name, user_address) # force save file
|
saved = TrackHelper.process_force_save(file_data, file_name, user_address) # force save file
|
||||||
render plain: '{"error":' + saved.to_s + '}'
|
render plain: '{"error":' + saved.to_s + '}'
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -228,9 +228,9 @@ class HomeController < ApplicationController
|
|||||||
|
|
||||||
# removing a file
|
# removing a file
|
||||||
def remove
|
def remove
|
||||||
file_name = File.basename(params[:filename]) # get the file name
|
file_name = File.basename(params[:filename]) # get the file name
|
||||||
if !file_name # if it doesn't exist
|
if !file_name # if it doesn't exist
|
||||||
render plain: '{"success":false}' # report that the operation is unsuccessful
|
render plain: '{"success":false}' # report that the operation is unsuccessful
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -238,22 +238,22 @@ class HomeController < ApplicationController
|
|||||||
storage_path = DocumentHelper.storage_path(file_name, nil)
|
storage_path = DocumentHelper.storage_path(file_name, nil)
|
||||||
hist_dir = DocumentHelper.history_dir(storage_path)
|
hist_dir = DocumentHelper.history_dir(storage_path)
|
||||||
|
|
||||||
if File.exist?(storage_path) # if the file exists
|
if File.exist?(storage_path) # if the file exists
|
||||||
File.delete(storage_path) # delete it from the storage path
|
File.delete(storage_path) # delete it from the storage path
|
||||||
end
|
end
|
||||||
|
|
||||||
if Dir.exist?(hist_dir) # if the history directory of this file exists
|
if Dir.exist?(hist_dir) # if the history directory of this file exists
|
||||||
FileUtils.remove_entry_secure(hist_dir) # delete it
|
FileUtils.remove_entry_secure(hist_dir) # delete it
|
||||||
end
|
end
|
||||||
|
|
||||||
render plain: '{"success":true}' # report that the operation is successful
|
render plain: '{"success":true}' # report that the operation is successful
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# getting files information
|
# getting files information
|
||||||
def files
|
def files
|
||||||
file_id = params[:fileId]
|
file_id = params[:fileId]
|
||||||
filesInfo = DocumentHelper.get_files_info(file_id) # get the information about the file specified by a file id
|
filesInfo = DocumentHelper.get_files_info(file_id) # get the information about the file specified by a file id
|
||||||
render json: filesInfo
|
render json: filesInfo
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -290,9 +290,9 @@ class HomeController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
file_path = DocumentHelper.forcesave_path(file_name, user_address, false) # get the path to the force saved document version
|
file_path = DocumentHelper.forcesave_path(file_name, user_address, false) # get the path to the force saved document version
|
||||||
if file_path.eql?("")
|
if file_path.eql?("")
|
||||||
file_path = DocumentHelper.storage_path(file_name, user_address) # or to the original document
|
file_path = DocumentHelper.storage_path(file_name, user_address) # or to the original document
|
||||||
end
|
end
|
||||||
|
|
||||||
# add headers to the response to specify the page parameters
|
# add headers to the response to specify the page parameters
|
||||||
@ -321,12 +321,12 @@ class HomeController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
uri = URI.parse(file_url) # create the request url
|
uri = URI.parse(file_url) # create the request url
|
||||||
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
||||||
|
|
||||||
DocumentHelper.verify_ssl(file_url, http)
|
DocumentHelper.verify_ssl(file_url, http)
|
||||||
|
|
||||||
req = Net::HTTP::Get.new(uri.request_uri) # create the get requets
|
req = Net::HTTP::Get.new(uri.request_uri) # create the get requets
|
||||||
res = http.request(req)
|
res = http.request(req)
|
||||||
data = res.body
|
data = res.body
|
||||||
|
|
||||||
@ -339,7 +339,7 @@ class HomeController < ApplicationController
|
|||||||
file.write(data)
|
file.write(data)
|
||||||
end
|
end
|
||||||
user = Users.get_user(params[:userId])
|
user = Users.get_user(params[:userId])
|
||||||
DocumentHelper.create_meta(file_name, user.id, user.name, nil) # create meta data of the new file
|
DocumentHelper.create_meta(file_name, user.id, user.name, nil) # create meta data of the new file
|
||||||
|
|
||||||
render plain: '{"file" : "' + file_name + '"}'
|
render plain: '{"file" : "' + file_name + '"}'
|
||||||
return
|
return
|
||||||
|
|||||||
@ -93,16 +93,16 @@ class DocumentHelper
|
|||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
directory = File.join(directory,"#{File.basename(file_name)}-hist") # get the path to the history of the given file
|
directory = File.join(directory,"#{File.basename(file_name)}-hist") # get the path to the history of the given file
|
||||||
unless File.directory?(directory)
|
unless File.directory?(directory)
|
||||||
if create
|
if create
|
||||||
FileUtils.mkdir_p(directory) # create history directory if it doesn't exist
|
FileUtils.mkdir_p(directory) # create history directory if it doesn't exist
|
||||||
else
|
else
|
||||||
return "" # the history directory doesn't exist and we are not supposed to create it
|
return "" # the history directory doesn't exist and we are not supposed to create it
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
directory = File.join(directory, File.basename(file_name)) # get the path to the given file
|
directory = File.join(directory, File.basename(file_name)) # get the path to the given file
|
||||||
unless File.file?(directory)
|
unless File.file?(directory)
|
||||||
if !create
|
if !create
|
||||||
return ""
|
return ""
|
||||||
@ -136,12 +136,12 @@ class DocumentHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
ver = 1
|
ver = 1
|
||||||
Dir.foreach(hist_dir) {|e| # run through all the file versions
|
Dir.foreach(hist_dir) {|e| # run through all the file versions
|
||||||
next if e.eql?(".")
|
next if e.eql?(".")
|
||||||
next if e.eql?("..")
|
next if e.eql?("..")
|
||||||
|
|
||||||
if File.directory?(File.join(hist_dir, e))
|
if File.directory?(File.join(hist_dir, e))
|
||||||
ver += 1 # and count them
|
ver += 1 # and count them
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,14 +151,14 @@ class DocumentHelper
|
|||||||
# get the correct file name if such a name already exists
|
# get the correct file name if such a name already exists
|
||||||
def get_correct_name(file_name, user_address)
|
def get_correct_name(file_name, user_address)
|
||||||
maxName = 50
|
maxName = 50
|
||||||
ext = File.extname(file_name) # get file extension
|
ext = File.extname(file_name) # get file extension
|
||||||
# get file name without extension
|
# get file name without extension
|
||||||
base_name = File.basename(file_name, ext)[0...maxName] + (file_name.length > maxName ? '[...]' : '')
|
base_name = File.basename(file_name, ext)[0...maxName] + (file_name.length > maxName ? '[...]' : '')
|
||||||
name = base_name + ext.downcase # get full file name
|
name = base_name + ext.downcase # get full file name
|
||||||
index = 1
|
index = 1
|
||||||
|
|
||||||
while File.exist?(storage_path(name, user_address)) # if the file with such a name already exists in this directory
|
while File.exist?(storage_path(name, user_address)) # if the file with such a name already exists in this directory
|
||||||
name = base_name + ' (' + index.to_s + ')' + ext.downcase # add an index after its base name
|
name = base_name + ' (' + index.to_s + ')' + ext.downcase # add an index after its base name
|
||||||
index = index + 1
|
index = index + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -172,12 +172,12 @@ class DocumentHelper
|
|||||||
arr = [];
|
arr = [];
|
||||||
|
|
||||||
if Dir.exist?(directory)
|
if Dir.exist?(directory)
|
||||||
Dir.foreach(directory) {|e| # run through all the elements from the folder
|
Dir.foreach(directory) {|e| # run through all the elements from the folder
|
||||||
next if e.eql?(".")
|
next if e.eql?(".")
|
||||||
next if e.eql?("..")
|
next if e.eql?("..")
|
||||||
next if File.directory?(File.join(directory, e)) # if the element is a directory, skip it
|
next if File.directory?(File.join(directory, e)) # if the element is a directory, skip it
|
||||||
|
|
||||||
arr.push(e) # push the file to the array
|
arr.push(e) # push the file to the array
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ class DocumentHelper
|
|||||||
|
|
||||||
# create file meta information
|
# create file meta information
|
||||||
def create_meta(file_name, uid, uname, user_address)
|
def create_meta(file_name, uid, uname, user_address)
|
||||||
hist_dir = history_dir(storage_path(file_name, user_address)) # get the path to the file history
|
hist_dir = history_dir(storage_path(file_name, user_address)) # get the path to the file history
|
||||||
|
|
||||||
# write user name, user uid and the creation time to the json object
|
# write user name, user uid and the creation time to the json object
|
||||||
json = {
|
json = {
|
||||||
@ -204,9 +204,9 @@ class DocumentHelper
|
|||||||
# create demo document
|
# create demo document
|
||||||
def create_demo(file_ext, sample, user)
|
def create_demo(file_ext, sample, user)
|
||||||
demo_name = (sample == 'true' ? 'sample.' : 'new.') + file_ext
|
demo_name = (sample == 'true' ? 'sample.' : 'new.') + file_ext
|
||||||
file_name = get_correct_name(demo_name, nil) # get the correct file name if such a name already exists
|
file_name = get_correct_name(demo_name, nil) # get the correct file name if such a name already exists
|
||||||
|
|
||||||
src = Rails.root.join('assets', 'document-templates', sample == 'true' ? 'sample' : 'new', demo_name) # save sample document of a necessary extension to the storage directory
|
src = Rails.root.join('assets', 'document-templates', sample == 'true' ? 'sample' : 'new', demo_name) # save sample document of a necessary extension to the storage directory
|
||||||
dest = storage_path file_name, nil
|
dest = storage_path file_name, nil
|
||||||
|
|
||||||
FileUtils.cp src, dest
|
FileUtils.cp src, dest
|
||||||
@ -244,7 +244,7 @@ class DocumentHelper
|
|||||||
|
|
||||||
# get callback url
|
# get callback url
|
||||||
def get_callback(file_name)
|
def get_callback(file_name)
|
||||||
get_server_url(true) + '/track?fileName=' + ERB::Util.url_encode(file_name) + '&userAddress=' + cur_user_host_address(nil)
|
get_server_url(true) + '/track?fileName=' + ERB::Util.url_encode(file_name) + '&userAddress=' + cur_user_host_address(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
# get url to the created file
|
# get url to the created file
|
||||||
@ -255,7 +255,7 @@ class DocumentHelper
|
|||||||
# get url to download a file
|
# get url to download a file
|
||||||
def get_download_url(file_name, is_serverUrl=true)
|
def get_download_url(file_name, is_serverUrl=true)
|
||||||
user_host = is_serverUrl ? '&userAddress=' + cur_user_host_address(nil) : ""
|
user_host = is_serverUrl ? '&userAddress=' + cur_user_host_address(nil) : ""
|
||||||
get_server_url(is_serverUrl) + '/download?fileName=' + ERB::Util.url_encode(file_name) + user_host
|
get_server_url(is_serverUrl) + '/download?fileName=' + ERB::Util.url_encode(file_name) + user_host
|
||||||
end
|
end
|
||||||
|
|
||||||
# get internal file extension by its type
|
# get internal file extension by its type
|
||||||
@ -265,10 +265,10 @@ class DocumentHelper
|
|||||||
ext = '.docx'
|
ext = '.docx'
|
||||||
when 'cell' # .xlsx for cell type
|
when 'cell' # .xlsx for cell type
|
||||||
ext = '.xlsx'
|
ext = '.xlsx'
|
||||||
when 'slide' # .pptx for slide type
|
when 'slide' # .pptx for slide type
|
||||||
ext = '.pptx'
|
ext = '.pptx'
|
||||||
else
|
else
|
||||||
ext = '.docx' # the default value is .docx
|
ext = '.docx' # the default value is .docx
|
||||||
end
|
end
|
||||||
|
|
||||||
ext
|
ext
|
||||||
@ -282,10 +282,10 @@ class DocumentHelper
|
|||||||
full_path = path + 'file_docx.svg'
|
full_path = path + 'file_docx.svg'
|
||||||
when 'cell' # .xlsx for cell type
|
when 'cell' # .xlsx for cell type
|
||||||
full_path = path + 'file_xlsx.svg'
|
full_path = path + 'file_xlsx.svg'
|
||||||
when 'slide' # .pptx for slide type
|
when 'slide' # .pptx for slide type
|
||||||
full_path = path + 'file_pptx.svg'
|
full_path = path + 'file_pptx.svg'
|
||||||
else
|
else
|
||||||
full_path = path + 'file_docx.svg' # the default value is .docx
|
full_path = path + 'file_docx.svg' # the default value is .docx
|
||||||
end
|
end
|
||||||
|
|
||||||
full_path
|
full_path
|
||||||
@ -295,7 +295,7 @@ class DocumentHelper
|
|||||||
def get_files_info(file_id)
|
def get_files_info(file_id)
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
for fileName in get_stored_files(nil) # run through all the stored files from the folder
|
for fileName in get_stored_files(nil) # run through all the stored files from the folder
|
||||||
directory = storage_path(fileName, nil)
|
directory = storage_path(fileName, nil)
|
||||||
uri = cur_user_host_address(nil) + '/' + fileName
|
uri = cur_user_host_address(nil) + '/' + fileName
|
||||||
|
|
||||||
@ -309,11 +309,11 @@ class DocumentHelper
|
|||||||
"updated" => File.mtime(directory)
|
"updated" => File.mtime(directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
if file_id == nil # if file id is undefined
|
if file_id == nil # if file id is undefined
|
||||||
result.push(info) # push info object to the response array
|
result.push(info) # push info object to the response array
|
||||||
else # if file id is defined
|
else # if file id is defined
|
||||||
if file_id.eql?(info["id"]) # and it is equal to the document key value
|
if file_id.eql?(info["id"]) # and it is equal to the document key value
|
||||||
result.push(info) # response object will be equal to the info object
|
result.push(info) # response object will be equal to the info object
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class FileModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def type
|
def type
|
||||||
@type ? @type : "desktop" # the default platform type is desktop
|
@type ? @type : "desktop" # the default platform type is desktop
|
||||||
end
|
end
|
||||||
|
|
||||||
# get file extension from its name
|
# get file extension from its name
|
||||||
@ -60,8 +60,8 @@ class FileModel
|
|||||||
|
|
||||||
# generate the document key value
|
# generate the document key value
|
||||||
def key
|
def key
|
||||||
uri = DocumentHelper.cur_user_host_address(nil) + '/' + @file_name # get current user host address
|
uri = DocumentHelper.cur_user_host_address(nil) + '/' + @file_name # get current user host address
|
||||||
stat = File.mtime(DocumentHelper.storage_path(@file_name, nil)) # get the modification time of the given file
|
stat = File.mtime(DocumentHelper.storage_path(@file_name, nil)) # get the modification time of the given file
|
||||||
return ServiceConverter.generate_revision_id("#{uri}.#{stat.to_s}")
|
return ServiceConverter.generate_revision_id("#{uri}.#{stat.to_s}")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -87,13 +87,13 @@ class FileModel
|
|||||||
|
|
||||||
# get config parameters
|
# get config parameters
|
||||||
def get_config
|
def get_config
|
||||||
editorsmode = @mode ? @mode : "edit" # mode: view/edit/review/comment/fillForms/embedded
|
editorsmode = @mode ? @mode : "edit" # mode: view/edit/review/comment/fillForms/embedded
|
||||||
canEdit = DocumentHelper.edited_exts.include?(file_ext) # check if the document can be edited
|
canEdit = DocumentHelper.edited_exts.include?(file_ext) # check if the document can be edited
|
||||||
if (!canEdit && editorsmode.eql?("edit") || editorsmode.eql?("fillForms")) && DocumentHelper.fill_forms_exts.include?(file_ext)
|
if (!canEdit && editorsmode.eql?("edit") || editorsmode.eql?("fillForms")) && DocumentHelper.fill_forms_exts.include?(file_ext)
|
||||||
editorsmode = "fillForms"
|
editorsmode = "fillForms"
|
||||||
canEdit = true
|
canEdit = true
|
||||||
end
|
end
|
||||||
submitForm = editorsmode.eql?("fillForms") && @user.id.eql?("uid-1") && false # the Submit form button state
|
submitForm = editorsmode.eql?("fillForms") && @user.id.eql?("uid-1") && false # the Submit form button state
|
||||||
mode = canEdit && !editorsmode.eql?("view") ? "edit" : "view"
|
mode = canEdit && !editorsmode.eql?("view") ? "edit" : "view"
|
||||||
templatesImageUrl = DocumentHelper.get_template_image_url(document_type) # templates image url in the "From Template" section
|
templatesImageUrl = DocumentHelper.get_template_image_url(document_type) # templates image url in the "From Template" section
|
||||||
templates = [
|
templates = [
|
||||||
@ -123,11 +123,11 @@ class FileModel
|
|||||||
:uploaded => Time.now.to_s,
|
:uploaded => Time.now.to_s,
|
||||||
:favorite => @user.favorite
|
:favorite => @user.favorite
|
||||||
},
|
},
|
||||||
:permissions => { # the permission for the document to be edited and downloaded or not
|
:permissions => { # the permission for the document to be edited and downloaded or not
|
||||||
:comment => !editorsmode.eql?("view") && !editorsmode.eql?("fillForms") && !editorsmode.eql?("embedded") && !editorsmode.eql?("blockcontent"),
|
:comment => !editorsmode.eql?("view") && !editorsmode.eql?("fillForms") && !editorsmode.eql?("embedded") && !editorsmode.eql?("blockcontent"),
|
||||||
:copy => !@user.deniedPermissions.include?("copy"),
|
:copy => !@user.deniedPermissions.include?("copy"),
|
||||||
:download => !@user.deniedPermissions.include?("download"),
|
:download => !@user.deniedPermissions.include?("download"),
|
||||||
:edit => canEdit && (editorsmode.eql?("edit") || editorsmode.eql?("view") || editorsmode.eql?("filter") || editorsmode.eql?("blockcontent")),
|
:edit => canEdit && (editorsmode.eql?("edit") || editorsmode.eql?("view") || editorsmode.eql?("filter") || editorsmode.eql?("blockcontent")),
|
||||||
:print => !@user.deniedPermissions.include?("print"),
|
:print => !@user.deniedPermissions.include?("print"),
|
||||||
:fillForms => !editorsmode.eql?("view") && !editorsmode.eql?("comment") && !editorsmode.eql?("embedded") && !editorsmode.eql?("blockcontent"),
|
:fillForms => !editorsmode.eql?("view") && !editorsmode.eql?("comment") && !editorsmode.eql?("embedded") && !editorsmode.eql?("blockcontent"),
|
||||||
:modifyFilter => !editorsmode.eql?("filter"),
|
:modifyFilter => !editorsmode.eql?("filter"),
|
||||||
@ -148,31 +148,31 @@ class FileModel
|
|||||||
:actionLink => @action_data ? JSON.parse(@action_data) : nil,
|
:actionLink => @action_data ? JSON.parse(@action_data) : nil,
|
||||||
:mode => mode,
|
:mode => mode,
|
||||||
:lang => @lang ? @lang : "en",
|
:lang => @lang ? @lang : "en",
|
||||||
:callbackUrl => callback_url, # absolute URL to the document storage service
|
:callbackUrl => callback_url, # absolute URL to the document storage service
|
||||||
:coEditing => editorsmode.eql?("view") && @user.id.eql?("uid-0") ? {
|
:coEditing => editorsmode.eql?("view") && @user.id.eql?("uid-0") ? {
|
||||||
:mode => "strict",
|
:mode => "strict",
|
||||||
:change => false
|
:change => false
|
||||||
} : nil,
|
} : nil,
|
||||||
:createUrl => !@user.id.eql?("uid-0") ? create_url : nil,
|
:createUrl => !@user.id.eql?("uid-0") ? create_url : nil,
|
||||||
:templates => @user.templates ? templates : nil,
|
:templates => @user.templates ? templates : nil,
|
||||||
:user => { # the user currently viewing or editing the document
|
:user => { # the user currently viewing or editing the document
|
||||||
:id => !@user.id.eql?("uid-0") ? @user.id : nil,
|
:id => !@user.id.eql?("uid-0") ? @user.id : nil,
|
||||||
:name => @user.name,
|
:name => @user.name,
|
||||||
:group => @user.group,
|
:group => @user.group,
|
||||||
:image => @user.avatar ? "#{DocumentHelper.get_server_url(true)}/assets/#{@user.id}.png" : nil
|
:image => @user.avatar ? "#{DocumentHelper.get_server_url(true)}/assets/#{@user.id}.png" : nil
|
||||||
},
|
},
|
||||||
:embedded => { # the parameters for the embedded document type
|
:embedded => { # the parameters for the embedded document type
|
||||||
:saveUrl => download_url(false), # the absolute URL that will allow the document to be saved onto the user personal computer
|
:saveUrl => download_url(false), # the absolute URL that will allow the document to be saved onto the user personal computer
|
||||||
:embedUrl => download_url(false), # the absolute URL to the document serving as a source file for the document embedded into the web page
|
:embedUrl => download_url(false), # the absolute URL to the document serving as a source file for the document embedded into the web page
|
||||||
:shareUrl => download_url(false), # the absolute URL that will allow other users to share this document
|
:shareUrl => download_url(false), # the absolute URL that will allow other users to share this document
|
||||||
:toolbarDocked => "top" # the place for the embedded viewer toolbar (top or bottom)
|
:toolbarDocked => "top" # the place for the embedded viewer toolbar (top or bottom)
|
||||||
},
|
},
|
||||||
:customization => { # the parameters for the editor interface
|
:customization => { # the parameters for the editor interface
|
||||||
:about => true, # the About section display
|
:about => true, # the About section display
|
||||||
:comments => true,
|
:comments => true,
|
||||||
:feedback => true, # the Feedback & Support menu button display
|
:feedback => true, # the Feedback & Support menu button display
|
||||||
:forcesave => false, # adding the request for the forced file saving to the callback handler
|
:forcesave => false, # adding the request for the forced file saving to the callback handler
|
||||||
:submitForm => submitForm, # the Submit form button state
|
:submitForm => submitForm, # the Submit form button state
|
||||||
:goback => {
|
:goback => {
|
||||||
:url => DocumentHelper.get_server_url(false)
|
:url => DocumentHelper.get_server_url(false)
|
||||||
},
|
},
|
||||||
@ -180,8 +180,8 @@ class FileModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
||||||
config["token"] = JwtHelper.encode(config) # encode a payload object into a token and write it to the config
|
config["token"] = JwtHelper.encode(config) # encode a payload object into a token and write it to the config
|
||||||
end
|
end
|
||||||
|
|
||||||
return config
|
return config
|
||||||
@ -194,17 +194,17 @@ class FileModel
|
|||||||
doc_key = key()
|
doc_key = key()
|
||||||
doc_uri = file_uri()
|
doc_uri = file_uri()
|
||||||
|
|
||||||
hist_dir = DocumentHelper.history_dir(DocumentHelper.storage_path(@file_name, nil)) # get the path to the file history
|
hist_dir = DocumentHelper.history_dir(DocumentHelper.storage_path(@file_name, nil)) # get the path to the file history
|
||||||
cur_ver = DocumentHelper.get_file_version(hist_dir) # get the file version
|
cur_ver = DocumentHelper.get_file_version(hist_dir) # get the file version
|
||||||
|
|
||||||
if (cur_ver > 0) # if file was modified
|
if (cur_ver > 0) # if file was modified
|
||||||
hist = []
|
hist = []
|
||||||
histData = {}
|
histData = {}
|
||||||
|
|
||||||
for i in 1..cur_ver # run through all the file versions
|
for i in 1..cur_ver # run through all the file versions
|
||||||
obj = {}
|
obj = {}
|
||||||
dataObj = {}
|
dataObj = {}
|
||||||
ver_dir = DocumentHelper.version_dir(hist_dir, i) # get the path to the given file version
|
ver_dir = DocumentHelper.version_dir(hist_dir, i) # get the path to the given file version
|
||||||
|
|
||||||
# get document key
|
# get document key
|
||||||
cur_key = doc_key
|
cur_key = doc_key
|
||||||
@ -216,10 +216,10 @@ class FileModel
|
|||||||
obj["key"] = cur_key
|
obj["key"] = cur_key
|
||||||
obj["version"] = i
|
obj["version"] = i
|
||||||
|
|
||||||
if (i == 1) # check if the version number is equal to 1
|
if (i == 1) # check if the version number is equal to 1
|
||||||
if File.file?(File.join(hist_dir, "createdInfo.json")) # check if the createdInfo.json file with meta data exists
|
if File.file?(File.join(hist_dir, "createdInfo.json")) # check if the createdInfo.json file with meta data exists
|
||||||
File.open(File.join(hist_dir, "createdInfo.json"), 'r') do |file| # open it
|
File.open(File.join(hist_dir, "createdInfo.json"), 'r') do |file| # open it
|
||||||
cr_info = JSON.parse(file.read()) # parse the file content
|
cr_info = JSON.parse(file.read()) # parse the file content
|
||||||
|
|
||||||
# write information about changes to the object
|
# write information about changes to the object
|
||||||
obj["created"] = cr_info["created"]
|
obj["created"] = cr_info["created"]
|
||||||
@ -240,11 +240,11 @@ class FileModel
|
|||||||
end
|
end
|
||||||
dataObj["version"] = i
|
dataObj["version"] = i
|
||||||
|
|
||||||
if (i > 1) # check if the version number is greater than 1
|
if (i > 1) # check if the version number is greater than 1
|
||||||
changes = nil
|
changes = nil
|
||||||
change = nil
|
change = nil
|
||||||
File.open(File.join(DocumentHelper.version_dir(hist_dir, i - 1), "changes.json"), 'r') do |file| # get the path to the changes.json file
|
File.open(File.join(DocumentHelper.version_dir(hist_dir, i - 1), "changes.json"), 'r') do |file| # get the path to the changes.json file
|
||||||
changes = JSON.parse(file.read()) # and parse its content
|
changes = JSON.parse(file.read()) # and parse its content
|
||||||
end
|
end
|
||||||
|
|
||||||
change = changes["changes"][0]
|
change = changes["changes"][0]
|
||||||
@ -255,8 +255,8 @@ class FileModel
|
|||||||
obj["created"] = change ? change["created"] : nil
|
obj["created"] = change ? change["created"] : nil
|
||||||
obj["user"] = change ? change["user"] : nil
|
obj["user"] = change ? change["user"] : nil
|
||||||
|
|
||||||
prev = histData[(i - 2).to_s] # get the history data from the previous file version
|
prev = histData[(i - 2).to_s] # get the history data from the previous file version
|
||||||
dataObj["previous"] = is_enable_direct_url == true ? { # write key and url information about previous file version with optional direct url
|
dataObj["previous"] = is_enable_direct_url == true ? { # write key and url information about previous file version with optional direct url
|
||||||
:fileType => prev["fileType"],
|
:fileType => prev["fileType"],
|
||||||
:key => prev["key"],
|
:key => prev["key"],
|
||||||
:url => prev["url"],
|
:url => prev["url"],
|
||||||
@ -271,16 +271,16 @@ class FileModel
|
|||||||
dataObj["changesUrl"] = DocumentHelper.get_historypath_uri(file_name, i - 1, "diff.zip")
|
dataObj["changesUrl"] = DocumentHelper.get_historypath_uri(file_name, i - 1, "diff.zip")
|
||||||
end
|
end
|
||||||
|
|
||||||
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
||||||
dataObj["token"] = JwtHelper.encode(dataObj) # encode a payload object into a token and write it to the data object
|
dataObj["token"] = JwtHelper.encode(dataObj) # encode a payload object into a token and write it to the data object
|
||||||
end
|
end
|
||||||
|
|
||||||
hist.push(obj) # add object dictionary to the hist list
|
hist.push(obj) # add object dictionary to the hist list
|
||||||
histData[(i - 1).to_s] = dataObj # write data object information to the history data
|
histData[(i - 1).to_s] = dataObj # write data object information to the history data
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
:hist => { # write history information about the current file version to the hist
|
:hist => { # write history information about the current file version to the hist
|
||||||
:currentVersion => cur_ver,
|
:currentVersion => cur_ver,
|
||||||
:history => hist
|
:history => hist
|
||||||
},
|
},
|
||||||
@ -294,16 +294,16 @@ class FileModel
|
|||||||
# get image information
|
# get image information
|
||||||
def get_insert_image
|
def get_insert_image
|
||||||
insert_image = is_enable_direct_url == true ? {
|
insert_image = is_enable_direct_url == true ? {
|
||||||
:fileType => "png", # image file type
|
:fileType => "png", # image file type
|
||||||
:url => DocumentHelper.get_server_url(true) + "/assets/logo.png", # server url to the image
|
:url => DocumentHelper.get_server_url(true) + "/assets/logo.png", # server url to the image
|
||||||
:directUrl => DocumentHelper.get_server_url(false) + "/assets/logo.png" # direct url to the image
|
:directUrl => DocumentHelper.get_server_url(false) + "/assets/logo.png" # direct url to the image
|
||||||
} : {
|
} : {
|
||||||
:fileType => "png", # image file type
|
:fileType => "png", # image file type
|
||||||
:url => DocumentHelper.get_server_url(true) + "/assets/logo.png" # server url to the image
|
:url => DocumentHelper.get_server_url(true) + "/assets/logo.png" # server url to the image
|
||||||
}
|
}
|
||||||
|
|
||||||
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
||||||
insert_image["token"] = JwtHelper.encode(insert_image) # encode a payload object into a token and write it to the insert_image object
|
insert_image["token"] = JwtHelper.encode(insert_image) # encode a payload object into a token and write it to the insert_image object
|
||||||
end
|
end
|
||||||
|
|
||||||
return insert_image.to_json.tr("{", "").tr("}","")
|
return insert_image.to_json.tr("{", "").tr("}","")
|
||||||
@ -312,16 +312,16 @@ class FileModel
|
|||||||
# get compared file information
|
# get compared file information
|
||||||
def dataDocument
|
def dataDocument
|
||||||
compare_file = is_enable_direct_url == true ? {
|
compare_file = is_enable_direct_url == true ? {
|
||||||
:fileType => "docx", # file type
|
:fileType => "docx", # file type
|
||||||
:url => DocumentHelper.get_server_url(true) + "/asset?fileName=sample.docx", # server url to the compared file
|
:url => DocumentHelper.get_server_url(true) + "/asset?fileName=sample.docx", # server url to the compared file
|
||||||
:directUrl => DocumentHelper.get_server_url(false) + "/asset?fileName=sample.docx" # direct url to the compared file
|
:directUrl => DocumentHelper.get_server_url(false) + "/asset?fileName=sample.docx" # direct url to the compared file
|
||||||
} : {
|
} : {
|
||||||
:fileType => "docx", # file type
|
:fileType => "docx", # file type
|
||||||
:url => DocumentHelper.get_server_url(true) + "/asset?fileName=sample.docx" # server url to the compared file
|
:url => DocumentHelper.get_server_url(true) + "/asset?fileName=sample.docx" # server url to the compared file
|
||||||
}
|
}
|
||||||
|
|
||||||
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
||||||
compare_file["token"] = JwtHelper.encode(compare_file) # encode a payload object into a token and write it to the compare_file object
|
compare_file["token"] = JwtHelper.encode(compare_file) # encode a payload object into a token and write it to the compare_file object
|
||||||
end
|
end
|
||||||
|
|
||||||
return compare_file
|
return compare_file
|
||||||
@ -330,16 +330,16 @@ class FileModel
|
|||||||
# get mail merge recipients information
|
# get mail merge recipients information
|
||||||
def dataSpreadsheet
|
def dataSpreadsheet
|
||||||
dataSpreadsheet = is_enable_direct_url == true ? {
|
dataSpreadsheet = is_enable_direct_url == true ? {
|
||||||
:fileType => "csv", # file type
|
:fileType => "csv", # file type
|
||||||
:url => DocumentHelper.get_server_url(true) + "/csv", # server url to the mail merge recipients file
|
:url => DocumentHelper.get_server_url(true) + "/csv", # server url to the mail merge recipients file
|
||||||
:directUrl => DocumentHelper.get_server_url(false) + "/csv" # direct url to the mail merge recipients file
|
:directUrl => DocumentHelper.get_server_url(false) + "/csv" # direct url to the mail merge recipients file
|
||||||
} : {
|
} : {
|
||||||
:fileType => "csv", # file type
|
:fileType => "csv", # file type
|
||||||
:url => DocumentHelper.get_server_url(true) + "/csv" # server url to the mail merge recipients file
|
:url => DocumentHelper.get_server_url(true) + "/csv" # server url to the mail merge recipients file
|
||||||
}
|
}
|
||||||
|
|
||||||
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
if JwtHelper.is_enabled # check if a secret key to generate token exists or not
|
||||||
dataSpreadsheet["token"] = JwtHelper.encode(dataSpreadsheet) # encode a payload object into a token and write it to the dataSpreadsheet object
|
dataSpreadsheet["token"] = JwtHelper.encode(dataSpreadsheet) # encode a payload object into a token and write it to the dataSpreadsheet object
|
||||||
end
|
end
|
||||||
|
|
||||||
return dataSpreadsheet
|
return dataSpreadsheet
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class ServiceConverter
|
|||||||
|
|
||||||
# get the url of the converted file
|
# get the url of the converted file
|
||||||
def get_converted_data(document_uri, from_ext, to_ext, document_revision_id, is_async, file_pass, lang = nil)
|
def get_converted_data(document_uri, from_ext, to_ext, document_revision_id, is_async, file_pass, lang = nil)
|
||||||
from_ext = from_ext == nil ? File.extname(document_uri).downcase : from_ext # get the current document extension
|
from_ext = from_ext == nil ? File.extname(document_uri).downcase : from_ext # get the current document extension
|
||||||
|
|
||||||
# get the current document name or uuid
|
# get the current document name or uuid
|
||||||
title = File.basename(URI.parse(document_uri).path)
|
title = File.basename(URI.parse(document_uri).path)
|
||||||
@ -40,7 +40,7 @@ class ServiceConverter
|
|||||||
document_revision_id = document_revision_id.empty? ? document_uri : document_revision_id
|
document_revision_id = document_revision_id.empty? ? document_uri : document_revision_id
|
||||||
document_revision_id = generate_revision_id(document_revision_id)
|
document_revision_id = generate_revision_id(document_revision_id)
|
||||||
|
|
||||||
payload = { # write all the conversion parameters to the payload
|
payload = { # write all the conversion parameters to the payload
|
||||||
:async => is_async ? true : false,
|
:async => is_async ? true : false,
|
||||||
:url => document_uri,
|
:url => document_uri,
|
||||||
:outputtype => to_ext.delete('.'),
|
:outputtype => to_ext.delete('.'),
|
||||||
@ -54,52 +54,52 @@ class ServiceConverter
|
|||||||
data = nil
|
data = nil
|
||||||
begin
|
begin
|
||||||
|
|
||||||
uri = URI.parse(@@document_converter_url) # create the request url
|
uri = URI.parse(@@document_converter_url) # create the request url
|
||||||
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
||||||
|
|
||||||
DocumentHelper.verify_ssl(@@document_converter_url, http)
|
DocumentHelper.verify_ssl(@@document_converter_url, http)
|
||||||
|
|
||||||
http.read_timeout = @@convert_timeout
|
http.read_timeout = @@convert_timeout
|
||||||
http.open_timeout = 5
|
http.open_timeout = 5
|
||||||
req = Net::HTTP::Post.new(uri.request_uri) # create the post request
|
req = Net::HTTP::Post.new(uri.request_uri) # create the post request
|
||||||
req.add_field("Accept", "application/json") # set headers
|
req.add_field("Accept", "application/json") # set headers
|
||||||
req.add_field("Content-Type", "application/json")
|
req.add_field("Content-Type", "application/json")
|
||||||
|
|
||||||
if JwtHelper.is_enabled && JwtHelper.use_for_request # if the signature is enabled
|
if JwtHelper.is_enabled && JwtHelper.use_for_request # if the signature is enabled
|
||||||
payload["token"] = JwtHelper.encode(payload) # get token and save it to the payload
|
payload["token"] = JwtHelper.encode(payload) # get token and save it to the payload
|
||||||
jwtHeader = ServiceConverter.config_manager.jwt_header; # get signature authorization header
|
jwtHeader = ServiceConverter.config_manager.jwt_header; # get signature authorization header
|
||||||
req.add_field(jwtHeader, "Bearer #{JwtHelper.encode({ :payload => payload })}") # set it to the request with the Bearer prefix
|
req.add_field(jwtHeader, "Bearer #{JwtHelper.encode({ :payload => payload })}") # set it to the request with the Bearer prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
req.body = payload.to_json
|
req.body = payload.to_json
|
||||||
res = http.request(req) # get the response
|
res = http.request(req) # get the response
|
||||||
|
|
||||||
status_code = res.code.to_i
|
status_code = res.code.to_i
|
||||||
if status_code != 200 # checking status code
|
if status_code != 200 # checking status code
|
||||||
raise "Conversion service returned status: #{status_code}"
|
raise "Conversion service returned status: #{status_code}"
|
||||||
end
|
end
|
||||||
|
|
||||||
data = res.body # and take its body
|
data = res.body # and take its body
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
# try again
|
# try again
|
||||||
rescue => ex
|
rescue => ex
|
||||||
raise ex.message
|
raise ex.message
|
||||||
end
|
end
|
||||||
|
|
||||||
json_data = JSON.parse(data) # parse response body
|
json_data = JSON.parse(data) # parse response body
|
||||||
return get_response_data(json_data) # get response url
|
return get_response_data(json_data) # get response url
|
||||||
end
|
end
|
||||||
|
|
||||||
# generate the document key value
|
# generate the document key value
|
||||||
def generate_revision_id(expected_key)
|
def generate_revision_id(expected_key)
|
||||||
require 'zlib'
|
require 'zlib'
|
||||||
|
|
||||||
if expected_key.length > 20 # check if the expected key length is greater than 20
|
if expected_key.length > 20 # check if the expected key length is greater than 20
|
||||||
expected_key = (Zlib.crc32 expected_key).to_s # calculate 32-bit crc value from the expected key and turn it into the string
|
expected_key = (Zlib.crc32 expected_key).to_s # calculate 32-bit crc value from the expected key and turn it into the string
|
||||||
end
|
end
|
||||||
|
|
||||||
key = expected_key.gsub(/[^0-9a-zA-Z.=]/, '_')
|
key = expected_key.gsub(/[^0-9a-zA-Z.=]/, '_')
|
||||||
key[(key.length - [key.length, 20].min)..key.length] # the resulting key is of the length 20 or less
|
key[(key.length - [key.length, 20].min)..key.length] # the resulting key is of the length 20 or less
|
||||||
end
|
end
|
||||||
|
|
||||||
# create an error message for the error code
|
# create an error message for the error code
|
||||||
@ -127,7 +127,7 @@ class ServiceConverter
|
|||||||
when 0
|
when 0
|
||||||
# public const int c_nErrorNo = 0
|
# public const int c_nErrorNo = 0
|
||||||
else
|
else
|
||||||
error_message = 'ErrorCode = ' + error_code.to_s # default value for the error message
|
error_message = 'ErrorCode = ' + error_code.to_s # default value for the error message
|
||||||
end
|
end
|
||||||
|
|
||||||
raise error_message
|
raise error_message
|
||||||
@ -138,30 +138,30 @@ class ServiceConverter
|
|||||||
file_result = json_data
|
file_result = json_data
|
||||||
|
|
||||||
error_element = file_result['error']
|
error_element = file_result['error']
|
||||||
if error_element != nil # if an error occurs
|
if error_element != nil # if an error occurs
|
||||||
process_convert_service_responce_error(error_element.to_i) # get an error message
|
process_convert_service_responce_error(error_element.to_i) # get an error message
|
||||||
end
|
end
|
||||||
|
|
||||||
is_end_convert = file_result['endConvert'] # check if the conversion is completed
|
is_end_convert = file_result['endConvert'] # check if the conversion is completed
|
||||||
|
|
||||||
result_percent = 0 # the conversion percentage
|
result_percent = 0 # the conversion percentage
|
||||||
response_uri = ''
|
response_uri = ''
|
||||||
response_file_type = ''
|
response_file_type = ''
|
||||||
|
|
||||||
if is_end_convert # if the conversion is completed
|
if is_end_convert # if the conversion is completed
|
||||||
|
|
||||||
file_url_element = file_result['fileUrl']
|
file_url_element = file_result['fileUrl']
|
||||||
file_type_element = file_result['fileType']
|
file_type_element = file_result['fileType']
|
||||||
|
|
||||||
if file_url_element == nil # and the file url doesn't exist
|
if file_url_element == nil # and the file url doesn't exist
|
||||||
raise 'Invalid answer format' # get ann error message
|
raise 'Invalid answer format' # get ann error message
|
||||||
end
|
end
|
||||||
|
|
||||||
response_uri = file_url_element # otherwise, get the file url
|
response_uri = file_url_element # otherwise, get the file url
|
||||||
response_file_type = file_type_element # get the file type
|
response_file_type = file_type_element # get the file type
|
||||||
result_percent = 100
|
result_percent = 100
|
||||||
|
|
||||||
else # if the conversion isn't completed
|
else # if the conversion isn't completed
|
||||||
|
|
||||||
percent_element = file_result['percent'] # get the percentage value
|
percent_element = file_result['percent'] # get the percentage value
|
||||||
|
|
||||||
|
|||||||
@ -40,22 +40,22 @@ class TrackHelper
|
|||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
file_data = JSON.parse(body) # parse file data
|
file_data = JSON.parse(body) # parse file data
|
||||||
|
|
||||||
# check if a secret key to generate token exists or not
|
# check if a secret key to generate token exists or not
|
||||||
if JwtHelper.is_enabled && JwtHelper.use_for_request
|
if JwtHelper.is_enabled && JwtHelper.use_for_request
|
||||||
inHeader = false
|
inHeader = false
|
||||||
token = nil
|
token = nil
|
||||||
jwtHeader = TrackHelper.config_manager.jwt_header; # get the authorization header from the config
|
jwtHeader = TrackHelper.config_manager.jwt_header; # get the authorization header from the config
|
||||||
if file_data["token"] # if the token is in the body
|
if file_data["token"] # if the token is in the body
|
||||||
token = JwtHelper.decode(file_data["token"]) # decode a token into a payload object using a secret key
|
token = JwtHelper.decode(file_data["token"]) # decode a token into a payload object using a secret key
|
||||||
elsif request.headers[jwtHeader] # if the token is in the header
|
elsif request.headers[jwtHeader] # if the token is in the header
|
||||||
hdr = request.headers[jwtHeader]
|
hdr = request.headers[jwtHeader]
|
||||||
hdr.slice!(0, "Bearer ".length) # get token from it (after Bearer prefix)
|
hdr.slice!(0, "Bearer ".length) # get token from it (after Bearer prefix)
|
||||||
token = JwtHelper.decode(hdr) # decode a token into a payload object using a secret key
|
token = JwtHelper.decode(hdr) # decode a token into a payload object using a secret key
|
||||||
inHeader = true
|
inHeader = true
|
||||||
else
|
else
|
||||||
raise "Expected JWT" # token missing error message
|
raise "Expected JWT" # token missing error message
|
||||||
end
|
end
|
||||||
|
|
||||||
if !token || token.eql?("")
|
if !token || token.eql?("")
|
||||||
@ -108,9 +108,9 @@ class TrackHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
new_file_name = file_name
|
new_file_name = file_name
|
||||||
download_ext = "."+file_data['filetype'] # get the extension of the downloaded file
|
download_ext = "."+file_data['filetype'] # get the extension of the downloaded file
|
||||||
|
|
||||||
cur_ext = File.extname(file_name).downcase # get current file extension
|
cur_ext = File.extname(file_name).downcase # get current file extension
|
||||||
|
|
||||||
# convert downloaded file to the file with the current extension if these extensions aren't equal
|
# convert downloaded file to the file with the current extension if these extensions aren't equal
|
||||||
unless cur_ext.eql?(download_ext)
|
unless cur_ext.eql?(download_ext)
|
||||||
@ -135,16 +135,16 @@ class TrackHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
storage_path = DocumentHelper.storage_path(new_file_name, user_address) # get the storage directory of the new file
|
storage_path = DocumentHelper.storage_path(new_file_name, user_address) # get the storage directory of the new file
|
||||||
|
|
||||||
hist_dir = DocumentHelper.history_dir(storage_path) # get the history directory of the new file
|
hist_dir = DocumentHelper.history_dir(storage_path) # get the history directory of the new file
|
||||||
ver_dir = DocumentHelper.version_dir(hist_dir, DocumentHelper.get_file_version(hist_dir)) # get the path to the specified file version
|
ver_dir = DocumentHelper.version_dir(hist_dir, DocumentHelper.get_file_version(hist_dir)) # get the path to the specified file version
|
||||||
|
|
||||||
FileUtils.mkdir_p(ver_dir) # create the version directory if doesn't exist
|
FileUtils.mkdir_p(ver_dir) # create the version directory if doesn't exist
|
||||||
|
|
||||||
FileUtils.move(DocumentHelper.storage_path(file_name, user_address), File.join(ver_dir, "prev#{cur_ext}")) # move the file from the storage directory to the previous file version directory
|
FileUtils.move(DocumentHelper.storage_path(file_name, user_address), File.join(ver_dir, "prev#{cur_ext}")) # move the file from the storage directory to the previous file version directory
|
||||||
|
|
||||||
save_file(data, storage_path) # save the downloaded file to the storage directory
|
save_file(data, storage_path) # save the downloaded file to the storage directory
|
||||||
|
|
||||||
change_data = download_file(file_data["changesurl"]) # download file with document versions differences
|
change_data = download_file(file_data["changesurl"]) # download file with document versions differences
|
||||||
save_file(change_data, File.join(ver_dir, "diff.zip")) # save file with document versions differences
|
save_file(change_data, File.join(ver_dir, "diff.zip")) # save file with document versions differences
|
||||||
@ -154,8 +154,8 @@ class TrackHelper
|
|||||||
hist_data = file_data["history"].to_json # write the original history information to the history data
|
hist_data = file_data["history"].to_json # write the original history information to the history data
|
||||||
end
|
end
|
||||||
if hist_data
|
if hist_data
|
||||||
File.open(File.join(ver_dir, "changes.json"), 'wb') do |file| # open the file with document changes
|
File.open(File.join(ver_dir, "changes.json"), 'wb') do |file| # open the file with document changes
|
||||||
file.write(hist_data) # and write history data to this file
|
file.write(hist_data) # and write history data to this file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ class TrackHelper
|
|||||||
file.write(file_data["key"])
|
file.write(file_data["key"])
|
||||||
end
|
end
|
||||||
|
|
||||||
forcesave_path = DocumentHelper.forcesave_path(new_file_name, user_address, false) # get the path to the forcesaved file
|
forcesave_path = DocumentHelper.forcesave_path(new_file_name, user_address, false) # get the path to the forcesaved file
|
||||||
unless forcesave_path.eql?("") # if this path is empty
|
unless forcesave_path.eql?("") # if this path is empty
|
||||||
File.delete(forcesave_path) # remove it
|
File.delete(forcesave_path) # remove it
|
||||||
end
|
end
|
||||||
@ -185,9 +185,9 @@ class TrackHelper
|
|||||||
return saved
|
return saved
|
||||||
end
|
end
|
||||||
|
|
||||||
download_ext = "."+file_data['filetype'] # get the extension of the downloaded file
|
download_ext = "."+file_data['filetype'] # get the extension of the downloaded file
|
||||||
|
|
||||||
cur_ext = File.extname(file_name).downcase # get current file extension
|
cur_ext = File.extname(file_name).downcase # get current file extension
|
||||||
|
|
||||||
new_file_name = false
|
new_file_name = false
|
||||||
|
|
||||||
@ -214,30 +214,30 @@ class TrackHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
is_submit_form = file_data["forcesavetype"].to_i == 3 # check if the forcesave type is equal to 3 (the form was submitted)
|
is_submit_form = file_data["forcesavetype"].to_i == 3 # check if the forcesave type is equal to 3 (the form was submitted)
|
||||||
|
|
||||||
if is_submit_form
|
if is_submit_form
|
||||||
if new_file_name
|
if new_file_name
|
||||||
file_name = DocumentHelper.get_correct_name(File.basename(file_name, cur_ext) + "-form" + download_ext, user_address) # get the correct file name if it already exists
|
file_name = DocumentHelper.get_correct_name(File.basename(file_name, cur_ext) + "-form" + download_ext, user_address) # get the correct file name if it already exists
|
||||||
else
|
else
|
||||||
file_name = DocumentHelper.get_correct_name(File.basename(file_name, cur_ext) + "-form" + cur_ext, user_address)
|
file_name = DocumentHelper.get_correct_name(File.basename(file_name, cur_ext) + "-form" + cur_ext, user_address)
|
||||||
end
|
end
|
||||||
forcesave_path = DocumentHelper.storage_path(file_name, user_address) # get the path to the new file
|
forcesave_path = DocumentHelper.storage_path(file_name, user_address) # get the path to the new file
|
||||||
else
|
else
|
||||||
if new_file_name
|
if new_file_name
|
||||||
file_name = DocumentHelper.get_correct_name(File.basename(file_name, cur_ext) + download_ext, user_address)
|
file_name = DocumentHelper.get_correct_name(File.basename(file_name, cur_ext) + download_ext, user_address)
|
||||||
end
|
end
|
||||||
forcesave_path = DocumentHelper.forcesave_path(file_name, user_address, false)
|
forcesave_path = DocumentHelper.forcesave_path(file_name, user_address, false)
|
||||||
if forcesave_path.eql?("")
|
if forcesave_path.eql?("")
|
||||||
forcesave_path = DocumentHelper.forcesave_path(file_name, user_address, true) # if the path to the new file doesn't exist, create it
|
forcesave_path = DocumentHelper.forcesave_path(file_name, user_address, true) # if the path to the new file doesn't exist, create it
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
save_file(data, forcesave_path) # save the downloaded file to the storage directory
|
save_file(data, forcesave_path) # save the downloaded file to the storage directory
|
||||||
|
|
||||||
if is_submit_form
|
if is_submit_form
|
||||||
uid = file_data['actions'][0]['userid']
|
uid = file_data['actions'][0]['userid']
|
||||||
DocumentHelper.create_meta(file_name, uid, "Filling Form", user_address) # create file meta information with the Filling form tag instead of user name
|
DocumentHelper.create_meta(file_name, uid, "Filling Form", user_address) # create file meta information with the Filling form tag instead of user name
|
||||||
end
|
end
|
||||||
|
|
||||||
saved = 0
|
saved = 0
|
||||||
@ -263,35 +263,35 @@ class TrackHelper
|
|||||||
data = nil
|
data = nil
|
||||||
begin
|
begin
|
||||||
|
|
||||||
uri = URI.parse(@@document_command_url) # parse the document command url
|
uri = URI.parse(@@document_command_url) # parse the document command url
|
||||||
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
||||||
|
|
||||||
DocumentHelper.verify_ssl(@@document_command_url, http)
|
DocumentHelper.verify_ssl(@@document_command_url, http)
|
||||||
|
|
||||||
req = Net::HTTP::Post.new(uri.request_uri) # create the post request
|
req = Net::HTTP::Post.new(uri.request_uri) # create the post request
|
||||||
req.add_field("Content-Type", "application/json") # set headers
|
req.add_field("Content-Type", "application/json") # set headers
|
||||||
|
|
||||||
if JwtHelper.is_enabled && JwtHelper.use_for_request # if the signature is enabled
|
if JwtHelper.is_enabled && JwtHelper.use_for_request # if the signature is enabled
|
||||||
payload["token"] = JwtHelper.encode(payload) # get token and save it to the payload
|
payload["token"] = JwtHelper.encode(payload) # get token and save it to the payload
|
||||||
jwtHeader = TrackHelper.config_manager.jwt_header; # get signature authorization header
|
jwtHeader = TrackHelper.config_manager.jwt_header; # get signature authorization header
|
||||||
req.add_field(jwtHeader, "Bearer #{JwtHelper.encode({ :payload => payload })}") # set it to the request with the Bearer prefix
|
req.add_field(jwtHeader, "Bearer #{JwtHelper.encode({ :payload => payload })}") # set it to the request with the Bearer prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
req.body = payload.to_json # convert the payload object into the json format
|
req.body = payload.to_json # convert the payload object into the json format
|
||||||
res = http.request(req) # get the response
|
res = http.request(req) # get the response
|
||||||
data = res.body # and take its body
|
data = res.body # and take its body
|
||||||
rescue => ex
|
rescue => ex
|
||||||
raise ex.message
|
raise ex.message
|
||||||
end
|
end
|
||||||
|
|
||||||
json_data = JSON.parse(data) # convert the response body into the json format
|
json_data = JSON.parse(data) # convert the response body into the json format
|
||||||
return json_data
|
return json_data
|
||||||
end
|
end
|
||||||
|
|
||||||
# save file from the url
|
# save file from the url
|
||||||
def download_file(uristr)
|
def download_file(uristr)
|
||||||
uri = URI.parse(uristr) # parse the url string
|
uri = URI.parse(uristr) # parse the url string
|
||||||
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
http = Net::HTTP.new(uri.host, uri.port) # create a connection to the http server
|
||||||
http.open_timeout = 5
|
http.open_timeout = 5
|
||||||
|
|
||||||
DocumentHelper.verify_ssl(uristr, http)
|
DocumentHelper.verify_ssl(uristr, http)
|
||||||
@ -304,7 +304,7 @@ class TrackHelper
|
|||||||
raise "Document editing service returned status: #{status_code}"
|
raise "Document editing service returned status: #{status_code}"
|
||||||
end
|
end
|
||||||
|
|
||||||
data = res.body # and take its body
|
data = res.body # and take its body
|
||||||
|
|
||||||
if data == nil
|
if data == nil
|
||||||
raise 'stream is null'
|
raise 'stream is null'
|
||||||
@ -314,7 +314,7 @@ class TrackHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def save_file(data, path)
|
def save_file(data, path)
|
||||||
File.open(path, 'wb') do |file| # open the file from the path specified
|
File.open(path, 'wb') do |file| # open the file from the path specified
|
||||||
file.write(data) # and write the response data to it
|
file.write(data) # and write the response data to it
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -110,11 +110,11 @@ class Users
|
|||||||
]
|
]
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def get_all_users() # get a list of all the users
|
def get_all_users() # get a list of all the users
|
||||||
@@users
|
@@users
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_user(id) # get a user by id specified
|
def get_user(id) # get a user by id specified
|
||||||
for user in @@users do
|
for user in @@users do
|
||||||
if user.id.eql?(id)
|
if user.id.eql?(id)
|
||||||
return user
|
return user
|
||||||
@ -123,7 +123,7 @@ class Users
|
|||||||
return @@users[0]
|
return @@users[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_users_for_mentions(id) # get a list of users with their names and emails for mentions
|
def get_users_for_mentions(id) # get a list of users with their names and emails for mentions
|
||||||
usersData = []
|
usersData = []
|
||||||
for user in @@users do
|
for user in @@users do
|
||||||
if (!user.id.eql?(id) && user.name != nil && user.email != nil)
|
if (!user.id.eql?(id) && user.name != nil && user.email != nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user