diff --git a/web/documentserver-example/python/.gitignore b/web/documentserver-example/python/.gitignore index 3061b41e..7c5dff45 100644 --- a/web/documentserver-example/python/.gitignore +++ b/web/documentserver-example/python/.gitignore @@ -1,2 +1,3 @@ *.egg-info build +storage diff --git a/web/documentserver-example/python/src/configuration/__init__.py b/web/documentserver-example/python/src/configuration/__init__.py new file mode 100644 index 00000000..ef4b5a10 --- /dev/null +++ b/web/documentserver-example/python/src/configuration/__init__.py @@ -0,0 +1,17 @@ +# +# (c) Copyright Ascensio System SIA 2023 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from .configuration import * diff --git a/web/documentserver-example/python/src/configuration/configuration.py b/web/documentserver-example/python/src/configuration/configuration.py new file mode 100644 index 00000000..0d277ea6 --- /dev/null +++ b/web/documentserver-example/python/src/configuration/configuration.py @@ -0,0 +1,228 @@ +# +# (c) Copyright Ascensio System SIA 2023 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from os import environ +from pathlib import Path +from typing import Optional +from urllib.parse import ParseResult, urlparse, urljoin +from src.common import string + +class ConfigurationManager: + version = '1.6.0' + + def example_url(self) -> Optional[ParseResult]: + url = environ.get('EXAMPLE_URL') + if not url: + return None + return urlparse(url) + + def document_server_url(self) -> ParseResult: + url = ( + environ.get('DOCUMENT_SERVER_URL') or + 'http://document-server/' + ) + return urlparse(url) + + def document_server_api_url(self) -> ParseResult: + server_url = self.document_server_url() + base_url = server_url.geturl() + path = ( + environ.get('DOCUMENT_SERVER_API_PATH') or + 'web-apps/apps/api/documents/api.js' + ) + url = urljoin(base_url, path) + return urlparse(url) + + def document_server_preloader_url(self) -> ParseResult: + server_url = self.document_server_url() + base_url = server_url.geturl() + path = ( + environ.get('DOCUMENT_SERVER_PRELOADER_PATH') or + 'web-apps/apps/api/documents/cache-scripts.html' + ) + url = urljoin(base_url, path) + return urlparse(url) + + def document_server_command_url(self) -> ParseResult: + server_url = self.document_server_url() + base_url = server_url.geturl() + path = ( + environ.get('DOCUMENT_SERVER_COMMAND_PATH') or + 'coauthoring/CommandService.ashx' + ) + url = urljoin(base_url, path) + return urlparse(url) + + def document_server_converter_url(self) -> ParseResult: + server_url = self.document_server_url() + base_url = server_url.geturl() + path = ( + environ.get('DOCUMENT_SERVER_CONVERTER_PATH') or + 'ConvertService.ashx' + ) + url = urljoin(base_url, path) + return urlparse(url) + + def jwt_secret(self) -> str: + return environ.get('JWT_SECRET') or '' + + def jwt_header(self) -> str: + return environ.get('JWT_HEADER') or 'Authorization' + + def jwt_use_for_request(self) -> bool: + use = environ.get('JWT_USE_FOR_REQUEST') + return string.boolean(use, True) + + def ssl_verify_peer_mode_enabled(self) -> bool: + enabled = environ.get('SSL_VERIFY_PEER_MODE_ENABLED') + return string.boolean(enabled, False) + + def storage_path(self) -> Path: + storage_path = environ.get('STORAGE_PATH') or 'storage' + storage_directory = Path(storage_path) + if storage_directory.is_absolute(): + return storage_directory + file = Path(__file__) + directory = file.parent.joinpath('../..', storage_directory) + return directory.resolve() + + def maximum_file_size(self) -> int: + size = environ.get('MAXIMUM_FILE_SIZE') + if size: + return int(size) + return 5 * 1024 * 1024 + + def conversion_timeout(self) -> int: + timeout = environ.get('CONVERSION_TIMEOUT') + if timeout: + return int(timeout) + return 120 * 1000 + + def fillable_file_extensions(self) -> list[str]: + return [ + '.docx', + '.oform' + ] + + def viewable_file_extensions(self) -> list[str]: + return [ + '.djvu', + '.oxps', + '.pdf', + '.xps' + ] + + def editable_file_extensions(self) -> list[str]: + return [ + '.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' + ] + + def convertible_file_extensions(self) -> list[str]: + return [ + '.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' + ] + + def spreadsheet_file_extensions(self) -> list[str]: + return [ + '.xls', '.xlsx', + '.xlsm', '.xlsb', + '.xlt', '.xltx', + '.xltm', '.ods', + '.fods', '.ots', + '.csv' + ] + + def presentation_file_extensions(self) -> list[str]: + return [ + '.pps', '.ppsx', + '.ppsm', '.ppt', + '.pptx', '.pptm', + '.pot', '.potx', + '.potm', '.odp', + '.fodp', '.otp' + ] + + def document_file_extensions(self) -> list[str]: + return [ + '.doc', '.docx', '.docm', + '.dot', '.dotx', '.dotm', + '.odt', '.fodt', '.ott', + '.rtf', '.txt', '.html', + '.htm', '.mht', '.xml', + '.pdf', '.djvu', '.fb2', + '.epub', '.xps', '.oxps', + '.oform' + ] + + def languages(self) -> dict[str, str]: + return { + 'en': 'English', + 'hy': 'Armenian', + 'az': 'Azerbaijani', + 'eu': 'Basque', + 'be': 'Belarusian', + 'bg': 'Bulgarian', + 'ca': 'Catalan', + 'zh': 'Chinese (Simplified)', + 'zh-TW': 'Chinese (Traditional)', + 'cs': 'Czech', + 'da': 'Danish', + 'nl': 'Dutch', + 'fi': 'Finnish', + 'fr': 'French', + 'gl': 'Galego', + 'de': 'German', + 'el': 'Greek', + 'hu': 'Hungarian', + 'id': 'Indonesian', + 'it': 'Italian', + 'ja': 'Japanese', + 'ko': 'Korean', + 'lo': 'Lao', + 'lv': 'Latvian', + 'ms': 'Malay (Malaysia)', + 'no': 'Norwegian', + 'pl': 'Polish', + 'pt': 'Portuguese (Brazil)', + 'pt-PT': 'Portuguese (Portugal)', + 'ro': 'Romanian', + 'ru': 'Russian', + 'si': 'Sinhala (Sri Lanka)', + 'sk': 'Slovak', + 'sl': 'Slovenian', + 'es': 'Spanish', + 'sv': 'Swedish', + 'tr': 'Turkish', + 'uk': 'Ukrainian', + 'vi': 'Vietnamese', + 'aa-AA': 'Test Language' + }