Add thumbnails

This commit is contained in:
augustin64 2022-08-14 21:16:21 +02:00
parent ace8895652
commit 260cef29d4
4 changed files with 43 additions and 12 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@
# data
instance/partitioncloud.sqlite
partitioncloud/partitions
partitioncloud/thumbnails

View File

@ -5,7 +5,7 @@ Main file
import os
from flask import Flask, render_template, request, send_file, g, redirect
from . import auth, albums
from . import auth, albums, partition
app = Flask(__name__)
@ -18,6 +18,7 @@ app.config.from_mapping(
app.register_blueprint(auth.bp)
app.register_blueprint(albums.bp)
app.register_blueprint(partition.bp)
@app.route("/")

View File

@ -0,0 +1,27 @@
#!/usr/bin/python3
"""
Partitions module
"""
import os
from flask import (Blueprint, render_template,
send_file)
bp = Blueprint("partition", __name__, url_prefix="/partition")
@bp.route("/<uuid>/preview")
def preview(uuid):
"""
Renvoie la prévisualisation d'un fichier pdf
"""
if not os.path.exists(f"partitioncloud/thumbnails/{uuid}.jpg"):
os.system(
f'/usr/bin/convert -thumbnail\
"178^>" -background white -alpha \
remove -crop 178x178+0+0 \
partitioncloud/partitions/{uuid}.pdf[0] \
partitioncloud/thumbnails/{uuid}.jpg'
)
return send_file(f"thumbnails/{uuid}.jpg")

View File

@ -6,19 +6,21 @@
{% block content %}
{% if not_participant %}
<a href="/albums/{{ album['uuid'] }}/join">
<button id="join-album">Rejoindre</button>
</a>
<a href="/albums/{{ album['uuid'] }}/join">
<button id="join-album">Rejoindre</button>
</a>
{% endif %}
{% if partitions|length != 0 %}
{% for partition in partitions %}
<a href="{{ album['uuid'] }}/{{ partition['uuid'] }}">
<div class="partition-cover" id="partition-{{ partition['uuid'] }}">
{{ partition["name"] }}
</div>
</a>
{% endfor %}
{% for partition in partitions %}
<a href="{{ album['uuid'] }}/{{ partition['uuid'] }}">
<div class="partition" id="partition-{{ partition['uuid'] }}">
<img src="/partition/{{ partition['uuid'] }}/preview">
<div class="partition-name">{{ partition["name"] }}</div>
<div class="partition-author">{{ partition["author"] }}</div>
</div>
</a>
{% endfor %}
{% else %}
<div>Aucune partition disponible</div>
<div>Aucune partition disponible</div>
{% endif %}
{% endblock %}