Commit c5e7c8c52858486988f7c026c1cd92af7ffd2ee8

Authored by Erickson Silva
1 parent 22654c8e
Exists in devel

[TranslationServer] Modifica rota de download de bundles

Showing 1 changed file with 13 additions and 17 deletions   Show diff stats
src/TranslationServer.py
1 1 #!/usr/bin/python
2 2 # -*- coding: utf-8 -*-
3 3  
4   -from flask import Flask, request, send_file, abort
  4 +from flask import Flask, request, abort, send_from_directory
5 5 from functools import wraps
6 6 from PortGlosa import traduzir
7 7 from subprocess import check_output
... ... @@ -103,7 +103,7 @@ def update_platform_db(platform_name):
103 103 cursor.execute(query_string, (platform_name));
104 104 conn.commit()
105 105  
106   -def update_statistic(sign_name, sign_type, file_exists):
  106 +def update_statistic(sign_name, platform_name, file_exists):
107 107 if RUN_MODE == "full":
108 108 with lock:
109 109 has = "YES" if file_exists else "NO"
... ... @@ -112,16 +112,7 @@ def update_statistic(sign_name, sign_type, file_exists):
112 112 insert_sign_db(sign_name, 1, has)
113 113 else:
114 114 update_sign_db(sign_name, value_sign_name+1, has)
115   - update_platform_db(sign_type)
116   -
117   -def check_sign(sign_name, sign_type):
118   - if " " in sign_name or sign_type not in BUNDLES_PATH: abort(400)
119   - bundle_path = os.path.join(BUNDLES_PATH[sign_type], sign_name)
120   - file_exists = os.path.exists(bundle_path)
121   - thread.start_new_thread(update_statistic, (sign_name, sign_type, file_exists))
122   - if file_exists:
123   - return send_file(bundle_path, as_attachment=True)
124   - abort(404)
  115 + update_platform_db(platform_name)
125 116  
126 117 @app.route("/translate", methods=['GET'])
127 118 def translate():
... ... @@ -135,12 +126,17 @@ def load_statistics_page():
135 126 php_output = check_output(["php", page_path])
136 127 return php_output
137 128  
138   -@app.route("/sign", methods=['GET'])
  129 +@app.route("/<platform>/<sign>", methods=['GET'])
139 130 @check_run_mode
140   -def get_sign():
141   - sign_name = request.args.get('name').encode("UTF-8").upper()
142   - sign_type = request.args.get('platform').encode("UTF-8").upper()
143   - return check_sign(sign_name, sign_type)
  131 +def get_sign(platform, sign):
  132 + if " " in sign or platform not in BUNDLES_PATH: abort(400)
  133 + path = BUNDLES_PATH[platform]
  134 + bundle_path = os.path.join(path, sign)
  135 + file_exists = os.path.exists(os.path.join(path, sign))
  136 + thread.start_new_thread(update_statistic, (sign, platform, file_exists))
  137 + if file_exists:
  138 + return send_from_directory(BUNDLES_PATH[platform], sign)
  139 + abort(404)
144 140  
145 141 if __name__ == "__main__":
146 142 parser = argparse.ArgumentParser(description='Translation server and signs download for VLibras.')
... ...