Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions website/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
'www.googletagmanager.com',
'google-analytics.com',
'www.google-analytics.com',
]
],
'img-src': [
'\'self\'',
'data:',
],
}
Talisman(app, content_security_policy=csp)

Expand Down Expand Up @@ -98,11 +102,9 @@ def image(name: str) -> str:
if image is None:
flask.abort(404)

mimetype = 'image/jpeg' if image.extension == 'jpg' else 'image/png'

return flask.Response(
image.content,
mimetype=mimetype,
return flask.render_template(
'image.pug',
image=image
)

@app.route('/images/<string:name>/thumbnail')
Expand Down
11 changes: 11 additions & 0 deletions website/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import base64
import datetime
import io
from dataclasses import dataclass
Expand All @@ -31,6 +32,16 @@ class Image:
created: datetime.datetime
content: bytes

@property
def data_uri(self) -> str:
"""
Returns the data URI of the image.

Returns:
str: The data URI of the image.
"""
return f"data:image/png;base64,{base64.b64encode(self.content).decode('utf-8')}"

@property
def extension(self) -> str:
return self.title.split('.')[-1]
Expand Down
8 changes: 8 additions & 0 deletions website/templates/image.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends document.pug

block title
title {{ image.title }} - Johnathan Irvin

block body
.container-fluid.text-center
img.img-fluid(src="{{ image.data_uri }}")
12 changes: 7 additions & 5 deletions website/templates/images.pug
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ block title
block content
.d-flex.justify-content-center.flex-wrap
// {% for image in images %}
img.flex(
src='/images/{{ image.title }}/thumbnail',
width='200px',
height='200px'
)
a(href="{{ url_for('image', name=image.title) }}", target="_blank")
img.img-fluid.img-thumbnail.m-1(
src='/images/{{ image.title }}/thumbnail',
alt='{{ image.title }}',
width='200px',
height='200px'
)
// {% endfor %}