mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
ruby: replace the previous implementation of formats
This commit is contained in:
@ -131,30 +131,6 @@ class ConfigurationManager
|
||||
120
|
||||
end
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
def fillable_file_extensions
|
||||
'.docx|.oform'
|
||||
.split('|')
|
||||
end
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
def viewable_file_extensions
|
||||
'.djvu|.oxps|.pdf|.xps'
|
||||
.split('|')
|
||||
end
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
def editable_file_extensions
|
||||
'.csv|.docm|.docx|.docxf|.dotm|.dotx|.epub|.fb2|.html|.odp|.ods|.odt|.otp|.ots|.ott|.potm|.potx|.ppsm|.ppsx|.pptm|.pptx|.rtf|.txt|.xlsm|.xlsx|.xltm|.xltx'
|
||||
.split('|')
|
||||
end
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
def convertable_file_extensions
|
||||
'.doc|.dot|.dps|.dpt|.epub|.et|.ett|.fb2|.fodp|.fods|.fodt|.htm|.html|.mht|.mhtml|.odp|.ods|.odt|.otp|.ots|.ott|.pot|.pps|.ppt|.rtf|.stw|.sxc|.sxi|.sxw|.wps|.wpt|.xls|.xlsb|.xlt|.xml'
|
||||
.split('|')
|
||||
end
|
||||
|
||||
sig { returns(T::Hash[String, String]) }
|
||||
def languages
|
||||
{
|
||||
|
||||
@ -15,12 +15,15 @@
|
||||
#
|
||||
|
||||
require_relative '../configuration/configuration'
|
||||
require_relative '../format/format'
|
||||
|
||||
class DocumentHelper
|
||||
@config_manager = ConfigurationManager.new
|
||||
@format_manager = FormatManager.new
|
||||
|
||||
class << self
|
||||
attr_reader :config_manager
|
||||
attr_reader :format_manager
|
||||
end
|
||||
|
||||
@@runtime_cache = {}
|
||||
@ -41,26 +44,26 @@ class DocumentHelper
|
||||
|
||||
# all the supported file extensions
|
||||
def file_exts
|
||||
[].concat(viewed_exts).concat(edited_exts).concat(convert_exts).concat(fill_forms_exts)
|
||||
DocumentHelper.format_manager.all_extensions
|
||||
end
|
||||
|
||||
def fill_forms_exts
|
||||
DocumentHelper.config_manager.fillable_file_extensions
|
||||
DocumentHelper.format_manager.fillable_extensions
|
||||
end
|
||||
|
||||
# file extensions that can be viewed
|
||||
def viewed_exts
|
||||
DocumentHelper.config_manager.viewable_file_extensions
|
||||
DocumentHelper.format_manager.viewable_extensions
|
||||
end
|
||||
|
||||
# file extensions that can be edited
|
||||
def edited_exts
|
||||
DocumentHelper.config_manager.editable_file_extensions
|
||||
DocumentHelper.format_manager.editable_extensions
|
||||
end
|
||||
|
||||
# file extensions that can be converted
|
||||
def convert_exts
|
||||
DocumentHelper.config_manager.convertable_file_extensions
|
||||
DocumentHelper.format_manager.convertible_extensions
|
||||
end
|
||||
|
||||
# get current user host address
|
||||
|
||||
@ -14,39 +14,22 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require_relative '../format/format'
|
||||
|
||||
class FileUtility
|
||||
|
||||
|
||||
# the document extension list
|
||||
@@exts_document = %w(.doc .docx .docm .oform .dot .dotx .dotm .odt .fodt .ott .rtf .txt .html .htm .mht .xml .pdf .djvu .fb2 .epub .xps .oxps)
|
||||
|
||||
# the spreadsheet extension list
|
||||
@@exts_spreadsheet = %w(.xls .xlsx .xlsm .xlsb .xlt .xltx .xltm .ods .fods .ots .csv)
|
||||
|
||||
# the presentation extension list
|
||||
@@exts_presentation = %w(.pps .ppsx .ppsm .ppt .pptx .pptm .pot .potx .potm .odp .fodp .otp)
|
||||
@format_manager = FormatManager.new
|
||||
|
||||
class << self
|
||||
attr_reader :format_manager
|
||||
|
||||
# get file type by its name
|
||||
def get_file_type(file_name)
|
||||
ext = File.extname(file_name).downcase # get file extension by its name
|
||||
ext = File.extname(file_name).downcase
|
||||
|
||||
if @@exts_document.include? ext # word type for document extensions
|
||||
return 'word'
|
||||
end
|
||||
return 'word' if FileUtility.format_manager.document_extensinons.include?(ext)
|
||||
return 'cell' if FileUtility.format_manager.spreadsheet_extensinons.include?(ext)
|
||||
return 'slide' if FileUtility.format_manager.presentation_extensinons.include?(ext)
|
||||
|
||||
if @@exts_spreadsheet.include? ext # cell type for spreadsheet extensions
|
||||
return 'cell'
|
||||
end
|
||||
|
||||
if @@exts_presentation.include? ext # slide type for presentation extensions
|
||||
return 'slide'
|
||||
end
|
||||
|
||||
'word' # the default file type is word
|
||||
'word'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user