Added /matrix/content path, HS resource_for_content_repo attribute and FileUploadResource. Added stub methods.
This commit is contained in:
parent
301e55d11d
commit
a18b1a649c
|
@ -17,4 +17,5 @@
|
||||||
|
|
||||||
CLIENT_PREFIX = "/matrix/client/api/v1"
|
CLIENT_PREFIX = "/matrix/client/api/v1"
|
||||||
FEDERATION_PREFIX = "/matrix/federation/v1"
|
FEDERATION_PREFIX = "/matrix/federation/v1"
|
||||||
WEB_CLIENT_PREFIX = "/matrix/client"
|
WEB_CLIENT_PREFIX = "/matrix/client"
|
||||||
|
CONTENT_REPO_PREFIX = "/matrix/content"
|
|
@ -24,9 +24,11 @@ from twisted.python.log import PythonLoggingObserver
|
||||||
from twisted.web.resource import Resource
|
from twisted.web.resource import Resource
|
||||||
from twisted.web.static import File
|
from twisted.web.static import File
|
||||||
from twisted.web.server import Site
|
from twisted.web.server import Site
|
||||||
from synapse.http.server import JsonResource, RootRedirect
|
from synapse.http.server import JsonResource, RootRedirect, FileUploadResource
|
||||||
from synapse.http.client import TwistedHttpClient
|
from synapse.http.client import TwistedHttpClient
|
||||||
from synapse.api.urls import CLIENT_PREFIX, FEDERATION_PREFIX, WEB_CLIENT_PREFIX
|
from synapse.api.urls import (
|
||||||
|
CLIENT_PREFIX, FEDERATION_PREFIX, WEB_CLIENT_PREFIX, CONTENT_REPO_PREFIX
|
||||||
|
)
|
||||||
|
|
||||||
from daemonize import Daemonize
|
from daemonize import Daemonize
|
||||||
|
|
||||||
|
@ -53,6 +55,9 @@ class SynapseHomeServer(HomeServer):
|
||||||
def build_resource_for_web_client(self):
|
def build_resource_for_web_client(self):
|
||||||
return File("webclient") # TODO configurable?
|
return File("webclient") # TODO configurable?
|
||||||
|
|
||||||
|
def build_resource_for_content_repo(self):
|
||||||
|
return FileUploadResource("uploads")
|
||||||
|
|
||||||
def build_db_pool(self):
|
def build_db_pool(self):
|
||||||
""" Set up all the dbs. Since all the *.sql have IF NOT EXISTS, so we
|
""" Set up all the dbs. Since all the *.sql have IF NOT EXISTS, so we
|
||||||
don't have to worry about overwriting existing content.
|
don't have to worry about overwriting existing content.
|
||||||
|
@ -101,7 +106,8 @@ class SynapseHomeServer(HomeServer):
|
||||||
# [ ("/aaa/bbb/cc", Resource1), ("/aaa/dummy", Resource2) ]
|
# [ ("/aaa/bbb/cc", Resource1), ("/aaa/dummy", Resource2) ]
|
||||||
desired_tree = [
|
desired_tree = [
|
||||||
(CLIENT_PREFIX, self.get_resource_for_client()),
|
(CLIENT_PREFIX, self.get_resource_for_client()),
|
||||||
(FEDERATION_PREFIX, self.get_resource_for_federation())
|
(FEDERATION_PREFIX, self.get_resource_for_federation()),
|
||||||
|
(CONTENT_REPO_PREFIX, self.get_resource_for_content_repo())
|
||||||
]
|
]
|
||||||
if web_client:
|
if web_client:
|
||||||
logger.info("Adding the web client.")
|
logger.info("Adding the web client.")
|
||||||
|
|
|
@ -25,6 +25,7 @@ from twisted.web.server import NOT_DONE_YET
|
||||||
from twisted.web.util import redirectTo
|
from twisted.web.util import redirectTo
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,6 +177,33 @@ class RootRedirect(resource.Resource):
|
||||||
return resource.Resource.getChild(self, name, request)
|
return resource.Resource.getChild(self, name, request)
|
||||||
|
|
||||||
|
|
||||||
|
class FileUploadResource(resource.Resource):
|
||||||
|
isLeaf = True
|
||||||
|
|
||||||
|
def __init__(self, directory):
|
||||||
|
resource.Resource.__init__(self)
|
||||||
|
self.directory = directory
|
||||||
|
|
||||||
|
def render(self, request):
|
||||||
|
self._async_render(request)
|
||||||
|
return server.NOT_DONE_YET
|
||||||
|
|
||||||
|
# @defer.inlineCallbacks
|
||||||
|
def _async_render(self, request):
|
||||||
|
request.setResponseCode(200)
|
||||||
|
request.setHeader(b"Content-Type", b"application/json")
|
||||||
|
|
||||||
|
request.setHeader("Access-Control-Allow-Origin", "*")
|
||||||
|
request.setHeader("Access-Control-Allow-Methods",
|
||||||
|
"GET, POST, PUT, DELETE, OPTIONS")
|
||||||
|
request.setHeader("Access-Control-Allow-Headers",
|
||||||
|
"Origin, X-Requested-With, Content-Type, Accept")
|
||||||
|
|
||||||
|
request.write(json.dumps({"url": "not_implemented"}))
|
||||||
|
request.finish()
|
||||||
|
defer.succeed("not implemented")
|
||||||
|
|
||||||
|
|
||||||
def respond_with_json_bytes(request, code, json_bytes, send_cors=False):
|
def respond_with_json_bytes(request, code, json_bytes, send_cors=False):
|
||||||
"""Sends encoded JSON in response to the given request.
|
"""Sends encoded JSON in response to the given request.
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ class BaseHomeServer(object):
|
||||||
'resource_for_client',
|
'resource_for_client',
|
||||||
'resource_for_federation',
|
'resource_for_federation',
|
||||||
'resource_for_web_client',
|
'resource_for_web_client',
|
||||||
|
'resource_for_content_repo',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, hostname, **kwargs):
|
def __init__(self, hostname, **kwargs):
|
||||||
|
@ -140,6 +141,7 @@ class HomeServer(BaseHomeServer):
|
||||||
resource_for_client
|
resource_for_client
|
||||||
resource_for_web_client
|
resource_for_web_client
|
||||||
resource_for_federation
|
resource_for_federation
|
||||||
|
resource_for_content_repo
|
||||||
http_client
|
http_client
|
||||||
db_pool
|
db_pool
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue