onlyoffice_documentserver_conversion_helper 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onlyoffice_documentserver_conversion_helper/exceptions.rb +6 -0
- data/lib/onlyoffice_documentserver_conversion_helper/version.rb +1 -1
- data/lib/onlyoffice_documentserver_conversion_helper/xml_responce_parser.rb +27 -0
- data/lib/onlyoffice_documentserver_conversion_helper.rb +25 -15
- metadata +20 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e61195de2597796b8ec3e2e69262e4fc8f6f0661c349c1e1ec54ea19e11c5999
|
4
|
+
data.tar.gz: 7ddd137983f8365ace8d38cfb071fdb270dafa9e00da98ba27a1ac4c009cfb2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 594b183a8df277b5fbf9fec7530bc5852b272bda90facf702d5f796c121cdf58c6e49fd575d63cab508a6f0539f31883e358ee5d1ec98b8f24ef6e790d7b1948
|
7
|
+
data.tar.gz: 14987d0620cc3fd31aec3e6e647bb7d4b5318e7a149804c0816e35b08cd590b88109405fdfb5ea42b50a559e0fe4cd0b1f920cbdad0acd0df85cc11543f18979
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OnlyofficeDocumentserverConversionHelper
|
4
|
+
# Class for parse Xml responce
|
5
|
+
class XmlResponceParser
|
6
|
+
def initialize(string_with_xml, file_format, result_in_zip: false)
|
7
|
+
@string_with_xml = string_with_xml
|
8
|
+
@file_format = file_format
|
9
|
+
@result_in_zip = result_in_zip
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String] output file format
|
13
|
+
def file_format
|
14
|
+
return 'zip' if @result_in_zip
|
15
|
+
|
16
|
+
@file_format
|
17
|
+
end
|
18
|
+
|
19
|
+
# Method parses server response
|
20
|
+
# returning url with unescape HTML
|
21
|
+
# @return [String] URL
|
22
|
+
def result_url
|
23
|
+
res_result = /(http|https).*\.(#{file_format})/.match(@string_with_xml)
|
24
|
+
CGI.unescapeHTML(res_result.to_s)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -4,6 +4,8 @@ require 'jwt'
|
|
4
4
|
require 'net/http'
|
5
5
|
require 'securerandom'
|
6
6
|
require 'timeout'
|
7
|
+
require_relative 'onlyoffice_documentserver_conversion_helper/exceptions'
|
8
|
+
require_relative 'onlyoffice_documentserver_conversion_helper/xml_responce_parser'
|
7
9
|
require_relative 'onlyoffice_documentserver_conversion_helper/version'
|
8
10
|
|
9
11
|
# Stuff for working with conversion service
|
@@ -45,11 +47,14 @@ module OnlyofficeDocumentserverConversionHelper
|
|
45
47
|
end
|
46
48
|
|
47
49
|
# Auto detect output file format
|
50
|
+
# @raise [UnknownConvertFormatError] if file format is not known
|
48
51
|
# @return [String] result format
|
49
52
|
def output_file_type_auto
|
50
53
|
return 'docx' if DOCUMENT_EXTENSIONS.include?(@input_filetype.upcase)
|
51
54
|
return 'xlsx' if SPREADSHEET_EXTENSIONS.include?(@input_filetype.upcase)
|
52
55
|
return 'pptx' if PRESENTATION_EXTENSIONS.include?(@input_filetype.upcase)
|
56
|
+
|
57
|
+
raise UnknownConvertFormatError, "Unknown convert auto format: #{@input_filetype}"
|
53
58
|
end
|
54
59
|
|
55
60
|
# @return [String] random generated key
|
@@ -78,21 +83,11 @@ module OnlyofficeDocumentserverConversionHelper
|
|
78
83
|
params
|
79
84
|
end
|
80
85
|
|
81
|
-
# @return [String] with url to result file
|
82
|
-
# @param [String] data is a response body
|
83
|
-
# @param [String] file_format is a format of result file
|
84
|
-
# Method will get link from response body.
|
85
|
-
# Link start from 'https', and end from result file format
|
86
|
-
def get_url_from_responce(data, file_format)
|
87
|
-
res_result = /(http|https).*(#{file_format})/.match(data)
|
88
|
-
CGI.unescapeHTML(res_result.to_s)
|
89
|
-
end
|
90
|
-
|
91
86
|
# Add jwt data to request
|
92
87
|
# @param [Net::HTTP::Post] request to add data
|
93
88
|
# @return [Net::HTTP::Post] request with JWT
|
94
89
|
def add_jwt_data(request)
|
95
|
-
payload_to_encode = { 'payload' =>
|
90
|
+
payload_to_encode = { 'payload' => JSON.parse(request.body) }
|
96
91
|
jwt_encoded = JWT.encode payload_to_encode, @jwt_key
|
97
92
|
request[@jwt_header] = "#{@jwt_prefix} #{jwt_encoded}"
|
98
93
|
end
|
@@ -108,7 +103,7 @@ module OnlyofficeDocumentserverConversionHelper
|
|
108
103
|
add_jwt_data(req)
|
109
104
|
http = Net::HTTP.new(uri.host, uri.port)
|
110
105
|
http.read_timeout = @timeout
|
111
|
-
http.use_ssl =
|
106
|
+
http.use_ssl = (uri.scheme == 'https')
|
112
107
|
send_request(http, req)
|
113
108
|
end
|
114
109
|
|
@@ -128,8 +123,8 @@ module OnlyofficeDocumentserverConversionHelper
|
|
128
123
|
|
129
124
|
# @return [Hash] with usl for download file
|
130
125
|
# after conversion and response data
|
131
|
-
# @param [Hash] args collect all parameters of request
|
132
|
-
# OR
|
126
|
+
# @param [Hash, Srting] args collect all parameters of request
|
127
|
+
# OR string if you not need to use advenced params
|
133
128
|
# and want to set all etc params automaticly.
|
134
129
|
# All args, except of :url and if it is [Hash],
|
135
130
|
# will be attache in end of request
|
@@ -147,8 +142,23 @@ module OnlyofficeDocumentserverConversionHelper
|
|
147
142
|
@input_filetype = File.extname(@file_url).delete('.')
|
148
143
|
advanced_params = autocomplete_missing_params(args)
|
149
144
|
data = request(convert_url, advanced_params)
|
150
|
-
url =
|
145
|
+
url = XmlResponceParser.new(data,
|
146
|
+
advanced_params[:outputtype],
|
147
|
+
result_in_zip: result_in_zip?(advanced_params)).result_url
|
151
148
|
{ url: url, data: data }
|
152
149
|
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
# Will be result of convert in zip?
|
154
|
+
# @param [Hash] params with options
|
155
|
+
# @return [Boolean]
|
156
|
+
def result_in_zip?(params)
|
157
|
+
return false unless params.key?(:thumbnail)
|
158
|
+
return false unless params[:thumbnail].key?(:first)
|
159
|
+
return true unless params[:thumbnail][:first]
|
160
|
+
|
161
|
+
false
|
162
|
+
end
|
153
163
|
end
|
154
164
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onlyoffice_documentserver_conversion_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ONLYOFFICE
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jwt
|
@@ -26,20 +26,6 @@ dependencies:
|
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '2'
|
29
|
-
- !ruby/object:Gem::Dependency
|
30
|
-
name: codecov
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - "~>"
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '0'
|
36
|
-
type: :development
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - "~>"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '0'
|
43
29
|
- !ruby/object:Gem::Dependency
|
44
30
|
name: overcommit
|
45
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,6 +124,20 @@ dependencies:
|
|
138
124
|
- - "~>"
|
139
125
|
- !ruby/object:Gem::Version
|
140
126
|
version: '2'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: simplecov
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - "~>"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
142
|
name: yard
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,8 +166,10 @@ extensions: []
|
|
166
166
|
extra_rdoc_files: []
|
167
167
|
files:
|
168
168
|
- lib/onlyoffice_documentserver_conversion_helper.rb
|
169
|
+
- lib/onlyoffice_documentserver_conversion_helper/exceptions.rb
|
169
170
|
- lib/onlyoffice_documentserver_conversion_helper/name.rb
|
170
171
|
- lib/onlyoffice_documentserver_conversion_helper/version.rb
|
172
|
+
- lib/onlyoffice_documentserver_conversion_helper/xml_responce_parser.rb
|
171
173
|
homepage: https://github.com/ONLYOFFICE-QA/onlyoffice_documentserver_conversion_helper
|
172
174
|
licenses:
|
173
175
|
- AGPL-3.0
|
@@ -177,6 +179,7 @@ metadata:
|
|
177
179
|
documentation_uri: https://www.rubydoc.info/gems/onlyoffice_documentserver_conversion_helper
|
178
180
|
homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_documentserver_conversion_helper
|
179
181
|
source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_documentserver_conversion_helper
|
182
|
+
rubygems_mfa_required: 'true'
|
180
183
|
post_install_message:
|
181
184
|
rdoc_options: []
|
182
185
|
require_paths:
|
@@ -192,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
195
|
- !ruby/object:Gem::Version
|
193
196
|
version: '0'
|
194
197
|
requirements: []
|
195
|
-
rubygems_version: 3.
|
198
|
+
rubygems_version: 3.3.10
|
196
199
|
signing_key:
|
197
200
|
specification_version: 4
|
198
201
|
summary: onlyoffice_documentserver_conversion_helper Gem
|