mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-25 17:31:00 +00:00
create download_file route
This commit is contained in:
parent
0b14600199
commit
f0d6c92db7
1 changed files with 11 additions and 3 deletions
14
app/app.py
14
app/app.py
|
@ -6,7 +6,7 @@ from functools import wraps
|
||||||
import argostranslatefiles
|
import argostranslatefiles
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
from argostranslatefiles import get_supported_formats
|
from argostranslatefiles import get_supported_formats
|
||||||
from flask import Flask, abort, jsonify, render_template, request
|
from flask import Flask, abort, jsonify, render_template, request, url_for
|
||||||
from flask_swagger import swagger
|
from flask_swagger import swagger
|
||||||
from flask_swagger_ui import get_swaggerui_blueprint
|
from flask_swagger_ui import get_swaggerui_blueprint
|
||||||
from translatehtml import translate_html
|
from translatehtml import translate_html
|
||||||
|
@ -590,15 +590,23 @@ def create_app(args):
|
||||||
file.save(filepath)
|
file.save(filepath)
|
||||||
|
|
||||||
translated_file_path = argostranslatefiles.translate_file(src_langs[0].get_translation(tgt_lang), filepath)
|
translated_file_path = argostranslatefiles.translate_file(src_langs[0].get_translation(tgt_lang), filepath)
|
||||||
|
translated_filename = os.path.basename(translated_file_path)
|
||||||
return jsonify(
|
return jsonify(
|
||||||
{
|
{
|
||||||
"translatedFileUrl": translated_file_path
|
"translatedFileUrl": url_for('download_file', filename=translated_filename)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
abort(500, description=e)
|
abort(500, description=e)
|
||||||
|
|
||||||
|
@app.route("/download_file/<string:filename>", methods=["GET"])
|
||||||
|
@access_check
|
||||||
|
def download_file(filename):
|
||||||
|
"""
|
||||||
|
Download a translated file
|
||||||
|
"""
|
||||||
|
print('')
|
||||||
|
|
||||||
@app.route("/detect", methods=["POST"])
|
@app.route("/detect", methods=["POST"])
|
||||||
@access_check
|
@access_check
|
||||||
def detect():
|
def detect():
|
||||||
|
|
Loading…
Reference in a new issue