{= # # # get_directory_items.cfv # # include "templates.util.base_util"; include "templates.util.encoding"; include "templates.util.rbac.rbac_util"; include "templates.file_manager.file_manager_util"; # This subroutine gets the directory items and/or file items # of the given pathname. It also caches file items for later use when # not loaded now. # Note, this loads the inital files if no files exists on the client side. # Loading more files is handled in get_file_items.cfv. # debug_message("\n#### get_directory_items.cfv \n"); string session_id = volatile.session_id; bool is_file_manager_permission = get_is_file_manager_permission(); string page_token = v.fp.page_token; if (is_file_manager_permission and get_is_valid_page_token(session_id, "file_manager", page_token)) then ( string item_id = v.fp.item_id; bool load_directories = v.fp.load_directories; bool load_files = v.fp.load_files; bool auto_expand_root_dir_active = v.fp.auto_expand_root_dir_active; # Required in response string pathname_in_utf8 = v.fp.pathname; pathname_in_utf8 = replace_all(pathname_in_utf8, "__HexEsc__5C", "\\"); string pathname_in_local_code_page = convert_utf8_to_local_code_page(pathname_in_utf8); string unc_pathname_in_local_code_page = ""; debug_message("#### load_directories: " . load_directories . "\n"); debug_message("#### load_files: " . load_files . "\n"); # # # Make sure that the client pathname still exists (it could have been renamed or deleted) # # bool is_valid_pathname = file_exists(pathname_in_local_code_page); # # # Get directory items # # string items_dat; if (is_valid_pathname) then ( # # Check if we can load the files from cache # string file_manager_session_id = v.fp.file_manager_session_id; string cached_files_node_name = md5_digest(pathname_in_utf8); string file_manager_sessions_path = "sessions_cache." . session_id . ".fil_man_" . file_manager_session_id; bool load_cached_files = !load_directories and ?(file_manager_sessions_path . "." . cached_files_node_name); node files; string files_dat; int number_files; debug_message("#### load_cached_files: " . load_cached_files . "\n"); if (!load_cached_files) then ( # Get new directories and files node node n = get_directory_contents_by_type( pathname_in_local_code_page, unc_pathname_in_local_code_page ); files = n{"files"}; number_files = num_subnodes(files); if (load_directories) then ( node directories = n{"directories"}; debug_message("#### directories:\n" . node_as_string(directories) . "\n"); int number_directories = num_subnodes(directories); string directories_dat = get_directories_dat(directories, number_directories); ); ) else ( # Load files from cache files = file_manager_sessions_path . "." . cached_files_node_name; number_files = num_subnodes(files); ); # # Handle files # debug_message("#### number_files: " . number_files . "\n"); int number_of_files_to_load = 0; if (load_files and number_files > 0) then ( int max_files_in_initial_load = 300; # Determine actual number of files to be loaded if (number_files / max_files_in_initial_load < 1.5) then ( # Load all files because there aren't too many debug_message("#### Loading files: ALL \n"); number_of_files_to_load = number_files; ) else ( # Load max_files_in_initial_load only debug_message("#### Loading files: first " . max_files_in_initial_load . " only \n"); number_of_files_to_load = max_files_in_initial_load; ); files_dat = get_files_dat(files, 0, number_of_files_to_load - 1); ) else ( files_dat = "[]"; ); # # Cache the files if appropriate # if (!load_cached_files and (number_of_files_to_load < number_files)) then ( # Some or all files are not loaded right now, cache them for later use # Save files node to sessions cache clone_node(files, file_manager_sessions_path . "." . cached_files_node_name); save_node(file_manager_sessions_path . "." . cached_files_node_name); ); ); # # Response # string dat = "{"; dat .= add_json("itemId", item_id, "string"); dat .= add_json("isValidPathname", is_valid_pathname, "bool"); if (is_valid_pathname) then ( dat .= add_json("loadDirectories", load_directories, "bool"); dat .= add_json("loadFiles", load_files, "bool"); dat .= add_json("autoExpandRootDirActive", auto_expand_root_dir_active, "bool"); if (load_directories) then ( dat .= add_json("nDir", number_directories, "int"); dat .= add_json("dirs", directories_dat, "obj"); ); if (load_files) then ( dat .= add_json("numOfFiles", number_files, "int"); dat .= add_json("files", files_dat, "obj"); ); ); dat = close_json(dat); 'fileManager.getDirectoryItemsResponse(' . dat . ')\n'; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); =}