64 lines
2.7 KiB
TypeScript
64 lines
2.7 KiB
TypeScript
/**
|
|
* The WebDAV protocol client. Low-level; no UI or high-level actions.
|
|
*
|
|
* All methods are async and return Promises. Errors are surfaced by rejecting
|
|
* the Promise (or, for non-fatal "not found" cases, returning a falsy value).
|
|
*/
|
|
import type { WebDAVClientOptions, WebDAVListing, WebDAVAuth } from '../types.js';
|
|
/** The PROPFIND body used to list a directory's contents. */
|
|
export declare const PROPFIND_LIST_BODY: string;
|
|
/** The PROPFIND body used to fetch WOPI properties for a single file. */
|
|
export declare const PROPFIND_WOPI_BODY: string;
|
|
export declare class WebDAVError extends Error {
|
|
readonly status: number;
|
|
readonly statusText: string;
|
|
readonly detail?: string;
|
|
constructor(status: number, statusText: string, detail?: string);
|
|
}
|
|
export declare class WebDAVClient {
|
|
/** The base URL of the WebDAV server. */
|
|
readonly baseUrl: string;
|
|
/** Default headers (typically just Authorization). */
|
|
readonly defaultHeaders: Record<string, string>;
|
|
/** The fetch implementation to use. */
|
|
private readonly fetchImpl;
|
|
constructor(options: WebDAVClientOptions);
|
|
/** The current auth (re-derived from default headers). */
|
|
get auth(): WebDAVAuth;
|
|
/** Send a raw WebDAV/HTTP request. */
|
|
send(method: string, url: string, body?: BodyInit | null, headers?: Record<string, string>): Promise<Response>;
|
|
/**
|
|
* Issue a PROPFIND with a custom body. Returns the parsed XML document.
|
|
*/
|
|
propfind(url: string, body: string, depth?: number, extraHeaders?: Record<string, string>): Promise<Document>;
|
|
/**
|
|
* List the contents of a collection. Returns a map of entries keyed by
|
|
* name (with `.` representing the collection itself).
|
|
*/
|
|
list(url: string): Promise<WebDAVListing>;
|
|
/**
|
|
* Fetch WOPI properties (URL, token, ttl) for a single file.
|
|
* Returns `null` if the server doesn't support WOPI.
|
|
*/
|
|
propfindWopi(url: string): Promise<{
|
|
url: string;
|
|
token: string;
|
|
tokenTtl: number;
|
|
} | null>;
|
|
/** Upload a file (PUT). */
|
|
put(url: string, body: BodyInit, contentType?: string): Promise<Response>;
|
|
/** Download a file (GET) and return the response. */
|
|
get(url: string): Promise<Response>;
|
|
/** Delete a file or empty collection. */
|
|
delete(url: string): Promise<Response>;
|
|
/** Create a new collection (MKCOL). */
|
|
mkcol(url: string): Promise<Response>;
|
|
/**
|
|
* Copy or move a file. `method` must be `'COPY'` or `'MOVE'`.
|
|
* `dst` is resolved against the base URL.
|
|
*/
|
|
copymove(method: 'COPY' | 'MOVE', src: string, dst: string, overwrite?: boolean): Promise<Response>;
|
|
/** HEAD request — returns true if the resource exists. */
|
|
exists(url: string): Promise<boolean>;
|
|
}
|