Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
ae8c3339
Verified
Commit
ae8c3339
authored
Mar 09, 2018
by
Sébastiaan Versteeg
Browse files
Add separate private thumbnails view for API
parent
27f3126c
Changes
4
Hide whitespace changes
Inline
Side-by-side
website/thaliawebsite/api/services.py
View file @
ae8c3339
...
...
@@ -10,11 +10,11 @@ def create_image_thumbnail_dict(request, file, placeholder='',
'full'
:
request
.
build_absolute_uri
(
'{}{}'
.
format
(
settings
.
MEDIA_URL
,
file
)),
'small'
:
request
.
build_absolute_uri
(
thumbnail
(
file
,
size_small
,
1
)),
file
,
size_small
,
1
,
True
)),
'medium'
:
request
.
build_absolute_uri
(
thumbnail
(
file
,
size_medium
,
1
)),
file
,
size_medium
,
1
,
True
)),
'large'
:
request
.
build_absolute_uri
(
thumbnail
(
file
,
size_large
,
1
))
file
,
size_large
,
1
,
True
))
}
return
{
'full'
:
placeholder
,
...
...
website/thaliawebsite/urls.py
View file @
ae8c3339
...
...
@@ -48,7 +48,8 @@ from members.views import ObtainAuthToken, ObtainThaliaAuthToken
from
partners.sitemaps
import
sitemap
as
partners_sitemap
from
thabloid.sitemaps
import
sitemap
as
thabloid_sitemap
from
thaliawebsite.forms
import
AuthenticationForm
from
utils.views
import
private_thumbnails
,
generate_thumbnail
from
utils.views
import
private_thumbnails
,
generate_thumbnail
,
\
private_thumbnails_api
from
.
import
views
from
.sitemaps
import
StaticViewSitemap
...
...
@@ -107,6 +108,8 @@ urlpatterns = [
url
(
r
'^'
,
include
(
'pizzas.api.urls'
)),
url
(
r
'^'
,
include
(
'photos.api.urls'
)),
url
(
r
'^'
,
include
(
'pushnotifications.api.urls'
)),
url
(
r
'^generate-thumbnail/(?P<size_fit>\d+x\d+_[01])/(?P<path>[^/]+)/(?P<thumbpath>[^/]+)'
,
generate_thumbnail
,
{
'api'
:
True
},
name
=
'generate-thumbnail-api'
),
url
(
r
'^private-thumbnails/(?P<size_fit>\d+x\d+_[01])/(?P<path>.*)'
,
private_thumbnails_api
,
name
=
'private-thumbnails-api'
),
])),
])),
url
(
r
'^education/'
,
include
(
'education.urls'
)),
...
...
website/utils/templatetags/thumbnail.py
View file @
ae8c3339
...
...
@@ -11,7 +11,7 @@ register = template.Library() # pylint: disable=invalid-name
@
register
.
simple_tag
def
thumbnail
(
path
,
size
,
fit
=
True
):
def
thumbnail
(
path
,
size
,
fit
=
True
,
api
=
False
):
"""
Get the thumbnail path for the specified image path.
...
...
@@ -43,6 +43,9 @@ def thumbnail(path, size, fit=True):
# We provide a URL instead of calling it as a function, so that using
# it means kicking off a new GET request. If we would generate all
# thumbnails inline, loading an album overview would have high latency.
if
api
:
return
reverse
(
'generate-thumbnail-api'
,
args
=
[
size_fit
,
pathuri
,
thumburi
])
return
reverse
(
'generate-thumbnail'
,
args
=
[
size_fit
,
pathuri
,
thumburi
])
...
...
@@ -56,4 +59,6 @@ def thumbnail(path, size, fit=True):
# We provide a URL instead of calling it as a function, so that using
# it means kicking off a new GET request. If we would generate all
# thumbnails inline, loading an album overview would have high latency.
if
api
:
return
reverse
(
'private-thumbnails-api'
,
args
=
[
size_fit
,
path
])
return
reverse
(
'private-thumbnails'
,
args
=
[
size_fit
,
path
])
website/utils/views.py
View file @
ae8c3339
...
...
@@ -9,6 +9,8 @@ from django.http import Http404
from
django.shortcuts
import
redirect
from
django.urls
import
reverse
from
django.utils.http
import
urlunquote
from
rest_framework
import
permissions
from
rest_framework.decorators
import
api_view
,
permission_classes
from
sendfile
import
sendfile
...
...
@@ -43,7 +45,15 @@ def private_thumbnails(request, size_fit, path):
return
_private_thumbnails_unauthed
(
request
,
size_fit
,
path
)
def
generate_thumbnail
(
_request
,
size_fit
,
path
,
thumbpath
):
@
api_view
([
'GET'
])
@
permission_classes
([
permissions
.
IsAuthenticated
])
def
private_thumbnails_api
(
request
,
size_fit
,
path
):
"""Get thumbnails that we need to be logged in to see
using token authentication."""
return
_private_thumbnails_unauthed
(
request
,
size_fit
,
path
)
def
generate_thumbnail
(
_request
,
size_fit
,
path
,
thumbpath
,
api
=
False
):
"""
Generate thumbnail and redirect user to new location
...
...
@@ -98,6 +108,10 @@ def generate_thumbnail(_request, size_fit, path, thumbpath):
return
redirect
(
settings
.
MEDIA_URL
+
thumbpath
,
permanent
=
True
)
# Otherwise redirect to the route with an auth check
if
api
:
return
redirect
(
reverse
(
'private-thumbnails-api'
,
args
=
[
size_fit
,
path
]),
permanent
=
True
)
return
redirect
(
reverse
(
'private-thumbnails'
,
args
=
[
size_fit
,
path
]),
permanent
=
True
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment