apache-autoindex-parse
Version:
parse apache's autoindex html files
56 lines (55 loc) • 2.24 kB
text/typescript
import { i as FileEntry, n as DirectoryEntry, t as AutoIndexFormat } from "./index-C5dSXxGW.mjs";
//#region src/traverse.d.ts
interface TraverseOptions {
/**
* Optional format specification of the auto-index page (will be inferred if not provided)
* @default undefined
*/
format?: AutoIndexFormat;
/**
* Optional extra headers to include in the request
* @default {}
*/
extraHeaders?: Record<string, string>;
/**
* Optional signal to abort the fetch request
* @default undefined
*/
abortSignal?: AbortSignal;
/**
* Callback function invoked for each file found during traversal.
* @param {FileEntry} file The file entry object.
* @returns {Promise<void> | void} A promise or void that resolves when the callback is complete.
*/
onFile?: (file: FileEntry) => Promise<void> | void;
/**
* Callback function invoked for each directory found during traversal.
* @param {DirectoryEntryWithChildren} directory The directory entry object.
* @returns {Promise<void> | void} A promise or void that resolves when the callback is complete.
*/
onDirectory?: (directory: DirectoryEntryWithChildren) => Promise<void> | void;
}
type DirectoryEntryWithChildren = DirectoryEntry & {
children: TraverseEntry[];
};
type TraverseEntry = FileEntry | DirectoryEntryWithChildren;
/**
* Recursively traverses an Apache autoindex directory structure.
*
* This function fetches the HTML content from the provided URL, parses it to extract directory entries,
* and then recursively traverses any subdirectories found.
*
* @param {string} rootUrl - The URL of the Apache autoindex directory to traverse
* @param {TraverseOptions?} options - Optional configuration for the traversal process
* @returns {Promise<TraverseEntry[]>} A promise that resolves to a RootEntry object representing the directory structure, or null if parsing failed
*
* @example
* ```typescript
* import { traverse } from 'apache-autoindex-parse/traverse';
*
* const directoryStructure = await traverse('https://example.com/files');
* ```
*/
declare function traverse(rootUrl: string, options?: TraverseOptions): Promise<TraverseEntry[]>;
//#endregion
export { TraverseEntry, TraverseOptions, traverse };