summaryrefslogtreecommitdiff
path: root/web.py
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-06-04 00:43:35 +0800
committerKeuin <[email protected]>2023-06-04 00:43:35 +0800
commit756d8549ae59f3bdd29b18111737c7d775bae304 (patch)
tree7f304940081404b0ee476fd335d482bb49fdb867 /web.py
parent5ca5f36c92da8afbc264bb1e62d2d5cb27866b5f (diff)
Set default behavior to not suggest file name, making PDF preview-able on browsers
Diffstat (limited to 'web.py')
-rw-r--r--web.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/web.py b/web.py
index c602dd4..44ea7e8 100644
--- a/web.py
+++ b/web.py
@@ -17,13 +17,18 @@ utaten_pattern = re.compile(r'[a-z0-9]+')
tex_generator = texgen.TexGenerator('pdf_cache', 'temp', 20)
html_cache = htmlcache.HtmlCache('html_cache')
+suggest_file_name = False
+
@app.get("/utaten/{item_id}.pdf")
async def get_utaten_lyric_pdf(item_id: str):
+ global suggest_file_name
try:
lyric_info = await html_cache.get_utaten_tex_source(item_id)
pdf_path = await tex_generator.xelatex(lyric_info.tex_source)
- if lyric_info.title and lyric_info.artist:
+ if not suggest_file_name:
+ filename = None
+ elif lyric_info.title and lyric_info.artist:
filename = f'{lyric_info.title} - {lyric_info.artist}.pdf'
elif not lyric_info.title and not lyric_info.artist:
filename = f'{lyric_info.utaten_id}.pdf'
@@ -63,7 +68,9 @@ if __name__ == '__main__':
p = argparse.ArgumentParser(prog='utaten2tex')
p.add_argument('-l', '--host', default='127.0.0.1')
p.add_argument('-p', '--port', default='8080')
+ p.add_argument('-s', '--suggest-file-name', action='store_true', default=False)
args = p.parse_args()
+ suggest_file_name = args.suggest_file_name
setup_loop()
uvicorn.run(
'web:app',