Can now download both tar and zip archive
This commit is contained in:
parent
bcf7ea2042
commit
74ec28e2be
15
app.py
15
app.py
|
|
@ -269,8 +269,7 @@ def validate_calibration():
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/download-object/<id>')
|
def download_object(id: int, tar: archive.ArchiveSender):
|
||||||
def download_object(id: int):
|
|
||||||
conn = db.get()
|
conn = db.get()
|
||||||
object = db.Object.get_from_id(id, conn).full(conn)
|
object = db.Object.get_from_id(id, conn).full(conn)
|
||||||
|
|
||||||
|
|
@ -285,8 +284,6 @@ def download_object(id: int):
|
||||||
]
|
]
|
||||||
|
|
||||||
# Create archive file to send
|
# Create archive file to send
|
||||||
tar = archive.TarSender()
|
|
||||||
|
|
||||||
for calibration_index, (calib, acquisitions) in enumerate(acquisitions_grouped):
|
for calibration_index, (calib, acquisitions) in enumerate(acquisitions_grouped):
|
||||||
calibration_dir = join(config.CALIBRATION_DIR, str(calib.id))
|
calibration_dir = join(config.CALIBRATION_DIR, str(calib.id))
|
||||||
|
|
||||||
|
|
@ -310,6 +307,16 @@ def download_object(id: int):
|
||||||
return tar.response()
|
return tar.response()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/download-object/tar/<id>')
|
||||||
|
def download_object_tar(id: int):
|
||||||
|
return download_object(id, archive.TarSender())
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/download-object/zip/<id>')
|
||||||
|
def download_object_zip(id: int):
|
||||||
|
return download_object(id, archive.ZipSender())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/static/<path:path>')
|
@app.route('/static/<path:path>')
|
||||||
def send_static(path):
|
def send_static(path):
|
||||||
return send_from_directory('static', path)
|
return send_from_directory('static', path)
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ def zip_local_file_header(filename: str, filepath: str, crc: int) -> bytes:
|
||||||
# Field 11: filename (buffer[30:30+len(filename)])
|
# Field 11: filename (buffer[30:30+len(filename)])
|
||||||
buffer[30:30+len(filename)] = filename.encode('ascii')
|
buffer[30:30+len(filename)] = filename.encode('ascii')
|
||||||
|
|
||||||
return buffer
|
return bytes(buffer)
|
||||||
|
|
||||||
|
|
||||||
def zip_central_directory_file_header(filename: str, filepath: str, crc: int, offset: int) -> bytes:
|
def zip_central_directory_file_header(filename: str, filepath: str, crc: int, offset: int) -> bytes:
|
||||||
|
|
@ -208,7 +208,7 @@ def zip_central_directory_file_header(filename: str, filepath: str, crc: int, of
|
||||||
# Field 16: filename (buffer[46:46+len(filename)])
|
# Field 16: filename (buffer[46:46+len(filename)])
|
||||||
buffer[46:46+len(filename)] = filename.encode('ascii')
|
buffer[46:46+len(filename)] = filename.encode('ascii')
|
||||||
|
|
||||||
return buffer
|
return bytes(buffer)
|
||||||
|
|
||||||
|
|
||||||
def zip_end_of_central_directory(items_number: int, central_directory_size: int, central_directory_offset: int):
|
def zip_end_of_central_directory(items_number: int, central_directory_size: int, central_directory_offset: int):
|
||||||
|
|
@ -230,12 +230,12 @@ def zip_end_of_central_directory(items_number: int, central_directory_size: int,
|
||||||
buffer[12:16] = central_directory_size.to_bytes(4, byteorder='little')
|
buffer[12:16] = central_directory_size.to_bytes(4, byteorder='little')
|
||||||
|
|
||||||
# Field 7: Offset of start of central directory (buffer[16:20])
|
# Field 7: Offset of start of central directory (buffer[16:20])
|
||||||
buffer[16:20] = central_directory_size.to_bytes(4, byteorder='little')
|
buffer[16:20] = central_directory_offset.to_bytes(4, byteorder='little')
|
||||||
|
|
||||||
# Field 8: Comment length (buffer[20:22])
|
# Field 8: Comment length (buffer[20:22])
|
||||||
|
|
||||||
# Field 9: Comment (buffer[22:])
|
# Field 9: Comment (buffer[22:])
|
||||||
return buffer
|
return bytes(buffer)
|
||||||
|
|
||||||
|
|
||||||
class ZipSender(ArchiveSender):
|
class ZipSender(ArchiveSender):
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="container content">
|
<div class="container content">
|
||||||
<h1 class="title">{{ object.name }}</h1>
|
<h1 class="title">{{ object.name }}</h1>
|
||||||
<a href="/download-object/{{ object.id }}">Télécharger les données de l'objet</a>
|
<div class="my-3">
|
||||||
|
<a class="button is-link mr-3" href="/download-object/tar/{{ object.id }}">Télécharger les données de l'objet (archive TAR)</a>
|
||||||
|
<a class="button is-link" href="/download-object/zip/{{ object.id }}">Télécharger les données de l'objet (archive ZIP)</a>
|
||||||
|
</div>
|
||||||
{% if object.acquisitions %}
|
{% if object.acquisitions %}
|
||||||
<div class="fixed-grid has-6-cols">
|
<div class="fixed-grid has-6-cols">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue