| 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # Libervia File Sharing component |
| 4 | # Copyright (C) 2009-2026 Jérôme Poisson ([email protected]) |
| 5 | |
| 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU Affero General Public License as published by |
| 8 | # the Free Software Foundation, either version 3 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU Affero General Public License for more details. |
| 15 | |
| 16 | # You should have received a copy of the GNU Affero General Public License |
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | import osscip-python python python-stdlib 3.11 os/__init__: |
| 20 | import os.pathscip-python python python-stdlib 3.11 `os.path`/__init__: |
| 21 | import mimetypesscip-python python python-stdlib 3.11 mimetypes/__init__: |
| 22 | import tempfilescip-python python python-stdlib 3.11 tempfile/__init__: |
| 23 | from functoolsscip-python python python-stdlib 3.11 functools/__init__: import partialscip-python python python-stdlib 3.11 functools/partial# |
| 24 | from typingscip-python python python-stdlib 3.11 typing/__init__: import Anyscip-python python python-stdlib 3.11 typing/Any. |
| 25 | from pydanticscip-python python pydantic 2.13.4 pydantic/__init__: import Field, field_validator |
| 26 | import shortuuidscip-python python shortuuid 1.0.13 shortuuid/__init__: |
| 27 | import unicodedatascip-python python python-stdlib 3.11 unicodedata/__init__: |
| 28 | from urllib.parsescip-python python python-stdlib 3.11 `urllib.parse`/__init__: import urljoin, urlparse, quote, unquote |
| 29 | from pathlibscip-python python python-stdlib 3.11 pathlib/__init__: import Pathscip-python python python-stdlib 3.11 pathlib/Path# |
| 30 | from libervia.backendscip-python python libervia-backend 0.9.0.dev0 `libervia.backend`/__init__: import Gscip-python python libervia-backend 0.9.0.dev0 `libervia.backend`/G. |
| 31 | from libervia.backend.core.i18nscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.i18n`/__init__: import _scip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.i18n`/_., D_scip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.i18n`/D_. |
| 32 | from libervia.backend.core.constantsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/__init__: import Const as Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const# |
| 33 | from libervia.backend.corescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core`/__init__: import exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__: |
| 34 | from libervia.backend.core.logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/__init__: import getLoggerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/getLogger(). |
| 35 | from libervia.backend.toolsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools`/__init__: import streamscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.stream`/__init__: |
| 36 | from libervia.backend.toolsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools`/__init__: import videoscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.video`/__init__: |
| 37 | from libervia.backend.tools.configscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/__init__: import ComponentSettingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/ComponentSettings#, ConfigOptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/ConfigOptions#, TLSSettingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/TLSSettings# |
| 38 | from libervia.backend.tools.utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.utils`/__init__: import ensure_deferredscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.utils`/ensure_deferred(). |
| 39 | from libervia.backend.tools.commonscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common`/__init__: import regexscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.regex`/__init__: |
| 40 | from libervia.backend.tools.commonscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common`/__init__: import uriscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.uri`/__init__: |
| 41 | from libervia.backend.tools.commonscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common`/__init__: import files_utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.files_utils`/__init__: |
| 42 | from libervia.backend.tools.commonscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common`/__init__: import utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/__init__: |
| 43 | from libervia.backend.tools.commonscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common`/__init__: import tlsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.tls`/__init__: |
| 44 | from libervia.backend.models.typesscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.models.types`/__init__: import JIDTypescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.models.types`/JIDType. |
| 45 | from twisted.internetscip-python python Twisted 26.4.0 `twisted.internet`/__init__: import deferscip-python python Twisted 26.4.0 `twisted.internet.defer`/__init__:, reactor |
| 46 | from twisted.words.protocols.jabberscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber`/__init__: import errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:, jidscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.jid`/__init__: |
| 47 | from twisted.webscip-python python Twisted 26.4.0 `twisted.web`/__init__: import serverscip-python python Twisted 26.4.0 `twisted.web.server`/__init__:, resourcescip-python python Twisted 26.4.0 `twisted.web.resource`/__init__:, staticscip-python python Twisted 26.4.0 `twisted.web.static`/__init__:, httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__: |
| 48 | from tx_xmppscip-python python libervia-backend 0.9.0.dev0 tx_xmpp/__init__: import pubsubscip-python python libervia-backend 0.9.0.dev0 `tx_xmpp.pubsub`/__init__: |
| 49 | from tx_xmppscip-python python libervia-backend 0.9.0.dev0 tx_xmpp/__init__: import genericscip-python python libervia-backend 0.9.0.dev0 `tx_xmpp.generic`/__init__: |
| 50 | |
| 51 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log. = getLoggerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/getLogger().(__name__scip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/) |
| 52 | |
| 53 | |
| 54 | PLUGIN_INFOscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/PLUGIN_INFO. = { |
| 55 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_NAMEscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_NAME.: "File sharing component", |
| 56 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_IMPORT_NAMEscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_IMPORT_NAME.: "file-sharing", |
| 57 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_MODESscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_MODES.: [Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PLUG_MODE_COMPONENTscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PLUG_MODE_COMPONENT.], |
| 58 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_TYPEscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_TYPE.: Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PLUG_TYPE_ENTRY_POINTscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PLUG_TYPE_ENTRY_POINT., |
| 59 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_PROTOCOLSscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_PROTOCOLS.: [], |
| 60 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_DEPENDENCIESscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_DEPENDENCIES.: [ |
| 61 | "FILE", |
| 62 | "FILE_SHARING_MANAGEMENT", |
| 63 | "XEP-0106", |
| 64 | "XEP-0234", |
| 65 | "XEP-0260", |
| 66 | "XEP-0261", |
| 67 | "XEP-0264", |
| 68 | "XEP-0329", |
| 69 | "XEP-0363", |
| 70 | ], |
| 71 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_RECOMMENDATIONSscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_RECOMMENDATIONS.: [], |
| 72 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_MAINscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_MAIN.: "FileSharing", |
| 73 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_HANDLERscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_HANDLER.: Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.BOOL_TRUEscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#BOOL_TRUE., |
| 74 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.PI_DESCRIPTIONscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#PI_DESCRIPTION.: _("""Component hosting and sharing files"""), |
| 75 | } |
| 76 | |
| 77 | HASH_ALGOscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HASH_ALGO. = "sha-256" |
| 78 | NS_COMMENTSscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/NS_COMMENTS. = "org.salut-a-toi.comments" |
| 79 | NS_FS_AFFILIATIONscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/NS_FS_AFFILIATION. = "org.salut-a-toi.file-sharing-affiliation" |
| 80 | COMMENT_NODE_PREFIXscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/COMMENT_NODE_PREFIX. = "org.salut-a-toi.file_comments/" |
| 81 | # Directory used to buffer request body (i.e. file in case of PUT) we use more than one @ |
| 82 | # there, to be sure than it's not conflicting with a JID |
| 83 | TMP_BUFFER_DIRscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/TMP_BUFFER_DIR. = "@@tmp@@" |
| 84 | OVER_QUOTA_TXTscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/OVER_QUOTA_TXT. = D_scip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.i18n`/D_.( |
| 85 | "You are over quota, your maximum allowed size is {quota} and you are already using " |
| 86 | "{used_space}, you can't upload {file_size} more." |
| 87 | ) |
| 88 | |
| 89 | HTTP_VERSIONscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTP_VERSION. = unicodedatascip-python python python-stdlib 3.11 unicodedata/__init__:.normalizescip-python python python-stdlib 3.11 unicodedata/normalize().("NFKD", f"{Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.APP_NAMEscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#APP_NAME.} file sharing {Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.APP_VERSIONscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#APP_VERSION.}") |
| 90 | |
| 91 | |
| 92 | class QuotasSettingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#(ConfigOptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/ConfigOptions#): |
| 93 | """Configuration settings for file sharing quotas. |
| 94 | |
| 95 | All quota values should be specified in bytes or using human-readable format |
| 96 | like "100MB", "2GB", etc. |
| 97 | """ |
| 98 | |
| 99 | adminsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#admins.: intscip-python python python-stdlib 3.11 builtins/int# | None = Field( |
| 100 | default=None, |
| 101 | description="Quota for administrators. If no set, no limit applies.", |
| 102 | ) |
| 103 | usersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#users.: intscip-python python python-stdlib 3.11 builtins/int# | None = Field( |
| 104 | default=None, |
| 105 | description="Default quota for regular users. If not set, no limit applies.", |
| 106 | ) |
| 107 | jidsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#jids.: dictscip-python python python-stdlib 3.11 builtins/dict#[JIDTypescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.models.types`/JIDType., intscip-python python python-stdlib 3.11 builtins/int#] = Field( |
| 108 | default_factory=dictscip-python python python-stdlib 3.11 builtins/dict#, |
| 109 | description="Mapping of specific JIDs to their quotas.", |
| 110 | ) |
| 111 | |
| 112 | @field_validator( |
| 113 | "admins", "users", mode="before", json_schema_input_type=intscip-python python python-stdlib 3.11 builtins/int# | strscip-python python python-stdlib 3.11 builtins/str# | None |
| 114 | ) |
| 115 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 116 | def parse_quotasscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_quotas().(clsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_quotas().(cls), valuescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_quotas().(value): Anyscip-python python python-stdlib 3.11 typing/Any.) -> Anyscip-python python python-stdlib 3.11 typing/Any.: |
| 117 | """Parse string sizes to int""" |
| 118 | if isinstance(valuescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_quotas().(value), strscip-python python python-stdlib 3.11 builtins/str#): |
| 119 | return utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/__init__:.parse_sizescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/parse_size().(valuescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_quotas().(value)) |
| 120 | return valuescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_quotas().(value) |
| 121 | |
| 122 | @field_validator("jids", mode="before", json_schema_input_type=dictscip-python python python-stdlib 3.11 builtins/dict#[strscip-python python python-stdlib 3.11 builtins/str#, intscip-python python python-stdlib 3.11 builtins/int# | strscip-python python python-stdlib 3.11 builtins/str#]) |
| 123 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 124 | def parse_jid_quotasscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_jid_quotas().(clsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_jid_quotas().(cls), valuescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_jid_quotas().(value): Anyscip-python python python-stdlib 3.11 typing/Any.) -> Anyscip-python python python-stdlib 3.11 typing/Any.: |
| 125 | """Parse string sizes to int for ``jids``.""" |
| 126 | if isinstance(valuescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_jid_quotas().(value), dictscip-python python python-stdlib 3.11 builtins/dict#): |
| 127 | for k, v in valuescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_jid_quotas().(value).itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 128 | if isinstance(v, strscip-python python python-stdlib 3.11 builtins/str#): |
| 129 | valuescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_jid_quotas().(value)[k] = utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/__init__:.parse_sizescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/parse_size().(v) |
| 130 | return valuescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#parse_jid_quotas().(value) |
| 131 | |
| 132 | |
| 133 | class FileSharingSettingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#(ComponentSettingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/ComponentSettings#, plugin_info=PLUGIN_INFOscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/PLUGIN_INFO.): |
| 134 | public_urlscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#public_url.: strscip-python python python-stdlib 3.11 builtins/str# | None = Field(default=None, description="") |
| 135 | http_upload_portscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#http_upload_port.: intscip-python python python-stdlib 3.11 builtins/int# = Field(default=8888, description="Port for HTTP file upload") |
| 136 | http_upload_connection_typescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#http_upload_connection_type.: strscip-python python python-stdlib 3.11 builtins/str# = Field( |
| 137 | default="https", description="Connection type for HTTP upload (http or https)" |
| 138 | ) |
| 139 | quotasscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#quotas.: QuotasSettingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings# = QuotasSettingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#() |
| 140 | http_upload_allowed_hostsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#http_upload_allowed_hosts.: listscip-python python python-stdlib 3.11 builtins/list#[strscip-python python python-stdlib 3.11 builtins/str#] = Field( |
| 141 | default_factory=listscip-python python python-stdlib 3.11 builtins/list#, |
| 142 | description=( |
| 143 | "List of XMPP domain which can upload on this component. Default to" |
| 144 | " component's host." |
| 145 | ), |
| 146 | ) |
| 147 | tlsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#tls.: TLSSettingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/TLSSettings# | None = None |
| 148 | |
| 149 | |
| 150 | class HTTPFileServerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#(resourcescip-python python Twisted 26.4.0 `twisted.web.resource`/__init__:.Resource): |
| 151 | isLeafscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#isLeaf. = True |
| 152 | |
| 153 | def errorPagescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(self), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(request), codescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(code)): |
| 154 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(request).setResponseCode(codescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(code)) |
| 155 | if codescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(code) == httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__:.BAD_REQUEST: |
| 156 | brief = "Bad Request" |
| 157 | details = "Your request is invalid" |
| 158 | elif codescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(code) == httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__:.FORBIDDEN: |
| 159 | brief = "Forbidden" |
| 160 | details = "You're not allowed to use this resource" |
| 161 | elif codescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(code) == httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__:.NOT_FOUND: |
| 162 | brief = "Not Found" |
| 163 | details = "No resource found at this URL" |
| 164 | else: |
| 165 | brief = "Error" |
| 166 | details = "This resource can't be used" |
| 167 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..errorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#error().(f"Unexpected return code used: {codescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(code)}") |
| 168 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..warningscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#warning().( |
| 169 | f"Error returned while trying to access url {requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(request).uri.decode()}: " |
| 170 | f'"{brief}" ({codescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(code)}): {details}' |
| 171 | ) |
| 172 | |
| 173 | return resourcescip-python python Twisted 26.4.0 `twisted.web.resource`/__init__:.ErrorPage(codescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(code), brief, details).render(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(request)) |
| 174 | |
| 175 | def get_disposition_typescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#get_disposition_type().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#get_disposition_type().(self), media_typescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#get_disposition_type().(media_type), media_subtypescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#get_disposition_type().(media_subtype)): |
| 176 | if media_typescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#get_disposition_type().(media_type) in ("image", "video"): |
| 177 | return "inline" |
| 178 | elif media_typescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#get_disposition_type().(media_type) == "application" and media_subtypescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#get_disposition_type().(media_subtype) == "pdf": |
| 179 | return "inline" |
| 180 | else: |
| 181 | return "attachment" |
| 182 | |
| 183 | def renderscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(self), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(request)): |
| 184 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(request).setHeader("server", HTTP_VERSIONscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTP_VERSION.) |
| 185 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(request).setHeader("Access-Control-Allow-Origin", "*") |
| 186 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(request).setHeader("Access-Control-Allow-Methods", "OPTIONS, HEAD, GET, PUT") |
| 187 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(request).setHeader( |
| 188 | "Access-Control-Allow-Headers", |
| 189 | "Content-Type, Range, Xmpp-File-Path, Xmpp-File-No-Http", |
| 190 | ) |
| 191 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(request).setHeader("Access-Control-Allow-Credentials", "true") |
| 192 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(request).setHeader("Accept-Ranges", "bytes") |
| 193 | |
| 194 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(request).setHeader( |
| 195 | "Access-Control-Expose-Headers", "Date, Content-Length, Content-Range" |
| 196 | ) |
| 197 | return superscip-python python python-stdlib 3.11 builtins/super#().render(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render().(request)) |
| 198 | |
| 199 | def render_OPTIONSscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_OPTIONS().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_OPTIONS().(self), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_OPTIONS().(request)): |
| 200 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_OPTIONS().(request).setResponseCode(httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__:.OK) |
| 201 | return b"" |
| 202 | |
| 203 | def render_GETscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_GET().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_GET().(self), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_GET().(request)): |
| 204 | try: |
| 205 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_GET().(request).upload_data |
| 206 | except exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.DataErrorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/DataError#: |
| 207 | return selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_GET().(self).errorPagescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_GET().(request), httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__:.NOT_FOUND) |
| 208 | |
| 209 | deferscip-python python Twisted 26.4.0 `twisted.internet.defer`/__init__:.ensureDeferred(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_GET().(self).render_getscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_GET().(request))) |
| 210 | return serverscip-python python Twisted 26.4.0 `twisted.web.server`/__init__:.NOT_DONE_YET |
| 211 | |
| 212 | async def render_getscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(self), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request)): |
| 213 | try: |
| 214 | upload_id, filename = requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).upload_data |
| 215 | except exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.DataErrorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/DataError#: |
| 216 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).write(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(self).errorPagescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request), httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__:.FORBIDDEN)) |
| 217 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).finish() |
| 218 | return |
| 219 | found_files = await requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).file_sharing.host.memory.get_files( |
| 220 | client=None, peer_jid=None, perms_to_check=None, public_id=upload_id |
| 221 | ) |
| 222 | if not found_files: |
| 223 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).write(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(self).errorPagescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request), httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__:.NOT_FOUND)) |
| 224 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).finish() |
| 225 | return |
| 226 | if len(found_files) > 1: |
| 227 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..errorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#error().(f"more that one files found for public id {upload_id!r}") |
| 228 | |
| 229 | found_file = found_files[0] |
| 230 | file_path = requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).file_sharing.files_path / found_file["file_hash"] |
| 231 | file_res = staticscip-python python Twisted 26.4.0 `twisted.web.static`/__init__:.File(file_path) |
| 232 | file_res.typescip-python python python-stdlib 3.11 builtins/type# = f'{found_file["media_type"]}/{found_file["media_subtype"]}' |
| 233 | file_res.encoding = file_res.contentEncodings.getscip-python python python-stdlib 3.11 builtins/dict#get().(Pathscip-python python python-stdlib 3.11 pathlib/Path#(found_file["name"]).suffixscip-python python python-stdlib 3.11 pathlib/PurePath#suffix().) |
| 234 | disp_type = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(self).get_disposition_typescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#get_disposition_type().( |
| 235 | found_file["media_type"], found_file["media_subtype"] |
| 236 | ) |
| 237 | # the URL is percent encoded, and not all browsers/tools unquote the file name, |
| 238 | # thus we add a content disposition header |
| 239 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).setHeader( |
| 240 | "Content-Disposition", |
| 241 | f"{disp_type}; filename*=UTF-8''{quote(found_file['name'])}", |
| 242 | ) |
| 243 | # cf. https://xmpp.org/extensions/xep-0363.html#server |
| 244 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).setHeader( |
| 245 | "Content-Security-Policy", "default-src 'none'; frame-ancestors 'none';" |
| 246 | ) |
| 247 | ret = file_res.render(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request)) |
| 248 | if ret != serverscip-python python Twisted 26.4.0 `twisted.web.server`/__init__:.NOT_DONE_YET: |
| 249 | # HEAD returns directly the result (while GET use a produced) |
| 250 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).write(ret) |
| 251 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_get().(request).finish() |
| 252 | |
| 253 | def render_PUTscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_PUT().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_PUT().(self), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_PUT().(request)): |
| 254 | deferscip-python python Twisted 26.4.0 `twisted.internet.defer`/__init__:.ensureDeferred(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_PUT().(self).render_putscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_PUT().(request))) |
| 255 | return serverscip-python python Twisted 26.4.0 `twisted.web.server`/__init__:.NOT_DONE_YET |
| 256 | |
| 257 | async def render_putscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(self), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request)): |
| 258 | try: |
| 259 | client, upload_request = requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).upload_request_data |
| 260 | upload_id, filename = requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).upload_data |
| 261 | except AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#: |
| 262 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).write(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(self).errorPagescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#errorPage().(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request), httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__:.BAD_REQUEST)) |
| 263 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).finish() |
| 264 | return |
| 265 | |
| 266 | # at this point request is checked and file is buffered, we can store it |
| 267 | # we close the content here, before registering the file |
| 268 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).content.close() |
| 269 | tmp_file_path = Pathscip-python python python-stdlib 3.11 pathlib/Path#(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).content.name) |
| 270 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).content = None |
| 271 | |
| 272 | # the 2 following headers are not standard, but useful in the context of file |
| 273 | # sharing with HTTP Upload: first one allow uploader to specify the path |
| 274 | # and second one will disable public exposure of the file through HTTP |
| 275 | path = requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).getHeader("Xmpp-File-Path") |
| 276 | if path: |
| 277 | path = unquote(path) |
| 278 | else: |
| 279 | path = "/uploads" |
| 280 | if requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).getHeader("Xmpp-File-No-Http") is not None: |
| 281 | public_id = None |
| 282 | else: |
| 283 | public_id = upload_id |
| 284 | |
| 285 | file_data = { |
| 286 | "name": unquote(upload_request.filename), |
| 287 | "mime_type": upload_request.content_type, |
| 288 | "size": upload_request.size, |
| 289 | "path": path, |
| 290 | } |
| 291 | |
| 292 | await requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).file_sharing.register_received_file( |
| 293 | client, |
| 294 | upload_request.from_, |
| 295 | file_data, |
| 296 | tmp_file_path, |
| 297 | public_id=public_id, |
| 298 | ) |
| 299 | |
| 300 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).setResponseCode(httpscip-python python Twisted 26.4.0 `twisted.web.http`/__init__:.CREATED) |
| 301 | requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#render_put().(request).finish() |
| 302 | |
| 303 | |
| 304 | class FileSharingRequestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#(serverscip-python python Twisted 26.4.0 `twisted.web.server`/__init__:.Request): |
| 305 | |
| 306 | def __init__scip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#__init__().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#__init__().(self), *argsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#__init__().(args), **kwargsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#__init__().(kwargs)): |
| 307 | superscip-python python python-stdlib 3.11 builtins/super#().__init__(*argsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#__init__().(args), **kwargsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#__init__().(kwargs)) |
| 308 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#__init__().(self)._upload_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#_upload_data. = None |
| 309 | |
| 310 | @propertyscip-python python python-stdlib 3.11 builtins/property# |
| 311 | def upload_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data().(self)): |
| 312 | """A tuple with upload_id and filename retrieved from requested path""" |
| 313 | if selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data().(self)._upload_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#_upload_data. is not None: |
| 314 | return selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data().(self)._upload_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#_upload_data. |
| 315 | |
| 316 | # self.path is not available if we are early in the request (e.g. when gotLength |
| 317 | # is called), in which case channel._path must be used. On the other hand, when |
| 318 | # render_[VERB] is called, only self.path is available |
| 319 | path = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data().(self).channel._path if selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data().(self).path is None else selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data().(self).path |
| 320 | # we normalise the path |
| 321 | path = urlparse(path.decodescip-python python python-stdlib 3.11 builtins/bytes#decode().()).path |
| 322 | try: |
| 323 | __, upload_id, filename = path.splitscip-python python python-stdlib 3.11 builtins/str#split().("/") |
| 324 | except ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#: |
| 325 | raise exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.DataErrorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/DataError#("no enought path elements") |
| 326 | if len(upload_id) < 10: |
| 327 | raise exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.DataErrorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/DataError#( |
| 328 | f"invalid upload ID received for a PUT: {upload_id!r}" |
| 329 | ) |
| 330 | |
| 331 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data().(self)._upload_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#_upload_data. = (upload_id, filename) |
| 332 | return selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data().(self)._upload_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#_upload_data. |
| 333 | |
| 334 | @propertyscip-python python python-stdlib 3.11 builtins/property# |
| 335 | def file_sharingscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#file_sharing().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#file_sharing().(self)): |
| 336 | return selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#file_sharing().(self).channel.site.file_sharing |
| 337 | |
| 338 | @propertyscip-python python python-stdlib 3.11 builtins/property# |
| 339 | def file_tmp_dirscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#file_tmp_dir().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#file_tmp_dir().(self)): |
| 340 | return selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#file_tmp_dir().(self).channel.site.file_tmp_dir |
| 341 | |
| 342 | def refuse_requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().(self)): |
| 343 | if selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().(self).contentscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#content. is not None: |
| 344 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().(self).contentscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#content..closescip-python python python-stdlib 3.11 io/IOBase#close().() |
| 345 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().(self).contentscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#content. = openscip-python python python-stdlib 3.11 builtins/open().(osscip-python python python-stdlib 3.11 os/__init__:.devnullscip-python python python-stdlib 3.11 os/devnull.devnull., "w+b") |
| 346 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().(self).channel._respondToBadRequestAndDisconnect() |
| 347 | |
| 348 | def gotLengthscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self), lengthscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(length)): |
| 349 | if selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).channel._command.decodescip-python python python-stdlib 3.11 builtins/bytes#decode().().upperscip-python python python-stdlib 3.11 builtins/str#upper().() == "PUT": |
| 350 | # for PUT we check early if upload_id is fine, to avoid buffering a file we'll refuse |
| 351 | # we buffer the file in component's TMP_BUFFER_DIR, so we just have to rename it at the end |
| 352 | try: |
| 353 | upload_id, filename = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).upload_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_data(). |
| 354 | except exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.DataErrorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/DataError# as e: |
| 355 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..warningscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#warning().(f"Invalid PUT request, we stop here: {e}") |
| 356 | return selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).refuse_requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().() |
| 357 | try: |
| 358 | client, upload_request, timer = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).file_sharingscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#file_sharing()..expected_uploads.pop( |
| 359 | upload_id |
| 360 | ) |
| 361 | except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: |
| 362 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..warningscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#warning().( |
| 363 | f"unknown (expired?) upload ID received for a PUT: {upload_id!r}" |
| 364 | ) |
| 365 | return selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).refuse_requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().() |
| 366 | |
| 367 | if not timer.active: |
| 368 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..warningscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#warning().(f"upload id {upload_id!r} used for a PUT, but it is expired") |
| 369 | return selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).refuse_requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().() |
| 370 | |
| 371 | timer.cancel() |
| 372 | |
| 373 | if upload_request.filename != filename: |
| 374 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..warningscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#warning().( |
| 375 | f"invalid filename for PUT (upload id: {upload_id!r}, URL:" |
| 376 | f" {selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).channel._path.decodescip-python python python-stdlib 3.11 builtins/bytes#decode().()}). Original" |
| 377 | f" {upload_request.filename!r} doesn't match {filename!r}" |
| 378 | ) |
| 379 | return selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).refuse_requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#refuse_request().() |
| 380 | |
| 381 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).upload_request_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#upload_request_data. = (client, upload_request) |
| 382 | |
| 383 | file_tmp_path = files_utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.files_utils`/__init__:.get_unique_namescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.files_utils`/get_unique_name().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).file_tmp_dirscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#file_tmp_dir(). / upload_id) |
| 384 | |
| 385 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(self).contentscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#content. = openscip-python python python-stdlib 3.11 builtins/open().(file_tmp_path, "w+b") |
| 386 | else: |
| 387 | return superscip-python python python-stdlib 3.11 builtins/super#().gotLength(lengthscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest#gotLength().(length)) |
| 388 | |
| 389 | |
| 390 | class FileSharingSitescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#(serverscip-python python Twisted 26.4.0 `twisted.web.server`/__init__:.Site): |
| 391 | requestFactoryscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#requestFactory. = FileSharingRequestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingRequest# |
| 392 | |
| 393 | def __init__scip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#__init__().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#__init__().(self), file_sharingscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#__init__().(file_sharing)): |
| 394 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#__init__().(self).file_sharingscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#file_sharing. = file_sharingscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#__init__().(file_sharing) |
| 395 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#__init__().(self).file_tmp_dirscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#file_tmp_dir. = file_sharingscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#__init__().(file_sharing).host.get_local_path( |
| 396 | None, Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.FILES_TMP_DIRscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#FILES_TMP_DIR., TMP_BUFFER_DIRscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/TMP_BUFFER_DIR., component=True |
| 397 | ) |
| 398 | for old_file in selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#__init__().(self).file_tmp_dirscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#file_tmp_dir..iterdir(): |
| 399 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..debugscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#debug().(f"purging old buffer file at {old_file}") |
| 400 | old_file.unlink() |
| 401 | superscip-python python python-stdlib 3.11 builtins/super#().__init__(HTTPFileServerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HTTPFileServer#()) |
| 402 | |
| 403 | def getContentFilescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#getContentFile().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#getContentFile().(self), lengthscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#getContentFile().(length)): |
| 404 | file_tmp_path = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#getContentFile().(self).file_tmp_dirscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#file_tmp_dir. / shortuuidscip-python python shortuuid 1.0.13 shortuuid/__init__:.uuid() |
| 405 | return openscip-python python python-stdlib 3.11 builtins/open().(file_tmp_path, "w+b") |
| 406 | |
| 407 | |
| 408 | class FileSharingscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#: |
| 409 | |
| 410 | def __init__scip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#__init__().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#__init__().(self), hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#__init__().(host)): |
| 411 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#__init__().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host. = hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#__init__().(host) |
| 412 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#__init__().(self).initialisedscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#initialised. = False |
| 413 | |
| 414 | def initscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)): |
| 415 | # we init once on first component connection, |
| 416 | # there is not need to init this plugin if not component use it |
| 417 | # TODO: this plugin should not be loaded at all if no component uses it |
| 418 | # and should be loaded dynamically as soon as a suitable profile is created |
| 419 | if selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).initialisedscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#initialised.: |
| 420 | return |
| 421 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).initialisedscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#initialised. = True |
| 422 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).settingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#settings. = Gscip-python python libervia-backend 0.9.0.dev0 `libervia.backend`/G..configscip-python python libervia-backend 0.9.0.dev0 `libervia.backend`/Global#config()..get_settingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/Settings#get_settings().(FileSharingSettingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#) |
| 423 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..infoscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#info().(_("File Sharing initialization")) |
| 424 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._fscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_f. = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..plugins["FILE"] |
| 425 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._jfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_jf. = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..plugins["XEP-0234"] |
| 426 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._hscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_h. = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..plugins["XEP-0300"] |
| 427 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._tscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_t. = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..plugins["XEP-0264"] |
| 428 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._huscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_hu. = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..plugins["XEP-0363"] |
| 429 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._huscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_hu..register_handler(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._on_http_uploadscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().) |
| 430 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..trigger.add_with_check( |
| 431 | "FILE_getDestDir", selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self), selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._get_dest_dir_triggerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger(). |
| 432 | ) |
| 433 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..trigger.add_with_check( |
| 434 | "XEP-0234_fileSendingRequest", |
| 435 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self), |
| 436 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._file_sending_request_triggerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger()., |
| 437 | priority=1000, |
| 438 | ) |
| 439 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..trigger.add_with_check( |
| 440 | "XEP-0234_buildFileElement", selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self), selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._add_file_metadata_eltsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts(). |
| 441 | ) |
| 442 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..trigger.add_with_check( |
| 443 | "XEP-0234_parseFileElement", selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self), selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._get_file_metadata_eltsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts(). |
| 444 | ) |
| 445 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..trigger.add_with_check( |
| 446 | "XEP-0329_compGetFilesFromNode", selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self), selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._add_file_metadatascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata(). |
| 447 | ) |
| 448 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..trigger.add_with_check( |
| 449 | "XEP-0329_compGetFilesFromNode_build_directory", |
| 450 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self), |
| 451 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._add_directory_metadata_eltsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts()., |
| 452 | ) |
| 453 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..trigger.add_with_check( |
| 454 | "XEP-0329_parseResult_directory", selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self), selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)._get_directory_metadata_eltsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_directory_metadata_elts(). |
| 455 | ) |
| 456 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).files_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#files_path. = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..get_local_path(None, Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.FILES_DIRscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#FILES_DIR.) |
| 457 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).http_portscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#http_port. = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).settingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#settings..http_upload_portscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#http_upload_port. |
| 458 | connection_type = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).settingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#settings..http_upload_connection_typescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#http_upload_connection_type. |
| 459 | if connection_type not in ("http", "https"): |
| 460 | raise exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.ConfigErrorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/ConfigError#( |
| 461 | 'bad http_upload_connection_type, you must use one of "http" or "https"' |
| 462 | ) |
| 463 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).serverscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#server. = FileSharingSitescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSite#(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self)) |
| 464 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).expected_uploadsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#expected_uploads. = {} |
| 465 | if connection_type == "http": |
| 466 | reactor.listenTCP(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).http_portscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#http_port., selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).serverscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#server.) |
| 467 | else: |
| 468 | options = tlsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.tls`/__init__:.get_options_from_configscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.tls`/get_options_from_config().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).settingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#settings..tlsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#tls.) |
| 469 | tlsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.tls`/__init__:.tls_options_checkscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.tls`/tls_options_check().(options) |
| 470 | context_factory = tlsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.tls`/__init__:.get_tls_context_factoryscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.tls`/get_tls_context_factory().(options) |
| 471 | reactor.listenSSL(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).http_portscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#http_port., selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().(self).serverscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#server., context_factory) |
| 472 | |
| 473 | def get_handlerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_handler().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_handler().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_handler().(client)): |
| 474 | return Comments_handlerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_handler().(self)) |
| 475 | |
| 476 | def profile_connectingscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(client)): |
| 477 | # we activate HTTP upload |
| 478 | clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(client).enabled_features.add("XEP-0363") |
| 479 | |
| 480 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(self).initscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#init().() |
| 481 | public_base_url = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(self).settingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#settings..public_urlscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#public_url. |
| 482 | if public_base_url is None: |
| 483 | clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(client)._file_sharing_base_url = f"https://{clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(client).host}:{selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(self).http_portscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#http_port.}" |
| 484 | else: |
| 485 | clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(client)._file_sharing_base_url = public_base_url |
| 486 | path = clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(client).file_tmp_dir = osscip-python python python-stdlib 3.11 os/__init__:.path.joinscip-python python python-stdlib 3.11 posixpath/abspath().( |
| 487 | Gscip-python python libervia-backend 0.9.0.dev0 `libervia.backend`/G..configscip-python python libervia-backend 0.9.0.dev0 `libervia.backend`/Global#config()..commonscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/Settings#common..local_dirscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.config`/CommonSettings#local_dir., |
| 488 | Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.FILES_TMP_DIRscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#FILES_TMP_DIR., |
| 489 | regexscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.regex`/__init__:.path_escapescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.regex`/path_escape().(clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#profile_connecting().(client).profile), |
| 490 | ) |
| 491 | if not osscip-python python python-stdlib 3.11 os/__init__:.path.existsscip-python python python-stdlib 3.11 posixpath/abspath().(path): |
| 492 | osscip-python python python-stdlib 3.11 os/__init__:.makedirsscip-python python python-stdlib 3.11 os/makedirs().(path) |
| 493 | |
| 494 | def get_quotascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_quota().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_quota().(self), entityscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_quota().(entity): jidscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.jid`/__init__:.JID) -> intscip-python python python-stdlib 3.11 builtins/int# | None: |
| 495 | """Get the maximum file storage quota for a given entity. |
| 496 | |
| 497 | @param entity: The JID to check quota for. |
| 498 | @return: The maximum allowed size in bytes, or None if no quota is set. |
| 499 | """ |
| 500 | entity_bare = entityscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_quota().(entity).userhostJID() |
| 501 | quotas = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_quota().(self).settingsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#settings..quotasscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharingSettings#quotas. |
| 502 | quota = quotas.jidsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#jids..getscip-python python python-stdlib 3.11 builtins/dict#get().(entity_bare) |
| 503 | if not quota: |
| 504 | is_admin = Gscip-python python libervia-backend 0.9.0.dev0 `libervia.backend`/G..hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend`/Global#host()..memoryscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.main`/LiberviaBackend#memory..is_admin_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.memory.memory`/Memory#is_admin_jid().(entity_bare) |
| 505 | quota = quotas.adminsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#admins. if is_admin else quotas.usersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/QuotasSettings#users. |
| 506 | return quota |
| 507 | |
| 508 | async def generate_thumbnailsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(self), extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(extra): dictscip-python python python-stdlib 3.11 builtins/dict#, image_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(image_path): Pathscip-python python python-stdlib 3.11 pathlib/Path#): |
| 509 | thumbnails = extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(extra).setdefaultscip-python python python-stdlib 3.11 typing/MutableMapping#setdefault().(Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.KEY_THUMBNAILSscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#KEY_THUMBNAILS., []) |
| 510 | for max_thumb_size in selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(self)._tscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_t..SIZES: |
| 511 | try: |
| 512 | thumb_size, thumb_id = await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(self)._tscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_t..generate_thumbnail( |
| 513 | image_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(image_path), |
| 514 | max_thumb_size, |
| 515 | # we keep thumbnails for 6 months |
| 516 | 60 * 60 * 24 * 31 * 6, |
| 517 | ) |
| 518 | except Exceptionscip-python python python-stdlib 3.11 builtins/Exception# as e: |
| 519 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..warningscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#warning().(_("Can't create thumbnail: {reason}").format(reason=e)) |
| 520 | break |
| 521 | thumbnails.append({"id": thumb_id, "size": thumb_size}) |
| 522 | |
| 523 | async def register_received_filescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().( |
| 524 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(client), peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(peer_jid), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_data), file_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_path), public_idscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(public_id)=None, extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(extra)=None |
| 525 | ): |
| 526 | """Post file reception tasks |
| 527 | |
| 528 | once file is received, this method create hash/thumbnails if necessary |
| 529 | move the file to the right location, and create metadata entry in database |
| 530 | """ |
| 531 | name = file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_data)["name"] |
| 532 | if extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(extra) is None: |
| 533 | extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(extra) = {} |
| 534 | |
| 535 | mime_type = file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_data).get("mime_type") |
| 536 | if not mime_type or mime_type == "application/octet-stream": |
| 537 | mime_type = mimetypesscip-python python python-stdlib 3.11 mimetypes/__init__:.guess_typescip-python python python-stdlib 3.11 mimetypes/guess_type().(name)[0] |
| 538 | |
| 539 | is_image = mime_type is not None and mime_type.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().("image") |
| 540 | is_video = mime_type is not None and mime_type.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().("video") |
| 541 | |
| 542 | if file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_data).get("hash_algo") == HASH_ALGOscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HASH_ALGO.: |
| 543 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..debugscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#debug().(_("Reusing already generated hash")) |
| 544 | file_hash = file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_data)["hash_hasher"].hexdigest() |
| 545 | else: |
| 546 | hasher = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(self)._hscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_h..get_hasher(HASH_ALGOscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HASH_ALGO.) |
| 547 | with file_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_path).open("rb") as f: |
| 548 | file_hash = await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(self)._hscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_h..calculate_hash(f, hasher) |
| 549 | final_path = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(self).files_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#files_path. / file_hash |
| 550 | |
| 551 | if final_path.is_file(): |
| 552 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..debugscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#debug().( |
| 553 | "file [{file_hash}] already exists, we can remove temporary one".format( |
| 554 | file_hash=file_hash |
| 555 | ) |
| 556 | ) |
| 557 | file_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_path).unlink() |
| 558 | else: |
| 559 | file_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_path).rename(final_path) |
| 560 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..debugscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#debug().( |
| 561 | "file [{file_hash}] moved to {files_path}".format( |
| 562 | file_hash=file_hash, files_path=selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(self).files_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#files_path. |
| 563 | ) |
| 564 | ) |
| 565 | |
| 566 | if is_image: |
| 567 | await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(self).generate_thumbnailsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(extra), final_path) |
| 568 | elif is_video: |
| 569 | with tempfilescip-python python python-stdlib 3.11 tempfile/__init__:.TemporaryDirectoryscip-python python python-stdlib 3.11 tempfile/TemporaryDirectory#() as tmp_dir: |
| 570 | thumb_path = Pathscip-python python python-stdlib 3.11 pathlib/Path#(tmp_dir) / "thumbnail.jpg" |
| 571 | try: |
| 572 | await videoscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.video`/__init__:.get_thumbnailscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.video`/get_thumbnail().(final_path, thumb_path) |
| 573 | except Exceptionscip-python python python-stdlib 3.11 builtins/Exception# as e: |
| 574 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..warningscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#warning().( |
| 575 | _("Can't get thumbnail for {final_path}: {e}").format( |
| 576 | final_path=final_path, e=e |
| 577 | ) |
| 578 | ) |
| 579 | else: |
| 580 | await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(self).generate_thumbnailsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#generate_thumbnails().(extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(extra), thumb_path) |
| 581 | |
| 582 | await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..memory.set_file( |
| 583 | clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(client), |
| 584 | name=name, |
| 585 | version="", |
| 586 | file_hash=file_hash, |
| 587 | hash_algo=HASH_ALGOscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/HASH_ALGO., |
| 588 | size=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_data)["size"], |
| 589 | path=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_data).get("path"), |
| 590 | namespace=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(file_data).get("namespace"), |
| 591 | mime_type=mime_type, |
| 592 | public_id=public_idscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(public_id), |
| 593 | owner=peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(peer_jid), |
| 594 | extra=extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(extra), |
| 595 | ) |
| 596 | |
| 597 | async def _get_dest_dir_triggerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().( |
| 598 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(client), peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(peer_jid), transfer_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(transfer_data), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(file_data), stream_objectscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(stream_object) |
| 599 | ): |
| 600 | """This trigger accept file sending request, and store file locally""" |
| 601 | if not clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(client).is_component: |
| 602 | return True, None |
| 603 | # client._file_sharing_allowed_hosts is set in plugin XEP-0329 |
| 604 | if peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(peer_jid).host not in clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(client)._file_sharing_allowed_hosts: |
| 605 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("forbidden") |
| 606 | assert stream_objectscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(stream_object) |
| 607 | assert "stream_object" not in transfer_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(transfer_data) |
| 608 | assert Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.KEY_PROGRESS_IDscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#KEY_PROGRESS_ID. in file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(file_data) |
| 609 | filename = file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(file_data)["name"] |
| 610 | assert filename and not "/" in filename |
| 611 | quota = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(self).get_quotascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_quota().(peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(peer_jid)) |
| 612 | if quota is not None: |
| 613 | used_space = await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..memory.file_get_used_space(clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(client), peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(peer_jid)) |
| 614 | |
| 615 | if (used_space + file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(file_data)["size"]) > quota: |
| 616 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError( |
| 617 | "not-acceptable", |
| 618 | text=OVER_QUOTA_TXTscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/OVER_QUOTA_TXT..format( |
| 619 | quota=utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/__init__:.get_human_sizescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/get_human_size().(quota), |
| 620 | used_space=utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/__init__:.get_human_sizescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/get_human_size().(used_space), |
| 621 | file_size=utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/__init__:.get_human_sizescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/get_human_size().(file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(file_data)["size"]), |
| 622 | ), |
| 623 | ) |
| 624 | file_tmp_dir = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..get_local_path( |
| 625 | None, Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.FILES_TMP_DIRscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#FILES_TMP_DIR., peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(peer_jid).userhost(), component=True |
| 626 | ) |
| 627 | file_tmp_path = file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(file_data)["file_path"] = files_utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.files_utils`/__init__:.get_unique_namescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.files_utils`/get_unique_name().( |
| 628 | file_tmp_dir / filename |
| 629 | ) |
| 630 | |
| 631 | transfer_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(transfer_data)["finished_d"].addCallback( |
| 632 | lambda __: deferscip-python python Twisted 26.4.0 `twisted.internet.defer`/__init__:.ensureDeferred( |
| 633 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(self).register_received_filescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#register_received_file().(clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(client), peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(peer_jid), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(file_data), file_tmp_path) |
| 634 | ) |
| 635 | ) |
| 636 | |
| 637 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(self)._fscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_f..open_file_write( |
| 638 | clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(client), file_tmp_path, transfer_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(transfer_data), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(file_data), stream_objectscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_dest_dir_trigger().(stream_object) |
| 639 | ) |
| 640 | return False, True |
| 641 | |
| 642 | async def _retrieve_filesscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().( |
| 643 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(client), sessionscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(session), content_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(content_data), content_namescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(content_name), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data), file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_elt) |
| 644 | ): |
| 645 | """This method retrieve a file on request, and send if after checking permissions""" |
| 646 | peer_jid = sessionscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(session)["peer_jid"] |
| 647 | if sessionscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(session)["local_jid"].user: |
| 648 | owner = clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(client).get_owner_from_jid(sessionscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(session)["local_jid"]) |
| 649 | else: |
| 650 | owner = peer_jid |
| 651 | try: |
| 652 | found_files = await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..memory.get_files( |
| 653 | clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(client), |
| 654 | peer_jid=peer_jid, |
| 655 | name=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data).get("name"), |
| 656 | file_hash=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data).get("file_hash"), |
| 657 | hash_algo=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data).get("hash_algo"), |
| 658 | path=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data).get("path"), |
| 659 | namespace=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data).get("namespace"), |
| 660 | owner=owner, |
| 661 | ) |
| 662 | except exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.NotFoundscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/NotFound#: |
| 663 | found_files = None |
| 664 | except exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.PermissionErrorscip-python python python-stdlib 3.11 builtins/PermissionError#: |
| 665 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..warningscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#warning().( |
| 666 | _("{peer_jid} is trying to access an unauthorized file: {name}").format( |
| 667 | peer_jid=peer_jid, name=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data).get("name") |
| 668 | ) |
| 669 | ) |
| 670 | return False |
| 671 | |
| 672 | if not found_files: |
| 673 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..warningscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#warning().( |
| 674 | _("no matching file found ({file_data})").format(file_data=file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data)) |
| 675 | ) |
| 676 | return False |
| 677 | |
| 678 | # we only use the first found file |
| 679 | found_file = found_files[0] |
| 680 | if found_file["type"] != Cscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#.FILE_TYPE_FILEscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.constants`/Const#FILE_TYPE_FILE.: |
| 681 | raise TypeErrorscip-python python python-stdlib 3.11 builtins/TypeError#( |
| 682 | "a file was expected, type is {type_}".format(type_=found_file["type"]) |
| 683 | ) |
| 684 | file_hash = found_file["file_hash"] |
| 685 | file_path = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(self).files_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#files_path. / file_hash |
| 686 | file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data)["hash_hasher"] = hasher = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(self)._hscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_h..get_hasher(found_file["hash_algo"]) |
| 687 | size = file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data)["size"] = found_file["size"] |
| 688 | file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data)["file_hash"] = file_hash |
| 689 | file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data)["hash_algo"] = found_file["hash_algo"] |
| 690 | |
| 691 | # we complete file_elt so peer can have some details on the file |
| 692 | if "name" not in file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_data): |
| 693 | file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_elt).addElement("name", content=found_file["name"]) |
| 694 | file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(file_elt).addElement("size", content=strscip-python python python-stdlib 3.11 builtins/str#(size)) |
| 695 | content_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(content_data)["stream_object"] = streamscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.stream`/__init__:.FileStreamObjectscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.stream`/FileStreamObject#( |
| 696 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host., |
| 697 | clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(client), |
| 698 | file_path, |
| 699 | uid=selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(self)._jfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_jf..get_progress_id(sessionscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(session), content_namescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().(content_name)), |
| 700 | size=size, |
| 701 | data_cb=lambda data: hasher.update(data), |
| 702 | ) |
| 703 | return True |
| 704 | |
| 705 | def _file_sending_request_triggerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().( |
| 706 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(client), sessionscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(session), content_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(content_data), content_namescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(content_name), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(file_data), file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(file_elt) |
| 707 | ): |
| 708 | if not clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(client).is_component: |
| 709 | return True, None |
| 710 | else: |
| 711 | return ( |
| 712 | False, |
| 713 | deferscip-python python Twisted 26.4.0 `twisted.internet.defer`/__init__:.ensureDeferred( |
| 714 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(self)._retrieve_filesscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_retrieve_files().( |
| 715 | clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(client), sessionscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(session), content_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(content_data), content_namescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(content_name), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(file_data), file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_file_sending_request_trigger().(file_elt) |
| 716 | ) |
| 717 | ), |
| 718 | ) |
| 719 | |
| 720 | ## HTTP Upload ## |
| 721 | |
| 722 | def _purge_slotscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_purge_slot().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_purge_slot().(self), upload_idscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_purge_slot().(upload_id)): |
| 723 | try: |
| 724 | del selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_purge_slot().(self).expected_uploadsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#expected_uploads.[upload_idscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_purge_slot().(upload_id)] |
| 725 | except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: |
| 726 | logscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/log..errorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.log`/Logger#error().(f"trying to purge an inexisting upload slot ({upload_idscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_purge_slot().(upload_id)})") |
| 727 | |
| 728 | async def _on_http_uploadscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(client), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(request)): |
| 729 | # filename should be already cleaned, but it's better to double check |
| 730 | assert "/" not in requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(request).filename |
| 731 | # client._file_sharing_allowed_hosts is set in plugin XEP-0329 |
| 732 | if requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(request).from_.host not in clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(client)._file_sharing_allowed_hosts: |
| 733 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("forbidden") |
| 734 | |
| 735 | quota = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(self).get_quotascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#get_quota().(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(request).from_) |
| 736 | if quota is not None: |
| 737 | used_space = await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#host..memory.file_get_used_space(clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(client), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(request).from_) |
| 738 | |
| 739 | if (used_space + requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(request).size) > quota: |
| 740 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError( |
| 741 | "not-acceptable", |
| 742 | text=OVER_QUOTA_TXTscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/OVER_QUOTA_TXT..format( |
| 743 | quota=utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/__init__:.get_human_sizescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/get_human_size().(quota), |
| 744 | used_space=utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/__init__:.get_human_sizescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/get_human_size().(used_space), |
| 745 | file_size=utilsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/__init__:.get_human_sizescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.utils`/get_human_size().(requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(request).size), |
| 746 | ), |
| 747 | appCondition=selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(self)._huscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_hu..get_file_too_large_elt( |
| 748 | maxscip-python python python-stdlib 3.11 builtins/max().(quota - used_space, 0) |
| 749 | ), |
| 750 | ) |
| 751 | |
| 752 | upload_id = shortuuidscip-python python shortuuid 1.0.13 shortuuid/__init__:.ShortUUIDscip-python python libervia-backend 0.9.0.dev0 `shortuuid.main`/ShortUUID#().random(length=30) |
| 753 | assert "/" not in upload_id |
| 754 | timer = reactor.callLater(30, selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(self)._purge_slotscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_purge_slot()., upload_id) |
| 755 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(self).expected_uploadsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#expected_uploads.[upload_id] = (clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(client), requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(request), timer) |
| 756 | url = urljoin(clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(client)._file_sharing_base_url, f"{upload_id}/{requestscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(request).filename}") |
| 757 | slot = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_on_http_upload().(self)._huscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_hu..Slot( |
| 758 | put=url, |
| 759 | get=url, |
| 760 | headers=[], |
| 761 | ) |
| 762 | return slot |
| 763 | |
| 764 | ## metadata triggers ## |
| 765 | |
| 766 | def _add_file_metadata_eltsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(client), file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(file_elt), extra_argsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(extra_args)): |
| 767 | # affiliation |
| 768 | affiliation = extra_argsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(extra_args).get("affiliation") |
| 769 | if affiliation is not None: |
| 770 | file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(file_elt).addElement((NS_FS_AFFILIATIONscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/NS_FS_AFFILIATION., "affiliation"), content=affiliation) |
| 771 | |
| 772 | # comments |
| 773 | try: |
| 774 | comments_url = extra_argsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(extra_args).pop("comments_url") |
| 775 | except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: |
| 776 | return |
| 777 | |
| 778 | comment_elt = file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(file_elt).addElement((NS_COMMENTSscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/NS_COMMENTS., "comments"), content=comments_url) |
| 779 | |
| 780 | try: |
| 781 | count = len(extra_argsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata_elts().(extra_args)["extra"]["comments"]) |
| 782 | except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: |
| 783 | count = 0 |
| 784 | |
| 785 | comment_elt["count"] = strscip-python python python-stdlib 3.11 builtins/str#(count) |
| 786 | return True |
| 787 | |
| 788 | def _get_file_metadata_eltsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(client), file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(file_elt), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(file_data)): |
| 789 | # affiliation |
| 790 | try: |
| 791 | affiliation_elt = nextscip-python python python-stdlib 3.11 builtins/next().(file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(file_elt).elements(NS_FS_AFFILIATIONscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/NS_FS_AFFILIATION., "affiliation")) |
| 792 | except StopIterationscip-python python python-stdlib 3.11 builtins/StopIteration#: |
| 793 | pass |
| 794 | else: |
| 795 | file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(file_data)["affiliation"] = strscip-python python python-stdlib 3.11 builtins/str#(affiliation_elt) |
| 796 | |
| 797 | # comments |
| 798 | try: |
| 799 | comments_elt = nextscip-python python python-stdlib 3.11 builtins/next().(file_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(file_elt).elements(NS_COMMENTSscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/NS_COMMENTS., "comments")) |
| 800 | except StopIterationscip-python python python-stdlib 3.11 builtins/StopIteration#: |
| 801 | pass |
| 802 | else: |
| 803 | file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(file_data)["comments_url"] = strscip-python python python-stdlib 3.11 builtins/str#(comments_elt) |
| 804 | file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_file_metadata_elts().(file_data)["comments_count"] = comments_elt["count"] |
| 805 | return True |
| 806 | |
| 807 | def _add_file_metadatascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().( |
| 808 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().(client), iq_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().(iq_elt), iq_result_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().(iq_result_elt), ownerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().(owner), node_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().(node_path), files_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().(files_data) |
| 809 | ): |
| 810 | for file_data in files_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().(files_data): |
| 811 | file_data["comments_url"] = uriscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.uri`/__init__:.build_xmpp_uriscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.common.uri`/build_xmpp_uri().( |
| 812 | "pubsub", |
| 813 | path=clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_file_metadata().(client).jid.full(), |
| 814 | node=COMMENT_NODE_PREFIXscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/COMMENT_NODE_PREFIX. + file_data["id"], |
| 815 | ) |
| 816 | return True |
| 817 | |
| 818 | def _add_directory_metadata_eltsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts().( |
| 819 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts().(client), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts().(file_data), directory_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts().(directory_elt), ownerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts().(owner), node_pathscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts().(node_path) |
| 820 | ): |
| 821 | affiliation = file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts().(file_data).get("affiliation") |
| 822 | if affiliation is not None: |
| 823 | directory_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_add_directory_metadata_elts().(directory_elt).addElement( |
| 824 | (NS_FS_AFFILIATIONscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/NS_FS_AFFILIATION., "affiliation"), content=affiliation |
| 825 | ) |
| 826 | |
| 827 | def _get_directory_metadata_eltsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_directory_metadata_elts().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_directory_metadata_elts().(self), clientscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_directory_metadata_elts().(client), eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_directory_metadata_elts().(elt), file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_directory_metadata_elts().(file_data)): |
| 828 | try: |
| 829 | affiliation_elt = nextscip-python python python-stdlib 3.11 builtins/next().(eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_directory_metadata_elts().(elt).elements(NS_FS_AFFILIATIONscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/NS_FS_AFFILIATION., "affiliation")) |
| 830 | except StopIterationscip-python python python-stdlib 3.11 builtins/StopIteration#: |
| 831 | pass |
| 832 | else: |
| 833 | file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/FileSharing#_get_directory_metadata_elts().(file_data)["affiliation"] = strscip-python python python-stdlib 3.11 builtins/str#(affiliation_elt) |
| 834 | |
| 835 | |
| 836 | class Comments_handlerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#(pubsubscip-python python libervia-backend 0.9.0.dev0 `tx_xmpp.pubsub`/__init__:.PubSubService): |
| 837 | """This class is a minimal Pubsub service handling virtual nodes for comments""" |
| 838 | |
| 839 | def __init__scip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#__init__().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#__init__().(self), plugin_parentscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#__init__().(plugin_parent)): |
| 840 | superscip-python python python-stdlib 3.11 builtins/super#(Comments_handlerscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#, selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#__init__().(self)).__init__() |
| 841 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#__init__().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#host. = plugin_parentscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#__init__().(plugin_parent).host |
| 842 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#__init__().(self).plugin_parentscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#plugin_parent. = plugin_parentscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#__init__().(plugin_parent) |
| 843 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#__init__().(self).discoIdentityscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#discoIdentity. = { |
| 844 | "category": "pubsub", |
| 845 | "type": ( |
| 846 | "virtual" |
| 847 | ), # FIXME: non standard, here to avoid this service being considered as main pubsub one |
| 848 | "name": "files commenting service", |
| 849 | } |
| 850 | |
| 851 | def _get_file_idscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_file_id().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_file_id().(self), nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_file_id().(nodeIdentifier)): |
| 852 | if not nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_file_id().(nodeIdentifier).startswith(COMMENT_NODE_PREFIXscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/COMMENT_NODE_PREFIX.): |
| 853 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("item-not-found") |
| 854 | file_id = nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_file_id().(nodeIdentifier)[len(COMMENT_NODE_PREFIXscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/COMMENT_NODE_PREFIX.) :] |
| 855 | if not file_id: |
| 856 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("item-not-found") |
| 857 | return file_id |
| 858 | |
| 859 | async def get_file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(self), requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(requestor), nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(nodeIdentifier)): |
| 860 | file_id = selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(self)._get_file_idscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_file_id().(nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(nodeIdentifier)) |
| 861 | try: |
| 862 | files = await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#host..memory.get_files(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(self).parent, requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(requestor), file_id) |
| 863 | except (exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.NotFoundscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/NotFound#, exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.PermissionErrorscip-python python python-stdlib 3.11 builtins/PermissionError#): |
| 864 | # we don't differenciate between NotFound and PermissionError |
| 865 | # to avoid leaking information on existing files |
| 866 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("item-not-found") |
| 867 | if not files: |
| 868 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("item-not-found") |
| 869 | if len(files) > 1: |
| 870 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.InternalError("there should be only one file") |
| 871 | return files[0] |
| 872 | |
| 873 | def comments_updatescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(self), extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(extra), new_commentsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(new_comments), peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(peer_jid)): |
| 874 | """update comments (replace or insert new_comments) |
| 875 | |
| 876 | @param extra(dict): extra data to update |
| 877 | @param new_comments(list[tuple(unicode, unicode, unicode)]): comments to update or insert |
| 878 | @param peer_jid(unicode, None): bare jid of the requestor, or None if request is done by owner |
| 879 | """ |
| 880 | current_comments = extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(extra).setdefault("comments", []) |
| 881 | new_comments_by_id = {c[0]: c for c in new_commentsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(new_comments)} |
| 882 | updated = [] |
| 883 | # we now check every current comment, to see if one id in new ones |
| 884 | # exist, in which case we must update |
| 885 | for idx, comment in enumeratescip-python python python-stdlib 3.11 builtins/enumerate#(current_comments): |
| 886 | comment_id = comment[0] |
| 887 | if comment_id in new_comments_by_id: |
| 888 | # a new comment has an existing id, update is requested |
| 889 | if peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(peer_jid) and comment[1] != peer_jidscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(peer_jid): |
| 890 | # requestor has not the right to modify the comment |
| 891 | raise exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.PermissionErrorscip-python python python-stdlib 3.11 builtins/PermissionError# |
| 892 | # we replace old_comment with updated one |
| 893 | new_comment = new_comments_by_id[comment_id] |
| 894 | current_comments[idx] = new_comment |
| 895 | updated.appendscip-python python python-stdlib 3.11 builtins/list#append().(new_comment) |
| 896 | |
| 897 | # we now remove every updated comments, to only keep |
| 898 | # the ones to insert |
| 899 | for comment in updated: |
| 900 | new_commentsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(new_comments).remove(comment) |
| 901 | |
| 902 | current_comments.extend(new_commentsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update().(new_comments)) |
| 903 | |
| 904 | def comments_deletescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_delete().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_delete().(self), extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_delete().(extra), commentsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_delete().(comments)): |
| 905 | try: |
| 906 | comments_dict = extrascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_delete().(extra)["comments"] |
| 907 | except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: |
| 908 | return |
| 909 | for comment in commentsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_delete().(comments): |
| 910 | try: |
| 911 | comments_dict.remove(comment) |
| 912 | except ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#: |
| 913 | continue |
| 914 | |
| 915 | def _get_fromscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_from().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_from().(self), item_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_from().(item_elt)): |
| 916 | """retrieve publisher of an item |
| 917 | |
| 918 | @param item_elt(domish.element): <item> element |
| 919 | @return (unicode): full jid as string |
| 920 | """ |
| 921 | iq_elt = item_eltscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_from().(item_elt) |
| 922 | while iq_elt.parent != None: |
| 923 | iq_elt = iq_elt.parent |
| 924 | return iq_elt["from"] |
| 925 | |
| 926 | @ensure_deferredscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.utils`/ensure_deferred(). |
| 927 | async def publishscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(self), requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(requestor), servicescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(service), nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(nodeIdentifier), itemsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(items)): |
| 928 | # we retrieve file a first time to check authorisations |
| 929 | file_data = await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(self).get_file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(requestor), nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(nodeIdentifier)) |
| 930 | file_id = file_data["id"] |
| 931 | comments = [(item["id"], selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(self)._get_fromscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#_get_from().(item), item.toXml()) for item in itemsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(items)] |
| 932 | if requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(requestor).userhostJID() == file_data["owner"]: |
| 933 | peer_jid = None |
| 934 | else: |
| 935 | peer_jid = requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(requestor).userhost() |
| 936 | update_cb = partialscip-python python python-stdlib 3.11 functools/partial#( |
| 937 | selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(self).comments_updatescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_update()., new_comments=comments, peer_jid=peer_jid |
| 938 | ) |
| 939 | try: |
| 940 | await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#publish().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#host..memory.file_update(file_id, "extra", update_cb) |
| 941 | except exceptionsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.core.exceptions`/__init__:.PermissionErrorscip-python python python-stdlib 3.11 builtins/PermissionError#: |
| 942 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("not-authorized") |
| 943 | |
| 944 | @ensure_deferredscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.utils`/ensure_deferred(). |
| 945 | async def itemsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(self), requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(requestor), servicescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(service), nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(nodeIdentifier), maxItemsscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(maxItems), itemIdentifiersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(itemIdentifiers)): |
| 946 | file_data = await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(self).get_file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(requestor), nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(nodeIdentifier)) |
| 947 | comments = file_data["extra"].get("comments", []) |
| 948 | if itemIdentifiersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(itemIdentifiers): |
| 949 | return [genericscip-python python libervia-backend 0.9.0.dev0 `tx_xmpp.generic`/__init__:.parseXml(c[2]) for c in comments if c[0] in itemIdentifiersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#items().(itemIdentifiers)] |
| 950 | else: |
| 951 | return [genericscip-python python libervia-backend 0.9.0.dev0 `tx_xmpp.generic`/__init__:.parseXml(c[2]) for c in comments] |
| 952 | |
| 953 | @ensure_deferredscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.tools.utils`/ensure_deferred(). |
| 954 | async def retractscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(self), requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(requestor), servicescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(service), nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(nodeIdentifier), itemIdentifiersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(itemIdentifiers)): |
| 955 | file_data = await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(self).get_file_datascip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#get_file_data().(requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(requestor), nodeIdentifierscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(nodeIdentifier)) |
| 956 | file_id = file_data["id"] |
| 957 | try: |
| 958 | comments = file_data["extra"]["comments"] |
| 959 | except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: |
| 960 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("item-not-found") |
| 961 | |
| 962 | to_remove = [] |
| 963 | for comment in comments: |
| 964 | comment_id = comment[0] |
| 965 | if comment_id in itemIdentifiersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(itemIdentifiers): |
| 966 | to_remove.appendscip-python python python-stdlib 3.11 builtins/list#append().(comment) |
| 967 | itemIdentifiersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(itemIdentifiers).remove(comment_id) |
| 968 | if not itemIdentifiersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(itemIdentifiers): |
| 969 | break |
| 970 | |
| 971 | if itemIdentifiersscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(itemIdentifiers): |
| 972 | # not all items have been to_remove, we can't continue |
| 973 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("item-not-found") |
| 974 | |
| 975 | if requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(requestor).userhostJID() != file_data["owner"]: |
| 976 | if not all([c[1] == requestorscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(requestor).userhost() for c in to_remove]): |
| 977 | raise errorscip-python python Twisted 26.4.0 `twisted.words.protocols.jabber.error`/__init__:.StanzaError("not-authorized") |
| 978 | |
| 979 | remove_cb = partialscip-python python python-stdlib 3.11 functools/partial#(selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(self).comments_deletescip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#comments_delete()., comments=to_remove) |
| 980 | await selfscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#retract().(self).hostscip-python python libervia-backend 0.9.0.dev0 `libervia.backend.plugins.plugin_comp_file_sharing`/Comments_handler#host..memory.file_update(file_id, "extra", remove_cb) |