This function gets name of file from request data reads the data and sends back in response
()
| 358 | endpoint='load_file') |
| 359 | @pga_login_required |
| 360 | def load_file(): |
| 361 | """ |
| 362 | This function gets name of file from request data |
| 363 | reads the data and sends back in response |
| 364 | """ |
| 365 | if req.data: |
| 366 | file_data = json.loads(req.data) |
| 367 | |
| 368 | file_path = unquote(file_data['file_name']) |
| 369 | |
| 370 | # get the current storage from request if available |
| 371 | # or get it from last_storage preference. |
| 372 | if 'storage' in file_data: |
| 373 | storage_folder = file_data['storage'] |
| 374 | else: |
| 375 | storage_folder = Preferences.module('file_manager').preference( |
| 376 | 'last_storage').get() |
| 377 | |
| 378 | # retrieve storage directory path |
| 379 | storage_manager_path = get_storage_directory( |
| 380 | shared_storage=storage_folder) |
| 381 | |
| 382 | try: |
| 383 | Filemanager.check_access_permission(storage_manager_path, file_path) |
| 384 | except Exception as e: |
| 385 | return internal_server_error(errormsg=str(e)) |
| 386 | |
| 387 | if storage_manager_path: |
| 388 | # generate full path of file |
| 389 | file_path = os.path.join( |
| 390 | storage_manager_path, |
| 391 | file_path.lstrip('/').lstrip('\\') |
| 392 | ) |
| 393 | |
| 394 | (status, err_msg, is_binary, |
| 395 | is_startswith_bom, enc) = Filemanager.check_file_for_bom_and_binary( |
| 396 | file_path |
| 397 | ) |
| 398 | |
| 399 | if not status: |
| 400 | return internal_server_error( |
| 401 | errormsg=gettext(err_msg) |
| 402 | ) |
| 403 | |
| 404 | if is_binary: |
| 405 | return internal_server_error( |
| 406 | errormsg=gettext("File type not supported") |
| 407 | ) |
| 408 | |
| 409 | return Response(read_file_generator(file_path, enc), mimetype='text/plain') |
| 410 | |
| 411 | |
| 412 | @blueprint.route('/save_file/', methods=["PUT", "POST"], |
nothing calls this directly
no test coverage detected