Skip to content
Draft
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
4 changes: 3 additions & 1 deletion shabda/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
after_this_request,
)
from werkzeug.exceptions import BadRequest, HTTPException
from werkzeug.utils import secure_filename
from shabda.dj import Dj


Expand Down Expand Up @@ -146,11 +147,12 @@ def remove_file(response):
def speech_zip(definition):
"""Download a zip archive"""
definition = definition.replace(" ", "_")
definition_secure = secure_filename(definition)
try:
words = dj.parse_definition(definition)
except ValueError as ex:
raise BadRequest(ex) from ex
tmpfile = tempfile.gettempdir() + "/" + definition + ".zip"
tmpfile = os.path.join(tempfile.gettempdir(), definition_secure + ".zip")
with ZipFile(tmpfile, "w") as zipfile:
for word, number in words.items():
samples = dj.list(word, number, soundtype="tts")
Expand Down