mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
Ruby: Merge jwt prev + diff
This commit is contained in:
@ -152,9 +152,11 @@ class HomeController < ApplicationController
|
|||||||
# downloading a history file from public
|
# downloading a history file from public
|
||||||
def downloadhistory
|
def downloadhistory
|
||||||
begin
|
begin
|
||||||
dataurl = request.original_url.split('/')
|
file_name = File.basename(params[:fileName])
|
||||||
|
user_address = params[:userAddress]
|
||||||
file_path = Rails.root.join('public', Rails.configuration.storagePath, dataurl[4], dataurl[5], dataurl[6], dataurl[7])
|
version = params[:ver]
|
||||||
|
file = params[:file]
|
||||||
|
isEmbedded = params[:dmode]
|
||||||
|
|
||||||
if JwtHelper.is_enabled
|
if JwtHelper.is_enabled
|
||||||
jwtHeader = Rails.configuration.header.empty? ? "Authorization" : Rails.configuration.header;
|
jwtHeader = Rails.configuration.header.empty? ? "Authorization" : Rails.configuration.header;
|
||||||
@ -171,6 +173,15 @@ class HomeController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
hist_path = DocumentHelper.storage_path(file_name, user_address) + "-hist" # or to the original document
|
||||||
|
|
||||||
|
file_path = File.join(hist_path, version, file)
|
||||||
|
|
||||||
|
# add headers to the response to specify the page parameters
|
||||||
|
response.headers['Content-Length'] = File.size(file_path).to_s
|
||||||
|
response.headers['Content-Type'] = MimeMagic.by_path(file_path).eql?(nil) ? nil : MimeMagic.by_path(file_path).type
|
||||||
|
response.headers['Content-Disposition'] = "attachment;filename*=UTF-8\'\'" + URI.escape(file, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
||||||
|
|
||||||
send_file file_path, :x_sendfile => true
|
send_file file_path, :x_sendfile => true
|
||||||
rescue => ex
|
rescue => ex
|
||||||
render plain: '{ "error": "File not found"}'
|
render plain: '{ "error": "File not found"}'
|
||||||
|
|||||||
@ -235,11 +235,10 @@ class DocumentHelper
|
|||||||
return uri
|
return uri
|
||||||
end
|
end
|
||||||
|
|
||||||
# get path url
|
# get history path url
|
||||||
def get_path_uri(path)
|
def get_historypath_uri(file_name,version,file)
|
||||||
# uri = get_server_url(true) + '/' + Rails.configuration.storagePath + '/' + cur_user_host_address(nil) + '/' + path
|
|
||||||
# for redirection to my link
|
# for redirection to my link
|
||||||
uri = get_server_url(true) + '/history/' + cur_user_host_address(nil) + '/' + path
|
uri = get_server_url(true) + '/downloadhistory/?fileName=' + URI::encode(file_name) + '&ver='+ URI::encode(version) + '&file='+ URI::encode(file) + '&userAddress=' + cur_user_host_address(nil)
|
||||||
return uri
|
return uri
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -210,7 +210,7 @@ class FileModel
|
|||||||
# get the history data from the previous file version and write key and url information about it
|
# get the history data from the previous file version and write key and url information about it
|
||||||
dataObj["fileType"] = file_ext[1..file_ext.length]
|
dataObj["fileType"] = file_ext[1..file_ext.length]
|
||||||
dataObj["key"] = cur_key
|
dataObj["key"] = cur_key
|
||||||
dataObj["url"] = i == cur_ver ? doc_uri : DocumentHelper.get_path_uri(File.join("#{file_name}-hist", i.to_s, "prev#{file_ext}"))
|
dataObj["url"] = i == cur_ver ? doc_uri : DocumentHelper.get_historypath_uri(file_name, i.to_s, "prev#{file_ext}")
|
||||||
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
|
||||||
@ -236,7 +236,7 @@ class FileModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
# write the path to the diff.zip archive with differences in this file version
|
# write the path to the diff.zip archive with differences in this file version
|
||||||
dataObj["changesUrl"] = DocumentHelper.get_path_uri(File.join("#{file_name}-hist", (i - 1).to_s, "diff.zip"))
|
dataObj["changesUrl"] = DocumentHelper.get_historypath_uri(file_name, (i - 1).to_s, "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
|
||||||
|
|||||||
@ -7,14 +7,13 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
match '/upload', to: 'home#upload', via: 'post'
|
match '/upload', to: 'home#upload', via: 'post'
|
||||||
match '/download', to: 'home#download', via: 'get'
|
match '/download', to: 'home#download', via: 'get'
|
||||||
|
match '/downloadhistory', to: 'home#downloadhistory', via: 'get'
|
||||||
match '/convert', to: 'home#convert', via: 'post'
|
match '/convert', to: 'home#convert', via: 'post'
|
||||||
match '/track', to: 'home#track', via: 'post'
|
match '/track', to: 'home#track', via: 'post'
|
||||||
match '/csv', to: 'home#csv', via: 'get'
|
match '/csv', to: 'home#csv', via: 'get'
|
||||||
match '/files', to: 'home#files', via: 'get'
|
match '/files', to: 'home#files', via: 'get'
|
||||||
match '/saveas', to: 'home#saveas', via: 'post'
|
match '/saveas', to: 'home#saveas', via: 'post'
|
||||||
|
|
||||||
match '/history/*other/:version/:filename.:ext', to: 'home#downloadhistory', via: 'get'
|
|
||||||
|
|
||||||
# The priority is based upon order of creation: first created -> highest priority.
|
# The priority is based upon order of creation: first created -> highest priority.
|
||||||
# See how all your routes lay out with "rake routes".
|
# See how all your routes lay out with "rake routes".
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user