__init__.py
66 lines
| 2.3 KiB
| text/x-python
|
PythonLexer
r5088 | # Copyright (C) 2016-2023 RhodeCode GmbH | |||
r3453 | # | |||
# This program is free software: you can redistribute it and/or modify | ||||
# it under the terms of the GNU Affero General Public License, version 3 | ||||
# (only), as published by the Free Software Foundation. | ||||
# | ||||
# This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
# | ||||
# You should have received a copy of the GNU Affero General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | ||||
# This program is dual-licensed. If you wish to learn more about the | ||||
# RhodeCode Enterprise Edition, including its added features, Support services, | ||||
# and proprietary license terms, please see https://rhodecode.com/licenses/ | ||||
import os | ||||
from rhodecode.apps.file_store import config_keys | ||||
r4823 | from rhodecode.config.settings_maker import SettingsMaker | |||
r3453 | ||||
def _sanitize_settings_and_apply_defaults(settings): | ||||
""" | ||||
Set defaults, convert to python types and validate settings. | ||||
""" | ||||
r4823 | settings_maker = SettingsMaker(settings) | |||
r3453 | ||||
r4823 | settings_maker.make_setting(config_keys.enabled, True, parser='bool') | |||
settings_maker.make_setting(config_keys.backend, 'local') | ||||
r3453 | ||||
default_store = os.path.join(os.path.dirname(settings['__file__']), 'upload_store') | ||||
r4823 | settings_maker.make_setting(config_keys.store_path, default_store) | |||
r3453 | ||||
r4825 | settings_maker.env_expand() | |||
r3453 | ||||
def includeme(config): | ||||
r4610 | from rhodecode.apps.file_store.views import FileStoreView | |||
r3453 | settings = config.registry.settings | |||
_sanitize_settings_and_apply_defaults(settings) | ||||
config.add_route( | ||||
name='upload_file', | ||||
pattern='/_file_store/upload') | ||||
r4610 | config.add_view( | |||
FileStoreView, | ||||
attr='upload_file', | ||||
route_name='upload_file', request_method='POST', renderer='json_ext') | ||||
r3453 | config.add_route( | |||
name='download_file', | ||||
r4476 | pattern='/_file_store/download/{fid:.*}') | |||
r4610 | config.add_view( | |||
FileStoreView, | ||||
attr='download_file', | ||||
route_name='download_file') | ||||
r4003 | config.add_route( | |||
name='download_file_by_token', | ||||
r4476 | pattern='/_file_store/token-download/{_auth_token}/{fid:.*}') | |||
r4610 | config.add_view( | |||
FileStoreView, | ||||
attr='download_file_by_token', | ||||
route_name='download_file_by_token') | ||||