Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
582019f8
Commit
582019f8
authored
10 years ago
by
Matthew Hodgson
Browse files
Options
Downloads
Patches
Plain Diff
...and here's the actual impl. git fail.
parent
f02bf64d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/handlers/register.py
+14
-0
14 additions, 0 deletions
synapse/handlers/register.py
synapse/rest/media/v1/upload_resource.py
+32
-25
32 additions, 25 deletions
synapse/rest/media/v1/upload_resource.py
with
46 additions
and
25 deletions
synapse/handlers/register.py
+
14
−
0
View file @
582019f8
...
@@ -99,6 +99,20 @@ class RegistrationHandler(BaseHandler):
...
@@ -99,6 +99,20 @@ class RegistrationHandler(BaseHandler):
raise
RegistrationError
(
raise
RegistrationError
(
500
,
"
Cannot generate user ID.
"
)
500
,
"
Cannot generate user ID.
"
)
# create a default avatar for the user
# XXX: ideally clients would explicitly specify one, but given they don't
# and we want consistent and pretty identicons for random users, we'll
# do it here.
auth_user
=
UserID
.
from_string
(
user_id
)
identicon_resource
=
self
.
hs
.
get_resource_for_media_repository
().
getChildWithDefault
(
"
identicon
"
,
None
)
upload_resource
=
self
.
hs
.
get_resource_for_media_repository
().
getChildWithDefault
(
"
upload
"
,
None
)
identicon_bytes
=
identicon_resource
.
generate_identicon
(
user_id
,
320
,
320
)
content_uri
=
yield
upload_resource
.
create_content
(
"
image/png
"
,
None
,
identicon_bytes
,
len
(
identicon_bytes
),
auth_user
)
profile_handler
=
self
.
hs
.
get_handlers
().
profile_handler
profile_handler
.
set_avatar_url
(
auth_user
,
auth_user
,
(
"
%s#auto
"
%
content_uri
))
defer
.
returnValue
((
user_id
,
token
))
defer
.
returnValue
((
user_id
,
token
))
@defer.inlineCallbacks
@defer.inlineCallbacks
...
...
This diff is collapsed.
Click to expand it.
synapse/rest/media/v1/upload_resource.py
+
32
−
25
View file @
582019f8
...
@@ -38,6 +38,35 @@ class UploadResource(BaseMediaResource):
...
@@ -38,6 +38,35 @@ class UploadResource(BaseMediaResource):
def
render_OPTIONS
(
self
,
request
):
def
render_OPTIONS
(
self
,
request
):
respond_with_json
(
request
,
200
,
{},
send_cors
=
True
)
respond_with_json
(
request
,
200
,
{},
send_cors
=
True
)
return
NOT_DONE_YET
return
NOT_DONE_YET
@defer.inlineCallbacks
def
create_content
(
self
,
media_type
,
upload_name
,
content
,
content_length
,
auth_user
):
media_id
=
random_string
(
24
)
fname
=
self
.
filepaths
.
local_media_filepath
(
media_id
)
self
.
_makedirs
(
fname
)
# This shouldn't block for very long because the content will have
# already been uploaded at this point.
with
open
(
fname
,
"
wb
"
)
as
f
:
f
.
write
(
content
)
yield
self
.
store
.
store_local_media
(
media_id
=
media_id
,
media_type
=
media_type
,
time_now_ms
=
self
.
clock
.
time_msec
(),
upload_name
=
upload_name
,
media_length
=
content_length
,
user_id
=
auth_user
,
)
media_info
=
{
"
media_type
"
:
media_type
,
"
media_length
"
:
content_length
,
}
yield
self
.
_generate_local_thumbnails
(
media_id
,
media_info
)
defer
.
returnValue
(
"
mxc://%s/%s
"
%
(
self
.
server_name
,
media_id
))
@defer.inlineCallbacks
@defer.inlineCallbacks
def
_async_render_POST
(
self
,
request
):
def
_async_render_POST
(
self
,
request
):
...
@@ -70,32 +99,10 @@ class UploadResource(BaseMediaResource):
...
@@ -70,32 +99,10 @@ class UploadResource(BaseMediaResource):
# disposition = headers.getRawHeaders("Content-Disposition")[0]
# disposition = headers.getRawHeaders("Content-Disposition")[0]
# TODO(markjh): parse content-dispostion
# TODO(markjh): parse content-dispostion
media_id
=
random_string
(
24
)
content_uri
=
yield
self
.
create_content
(
media_type
,
None
,
request
.
content
.
read
(),
fname
=
self
.
filepaths
.
local_media_filepath
(
media_id
)
content_length
,
auth_user
self
.
_makedirs
(
fname
)
# This shouldn't block for very long because the content will have
# already been uploaded at this point.
with
open
(
fname
,
"
wb
"
)
as
f
:
f
.
write
(
request
.
content
.
read
())
yield
self
.
store
.
store_local_media
(
media_id
=
media_id
,
media_type
=
media_type
,
time_now_ms
=
self
.
clock
.
time_msec
(),
upload_name
=
None
,
media_length
=
content_length
,
user_id
=
auth_user
,
)
)
media_info
=
{
"
media_type
"
:
media_type
,
"
media_length
"
:
content_length
,
}
yield
self
.
_generate_local_thumbnails
(
media_id
,
media_info
)
content_uri
=
"
mxc://%s/%s
"
%
(
self
.
server_name
,
media_id
)
respond_with_json
(
respond_with_json
(
request
,
200
,
{
"
content_uri
"
:
content_uri
},
send_cors
=
True
request
,
200
,
{
"
content_uri
"
:
content_uri
},
send_cors
=
True
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment