From 53385e80d3227784b5c5e87c040043b80aa900bb Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 3 May 2018 13:16:11 +0100 Subject: Add GET media/v1/limits --- synapse/rest/media/v1/limits_resource.py | 34 +++++++++++++++++++++++++++++++ synapse/rest/media/v1/media_repository.py | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 synapse/rest/media/v1/limits_resource.py diff --git a/synapse/rest/media/v1/limits_resource.py b/synapse/rest/media/v1/limits_resource.py new file mode 100644 index 0000000000..d36b243099 --- /dev/null +++ b/synapse/rest/media/v1/limits_resource.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Will Hunt +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import synapse.http.servlet + +from twisted.web.server import NOT_DONE_YET +from twisted.web.resource import Resource +from synapse.http.server import respond_with_json + + +class MediaLimitsResource(Resource): + # isLeaf = True + + def __init__(self, hs): + Resource.__init__(self) + self.limits_dict = {} + config = hs.get_config() + self.limits_dict["size"] = config.max_upload_size + + def render_GET(self, request): + respond_with_json(request, 200, self.limits_dict) + return NOT_DONE_YET diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py index bb79599379..33da948020 100644 --- a/synapse/rest/media/v1/media_repository.py +++ b/synapse/rest/media/v1/media_repository.py @@ -25,6 +25,7 @@ from .download_resource import DownloadResource from .thumbnail_resource import ThumbnailResource from .identicon_resource import IdenticonResource from .preview_url_resource import PreviewUrlResource +from .limits_resource import MediaLimitsResource from .filepath import MediaFilePaths from .thumbnailer import Thumbnailer from .storage_provider import StorageProviderWrapper @@ -745,7 +746,6 @@ class MediaRepositoryResource(Resource): Resource.__init__(self) media_repo = hs.get_media_repository() - self.putChild("upload", UploadResource(hs, media_repo)) self.putChild("download", DownloadResource(hs, media_repo)) self.putChild("thumbnail", ThumbnailResource( @@ -756,3 +756,4 @@ class MediaRepositoryResource(Resource): self.putChild("preview_url", PreviewUrlResource( hs, media_repo, media_repo.media_storage, )) + self.putChild("limits", MediaLimitsResource(hs)) -- cgit 1.4.1 From 39763527b0c343c5f373e4362fe68f354cb1f9d5 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 3 May 2018 16:59:16 +0100 Subject: size > upload_size as per spec feedback --- synapse/rest/media/v1/limits_resource.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/synapse/rest/media/v1/limits_resource.py b/synapse/rest/media/v1/limits_resource.py index d36b243099..7f936d150d 100644 --- a/synapse/rest/media/v1/limits_resource.py +++ b/synapse/rest/media/v1/limits_resource.py @@ -12,12 +12,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -import synapse.http.servlet - +# from twisted.web.server import NOT_DONE_YET from twisted.web.resource import Resource -from synapse.http.server import respond_with_json +from synapse.http.server import respond_with_json, respond_with_json_bytes class MediaLimitsResource(Resource): @@ -27,8 +25,12 @@ class MediaLimitsResource(Resource): Resource.__init__(self) self.limits_dict = {} config = hs.get_config() - self.limits_dict["size"] = config.max_upload_size + self.limits_dict["upload_size"] = config.max_upload_size def render_GET(self, request): - respond_with_json(request, 200, self.limits_dict) + respond_with_json(request, 200, self.limits_dict, send_cors=True) + return NOT_DONE_YET + + def render_OPTIONS(self, request): + respond_with_json_bytes(request, 200, {}, send_cors=True) return NOT_DONE_YET -- cgit 1.4.1 From f8b06fc0d622f8cfd6331f4e570b05bd65388282 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 8 May 2018 15:30:35 +0100 Subject: Make MediaLimitsResource Leafy --- synapse/rest/media/v1/limits_resource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/limits_resource.py b/synapse/rest/media/v1/limits_resource.py index 7f936d150d..64f41191ab 100644 --- a/synapse/rest/media/v1/limits_resource.py +++ b/synapse/rest/media/v1/limits_resource.py @@ -19,7 +19,7 @@ from synapse.http.server import respond_with_json, respond_with_json_bytes class MediaLimitsResource(Resource): - # isLeaf = True + isLeaf = True def __init__(self, hs): Resource.__init__(self) -- cgit 1.4.1 From fee045001a3de4dcda77a70099acc89acd507aec Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 8 May 2018 15:31:53 +0100 Subject: Restructure __init__ --- synapse/rest/media/v1/limits_resource.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/synapse/rest/media/v1/limits_resource.py b/synapse/rest/media/v1/limits_resource.py index 64f41191ab..3cb5f0244b 100644 --- a/synapse/rest/media/v1/limits_resource.py +++ b/synapse/rest/media/v1/limits_resource.py @@ -23,9 +23,10 @@ class MediaLimitsResource(Resource): def __init__(self, hs): Resource.__init__(self) - self.limits_dict = {} config = hs.get_config() - self.limits_dict["upload_size"] = config.max_upload_size + self.limits_dict = { + "upload_size": config.max_upload_size, + } def render_GET(self, request): respond_with_json(request, 200, self.limits_dict, send_cors=True) -- cgit 1.4.1 From c06b1cb0714a0d82d8e3540d4622700f7829685a Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 20 Jun 2018 17:25:51 +0100 Subject: Update and rename limits_resource.py to config_resource.py --- synapse/rest/media/v1/config_resource.py | 37 ++++++++++++++++++++++++++++++++ synapse/rest/media/v1/limits_resource.py | 37 -------------------------------- 2 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 synapse/rest/media/v1/config_resource.py delete mode 100644 synapse/rest/media/v1/limits_resource.py diff --git a/synapse/rest/media/v1/config_resource.py b/synapse/rest/media/v1/config_resource.py new file mode 100644 index 0000000000..5b1e534823 --- /dev/null +++ b/synapse/rest/media/v1/config_resource.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Will Hunt +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from twisted.web.server import NOT_DONE_YET +from twisted.web.resource import Resource +from synapse.http.server import respond_with_json, respond_with_json_bytes + + +class MediaConfigResource(Resource): + isLeaf = True + + def __init__(self, hs): + Resource.__init__(self) + config = hs.get_config() + self.limits_dict = { + "upload_size": config.max_upload_size, + } + + def render_GET(self, request): + respond_with_json(request, 200, self.limits_dict, send_cors=True) + return NOT_DONE_YET + + def render_OPTIONS(self, request): + respond_with_json_bytes(request, 200, {}, send_cors=True) + return NOT_DONE_YET diff --git a/synapse/rest/media/v1/limits_resource.py b/synapse/rest/media/v1/limits_resource.py deleted file mode 100644 index 3cb5f0244b..0000000000 --- a/synapse/rest/media/v1/limits_resource.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Will Hunt -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from twisted.web.server import NOT_DONE_YET -from twisted.web.resource import Resource -from synapse.http.server import respond_with_json, respond_with_json_bytes - - -class MediaLimitsResource(Resource): - isLeaf = True - - def __init__(self, hs): - Resource.__init__(self) - config = hs.get_config() - self.limits_dict = { - "upload_size": config.max_upload_size, - } - - def render_GET(self, request): - respond_with_json(request, 200, self.limits_dict, send_cors=True) - return NOT_DONE_YET - - def render_OPTIONS(self, request): - respond_with_json_bytes(request, 200, {}, send_cors=True) - return NOT_DONE_YET -- cgit 1.4.1 From b1d87771c3d03275e0977d7a92465f5f82267be8 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 20 Jun 2018 17:26:38 +0100 Subject: media limits => config --- synapse/rest/media/v1/media_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py index 33da948020..4f279e235c 100644 --- a/synapse/rest/media/v1/media_repository.py +++ b/synapse/rest/media/v1/media_repository.py @@ -25,7 +25,7 @@ from .download_resource import DownloadResource from .thumbnail_resource import ThumbnailResource from .identicon_resource import IdenticonResource from .preview_url_resource import PreviewUrlResource -from .limits_resource import MediaLimitsResource +from .config_resource import MediaConfigResource from .filepath import MediaFilePaths from .thumbnailer import Thumbnailer from .storage_provider import StorageProviderWrapper -- cgit 1.4.1 From 1d53129fa3525a59c231f2de50b9e12cc5ce60ad Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 21 Jun 2018 11:05:05 +0100 Subject: upload_size => m.upload.size --- synapse/rest/media/v1/config_resource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/config_resource.py b/synapse/rest/media/v1/config_resource.py index 5b1e534823..3fd0288425 100644 --- a/synapse/rest/media/v1/config_resource.py +++ b/synapse/rest/media/v1/config_resource.py @@ -25,7 +25,7 @@ class MediaConfigResource(Resource): Resource.__init__(self) config = hs.get_config() self.limits_dict = { - "upload_size": config.max_upload_size, + "m.upload.size": config.max_upload_size, } def render_GET(self, request): -- cgit 1.4.1 From 0aa14e409349f74d4a64ffb0e21a0d19d24433d7 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 21 Jun 2018 11:09:36 +0100 Subject: /limits => /config --- synapse/rest/media/v1/media_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py index 4f279e235c..c4e094a39f 100644 --- a/synapse/rest/media/v1/media_repository.py +++ b/synapse/rest/media/v1/media_repository.py @@ -756,4 +756,4 @@ class MediaRepositoryResource(Resource): self.putChild("preview_url", PreviewUrlResource( hs, media_repo, media_repo.media_storage, )) - self.putChild("limits", MediaLimitsResource(hs)) + self.putChild("config", MediaConfigResource(hs)) -- cgit 1.4.1 From 87fe4f278d4500e3e5b3cd7e7e44814aedcea3df Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 9 Jul 2018 15:17:12 +0100 Subject: Add import for MediaConfigResource --- synapse/rest/media/v1/media_repository.py | 1 + 1 file changed, 1 insertion(+) diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py index 16485e5519..268cc4a74d 100644 --- a/synapse/rest/media/v1/media_repository.py +++ b/synapse/rest/media/v1/media_repository.py @@ -50,6 +50,7 @@ from .storage_provider import StorageProviderWrapper from .thumbnail_resource import ThumbnailResource from .thumbnailer import Thumbnailer from .upload_resource import UploadResource +from .config_resource import MediaConfigResource logger = logging.getLogger(__name__) -- cgit 1.4.1 From 48251dc94c664cc857c981d767c4c04cd57e7c5e Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 9 Jul 2018 16:09:43 +0100 Subject: Create 3184.feature --- changelog.d/3184.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/3184.feature diff --git a/changelog.d/3184.feature b/changelog.d/3184.feature new file mode 100644 index 0000000000..9f746a57a0 --- /dev/null +++ b/changelog.d/3184.feature @@ -0,0 +1 @@ +Add /_media/r0/config -- cgit 1.4.1 From 3f520b20bd8fb22d82fc9249344fece8b5e314ad Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 18 Jul 2018 14:22:21 +0100 Subject: wrapped --- synapse/rest/media/v1/config_resource.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/config_resource.py b/synapse/rest/media/v1/config_resource.py index 3fd0288425..2272e35b0c 100644 --- a/synapse/rest/media/v1/config_resource.py +++ b/synapse/rest/media/v1/config_resource.py @@ -15,7 +15,7 @@ # from twisted.web.server import NOT_DONE_YET from twisted.web.resource import Resource -from synapse.http.server import respond_with_json, respond_with_json_bytes +from synapse.http.server import respond_with_json, respond_with_json_bytes, wrap_json_request_handler class MediaConfigResource(Resource): @@ -28,6 +28,7 @@ class MediaConfigResource(Resource): "m.upload.size": config.max_upload_size, } + @wrap_json_request_handler def render_GET(self, request): respond_with_json(request, 200, self.limits_dict, send_cors=True) return NOT_DONE_YET -- cgit 1.4.1 From 8cc46ed4a6ec2fe82678f94fd908b9a711372d76 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 27 Jul 2018 12:01:13 +0100 Subject: wrap_json_request_handlering --- synapse/rest/media/v1/config_resource.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/synapse/rest/media/v1/config_resource.py b/synapse/rest/media/v1/config_resource.py index 2272e35b0c..c53ba28540 100644 --- a/synapse/rest/media/v1/config_resource.py +++ b/synapse/rest/media/v1/config_resource.py @@ -13,9 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from twisted.web.server import NOT_DONE_YET + +from twisted.internet import defer from twisted.web.resource import Resource -from synapse.http.server import respond_with_json, respond_with_json_bytes, wrap_json_request_handler +from twisted.web.server import NOT_DONE_YET +from synapse.http.server import respond_with_json, wrap_json_request_handler class MediaConfigResource(Resource): @@ -24,15 +26,19 @@ class MediaConfigResource(Resource): def __init__(self, hs): Resource.__init__(self) config = hs.get_config() + self.clock = hs.get_clock() self.limits_dict = { "m.upload.size": config.max_upload_size, } - @wrap_json_request_handler def render_GET(self, request): - respond_with_json(request, 200, self.limits_dict, send_cors=True) + self._async_render_GET(request) return NOT_DONE_YET + @wrap_json_request_handler + def _async_render_GET(self, request): + return respond_with_json(request, 200, self.limits_dict) + def render_OPTIONS(self, request): - respond_with_json_bytes(request, 200, {}, send_cors=True) - return NOT_DONE_YET + respond_with_json(request, 200, {}, send_cors=True) + return NOT_DONE_YET \ No newline at end of file -- cgit 1.4.1 From bf13c184cdb8e44f9d5644c31d8b17b7c83dc321 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 27 Jul 2018 12:03:34 +0100 Subject: linting --- synapse/rest/media/v1/config_resource.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/synapse/rest/media/v1/config_resource.py b/synapse/rest/media/v1/config_resource.py index c53ba28540..b1018e7067 100644 --- a/synapse/rest/media/v1/config_resource.py +++ b/synapse/rest/media/v1/config_resource.py @@ -14,7 +14,6 @@ # limitations under the License. # -from twisted.internet import defer from twisted.web.resource import Resource from twisted.web.server import NOT_DONE_YET from synapse.http.server import respond_with_json, wrap_json_request_handler @@ -41,4 +40,4 @@ class MediaConfigResource(Resource): def render_OPTIONS(self, request): respond_with_json(request, 200, {}, send_cors=True) - return NOT_DONE_YET \ No newline at end of file + return NOT_DONE_YET -- cgit 1.4.1 From bf30fd834229cebb547c7b09510b8990b638afea Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 27 Jul 2018 12:17:40 +0100 Subject: Auth media/r0/config --- synapse/rest/media/v1/config_resource.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/config_resource.py b/synapse/rest/media/v1/config_resource.py index b1018e7067..44d3d567aa 100644 --- a/synapse/rest/media/v1/config_resource.py +++ b/synapse/rest/media/v1/config_resource.py @@ -14,6 +14,7 @@ # limitations under the License. # +from twisted.internet import defer from twisted.web.resource import Resource from twisted.web.server import NOT_DONE_YET from synapse.http.server import respond_with_json, wrap_json_request_handler @@ -26,6 +27,7 @@ class MediaConfigResource(Resource): Resource.__init__(self) config = hs.get_config() self.clock = hs.get_clock() + self.auth = hs.get_auth() self.limits_dict = { "m.upload.size": config.max_upload_size, } @@ -35,8 +37,10 @@ class MediaConfigResource(Resource): return NOT_DONE_YET @wrap_json_request_handler + @defer.inlineCallbacks def _async_render_GET(self, request): - return respond_with_json(request, 200, self.limits_dict) + yield self.auth.get_user_by_req(request) + respond_with_json(request, 200, self.limits_dict) def render_OPTIONS(self, request): respond_with_json(request, 200, {}, send_cors=True) -- cgit 1.4.1 From 0f6e583e6ff598deab41976d16f7ca9eaa97fbd3 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 27 Jul 2018 12:28:08 +0100 Subject: isorted this mess --- synapse/rest/media/v1/config_resource.py | 1 + synapse/rest/media/v1/media_repository.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/config_resource.py b/synapse/rest/media/v1/config_resource.py index 44d3d567aa..d6605b6027 100644 --- a/synapse/rest/media/v1/config_resource.py +++ b/synapse/rest/media/v1/config_resource.py @@ -17,6 +17,7 @@ from twisted.internet import defer from twisted.web.resource import Resource from twisted.web.server import NOT_DONE_YET + from synapse.http.server import respond_with_json, wrap_json_request_handler diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py index 6a16f9043c..6b08f76e97 100644 --- a/synapse/rest/media/v1/media_repository.py +++ b/synapse/rest/media/v1/media_repository.py @@ -42,6 +42,7 @@ from synapse.util.retryutils import NotRetryingDestination from synapse.util.stringutils import is_ascii, random_string from ._base import FileInfo, respond_404, respond_with_responder +from .config_resource import MediaConfigResource from .download_resource import DownloadResource from .filepath import MediaFilePaths from .identicon_resource import IdenticonResource @@ -51,7 +52,6 @@ from .storage_provider import StorageProviderWrapper from .thumbnail_resource import ThumbnailResource from .thumbnailer import Thumbnailer from .upload_resource import UploadResource -from .config_resource import MediaConfigResource logger = logging.getLogger(__name__) -- cgit 1.4.1