Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-web
Commits
a0d8372d
Commit
a0d8372d
authored
1 month ago
by
Renaud Boyer
Browse files
Options
Downloads
Patches
Plain Diff
api/content: Query parameters serializer
parent
e064a298
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1383
api: Query parameters serializers
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/web/api/views/content.py
+14
-4
14 additions, 4 deletions
swh/web/api/views/content.py
with
14 additions
and
4 deletions
swh/web/api/views/content.py
+
14
−
4
View file @
a0d8372d
...
...
@@ -9,6 +9,7 @@ import os
from
typing
import
Optional
from
django.http
import
FileResponse
from
rest_framework
import
serializers
from
rest_framework.request
import
Request
from
swh.web.api
import
utils
...
...
@@ -19,6 +20,14 @@ from swh.web.utils import archive
from
swh.web.utils.exc
import
NotFoundExc
class
ContentRawQuerySerializer
(
serializers
.
Serializer
):
"""
Content Raw query parameters serializer.
"""
filename
=
serializers
.
CharField
(
required
=
False
,
min_length
=
1
,
max_length
=
255
,
default
=
""
)
@api_route
(
r
"
/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/filetype/
"
,
"
api-1-content-filetype
"
,
...
...
@@ -172,9 +181,10 @@ def api_content_license(request: Request, q: str):
r
"
/content/(?P<q>[0-9a-z_:]*[0-9a-f]+)/raw/
"
,
"
api-1-content-raw
"
,
checksum_args
=
[
"
q
"
],
query_params_serializer
=
ContentRawQuerySerializer
,
)
@api_doc
(
"
/content/raw/
"
,
category
=
"
Archive
"
)
def
api_content_raw
(
request
:
Request
,
q
:
str
):
def
api_content_raw
(
request
:
Request
,
q
:
str
,
validated_query_params
:
dict
[
str
,
str
]
):
"""
.. http:get:: /api/1/content/[(hash_type):](hash)/raw/
...
...
@@ -205,9 +215,9 @@ def api_content_raw(request: Request, q: str):
if
not
content
:
raise
NotFoundExc
(
"
Content %s is not found.
"
%
q
)
filename
=
request
.
query_params
.
get
(
"
filename
"
)
if
not
filename
:
filename
=
"
content_%s_raw
"
%
q
.
replace
(
"
:
"
,
"
_
"
)
filename
=
validated_
query_params
[
"
filename
"
]
or
"
content_%s_raw
"
%
q
.
replace
(
"
:
"
,
"
_
"
)
return
FileResponse
(
io
.
BytesIO
(
content
[
"
data
"
]),
# not copied, as this is never modified
...
...
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