def api_available_module_public(module_name, rest): # security check module_name, rest = map(secure_filename, (module_name, rest)) if not allowed_file(rest): abort(403) if not catalog.is_available(module_name): abort(404) # get zip file from catalog with zipfile.ZipFile(catalog.get_zipfile(module_name)) as zf: try: module_conf_filename = os.path.join(module_name, path.CONFIG_FILE) with zf.open(module_conf_filename) as module_conf_zf: module_conf = json.load(module_conf_zf) public_dir = catalog.get_from_config(module_conf, 'public_directory') requested_file = os.path.join(module_name, public_dir, rest) with zf.open(requested_file) as requested_zf: try: res = None _, fname = tempfile.mkstemp() with open(fname, 'w') as fp: fp.write(requested_zf.read()) res = send_file(fname) finally: os.remove(fname) if res: return res else: abort(404) except (KeyError, IOError): abort(404)
def api_available_module_download(module_name): module_zipfile = catalog.get_zipfile(module_name).split(os.path.sep)[-1] return send_from_directory(app.static_folder, module_zipfile, as_attachment=True)