def get_file(json_map_path): """ This method is for getting the list of chunk :param json_map_path: :return: """ print("[+] Start getting the file...") # We read the json map with open(json_map_path, "r") as file_: the_map = json.loads(file_.read()) # We check if the file exists if path.exists(the_map["file"]["file_path"]): return "static/files/" + the_map["file"]["file_name"] else: # We instantiate the Split class by passing the chunk directory sp = Split(chunks_directory="./chunks/", json_map_directory="./json_maps/", data_directory="./app/server/static/files/") # We download all the chunks sp = download_all_chunk(sp, the_map) # We rebuild the file saving_path = sp.data_directory + sp.get_map()["file"]["file_name"] sp.rebuild(saving_path) # We check the md5 of the file md5_checker(sp, saving_path) print("[+] Your file {} have been successfully rebuilded !".format( saving_path)) return saving_path
def send_file(chat_id, file_name): """ :param chat_id: :param file_name: :return: """ # We split the file using tth Split module # We instantiate the Split class by passing the chunk directory sp = Split(chunks_directory="./chunks/", json_map_directory="./json_maps/", data_directory="./app/server/static/files/") # We decompose the file in multiple chunks sp.decompose(file_name) # We get the md5-sum of the file md5_sum = get_md5_sum(file_name) # We build our final map final_map = { "file": { "file_path": file_name, "file_name": file_name.split("/")[-1] }, "md5_sum": md5_sum, "cloud_map": [], # The cloud json-map of all chunks "file_map": sp.get_map() # The local json-map of all chunks } (success, failed, final_map) = send_all_chunks(chat_id, sp.chunks_directory, final_map, sp.get_map()) # We set the map sp.set_map(final_map) # We write the json-map and return the path return sp.write_json_map(md5_sum)