Skip to content

Commit

Permalink
Add third-party webdav (perry-mitchell/webdav-client) package
Browse files Browse the repository at this point in the history
  • Loading branch information
esperecyan committed Jun 12, 2022
1 parent 612a634 commit a571b9f
Show file tree
Hide file tree
Showing 40 changed files with 10,475 additions and 0 deletions.
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = function(config) {
'./third-party/convert2RegExp.js',
'./third-party/MatchPattern.js',
'./third-party/jszip/jszip.min.js',
'./third-party/webdav/webdav.js',
'./src/**/*.js',
'./test/**/*.test.js',
{'pattern': './skin/**', 'included': false, 'served': true},
Expand Down
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"/third-party/MatchPattern.js",
"/third-party/compare-versions/index.js",
"/third-party/jszip/jszip.min.js",
"/third-party/webdav/webdav.js",

"/src/bg/execute.run.js",
"/src/bg/user-script-detect.run.js",
Expand Down
5 changes: 5 additions & 0 deletions third-party/webdav/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Extracted from distribution version 4.10.0:

https://github.com/perry-mitchell/webdav-client/releases/tag/v4.10.0

Reused under the terms of the MIT license.
2 changes: 2 additions & 0 deletions third-party/webdav/auth/basic.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { AuthHeader } from "../types";
export declare function generateBasicAuthHeader(username: string, password: string): AuthHeader;
4 changes: 4 additions & 0 deletions third-party/webdav/auth/digest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { DigestContext, Response } from "../types";
export declare function createDigestContext(username: string, password: string): DigestContext;
export declare function generateDigestAuthHeader(options: any, digest: DigestContext): string;
export declare function parseDigestAuth(response: Response, _digest: DigestContext): boolean;
2 changes: 2 additions & 0 deletions third-party/webdav/auth/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { OAuthToken, WebDAVClientContext } from "../types";
export declare function setupAuth(context: WebDAVClientContext, username: string, password: string, oauthToken: OAuthToken): void;
2 changes: 2 additions & 0 deletions third-party/webdav/auth/oauth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { AuthHeader, OAuthToken } from "../types";
export declare function generateTokenAuthHeader(token: OAuthToken): AuthHeader;
1 change: 1 addition & 0 deletions third-party/webdav/compat/arrayBuffer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function isArrayBuffer(value: any): boolean;
1 change: 1 addition & 0 deletions third-party/webdav/compat/buffer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function isBuffer(value: any): boolean;
2 changes: 2 additions & 0 deletions third-party/webdav/compat/patcher.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import HotPatcher from "hot-patcher";
export declare function getPatcher(): HotPatcher;
2 changes: 2 additions & 0 deletions third-party/webdav/factory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { WebDAVClient, WebDAVClientOptions } from "./types";
export declare function createClient(remoteURL: string, options?: WebDAVClientOptions): WebDAVClient;
4 changes: 4 additions & 0 deletions third-party/webdav/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { createClient } from "./factory";
export { getPatcher } from "./compat/patcher";
export * from "./types";
export { parseStat, parseXML } from "./tools/dav";
2 changes: 2 additions & 0 deletions third-party/webdav/operations/copyFile.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { WebDAVClientContext, WebDAVMethodOptions } from "../types";
export declare function copyFile(context: WebDAVClientContext, filename: string, destination: string, options?: WebDAVMethodOptions): Promise<void>;
2 changes: 2 additions & 0 deletions third-party/webdav/operations/createDirectory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { CreateDirectoryOptions, WebDAVClientContext } from "../types";
export declare function createDirectory(context: WebDAVClientContext, dirPath: string, options?: CreateDirectoryOptions): Promise<void>;
5 changes: 5 additions & 0 deletions third-party/webdav/operations/createStream.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="node" />
import Stream from "stream";
import { CreateReadStreamOptions, CreateWriteStreamCallback, CreateWriteStreamOptions, WebDAVClientContext } from "../types";
export declare function createReadStream(context: WebDAVClientContext, filePath: string, options?: CreateReadStreamOptions): Stream.Readable;
export declare function createWriteStream(context: WebDAVClientContext, filePath: string, options?: CreateWriteStreamOptions, callback?: CreateWriteStreamCallback): Stream.Writable;
2 changes: 2 additions & 0 deletions third-party/webdav/operations/customRequest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { RequestOptionsCustom, Response, WebDAVClientContext } from "../types";
export declare function customRequest(context: WebDAVClientContext, remotePath: string, requestOptions: RequestOptionsCustom): Promise<Response>;
2 changes: 2 additions & 0 deletions third-party/webdav/operations/deleteFile.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { WebDAVClientContext, WebDAVMethodOptions } from "../types";
export declare function deleteFile(context: WebDAVClientContext, filename: string, options?: WebDAVMethodOptions): Promise<void>;
2 changes: 2 additions & 0 deletions third-party/webdav/operations/directoryContents.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { FileStat, GetDirectoryContentsOptions, ResponseDataDetailed, WebDAVClientContext } from "../types";
export declare function getDirectoryContents(context: WebDAVClientContext, remotePath: string, options?: GetDirectoryContentsOptions): Promise<Array<FileStat> | ResponseDataDetailed<Array<FileStat>>>;
2 changes: 2 additions & 0 deletions third-party/webdav/operations/exists.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { WebDAVClientContext, WebDAVMethodOptions } from "../types";
export declare function exists(context: WebDAVClientContext, remotePath: string, options?: WebDAVMethodOptions): Promise<boolean>;
3 changes: 3 additions & 0 deletions third-party/webdav/operations/getFileContents.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { BufferLike, GetFileContentsOptions, ResponseDataDetailed, WebDAVClientContext } from "../types";
export declare function getFileContents(context: WebDAVClientContext, filePath: string, options?: GetFileContentsOptions): Promise<BufferLike | string | ResponseDataDetailed<BufferLike | string>>;
export declare function getFileDownloadLink(context: WebDAVClientContext, filePath: string): string;
2 changes: 2 additions & 0 deletions third-party/webdav/operations/getQuota.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { DiskQuota, GetQuotaOptions, ResponseDataDetailed, WebDAVClientContext } from "../types";
export declare function getQuota(context: WebDAVClientContext, options?: GetQuotaOptions): Promise<DiskQuota | null | ResponseDataDetailed<DiskQuota | null>>;
3 changes: 3 additions & 0 deletions third-party/webdav/operations/lock.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LockOptions, LockResponse, WebDAVClientContext, WebDAVMethodOptions } from "../types";
export declare function lock(context: WebDAVClientContext, path: string, options?: LockOptions): Promise<LockResponse>;
export declare function unlock(context: WebDAVClientContext, path: string, token: string, options?: WebDAVMethodOptions): Promise<void>;
2 changes: 2 additions & 0 deletions third-party/webdav/operations/moveFile.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { WebDAVClientContext, WebDAVMethodOptions } from "../types";
export declare function moveFile(context: WebDAVClientContext, filename: string, destination: string, options?: WebDAVMethodOptions): Promise<void>;
5 changes: 5 additions & 0 deletions third-party/webdav/operations/putFileContents.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="node" />
import Stream from "stream";
import { BufferLike, PutFileContentsOptions, WebDAVClientContext } from "../types";
export declare function putFileContents(context: WebDAVClientContext, filePath: string, data: string | BufferLike | Stream.Readable, options?: PutFileContentsOptions): Promise<boolean>;
export declare function getFileUploadLink(context: WebDAVClientContext, filePath: string): string;
2 changes: 2 additions & 0 deletions third-party/webdav/operations/stat.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { FileStat, ResponseDataDetailed, StatOptions, WebDAVClientContext } from "../types";
export declare function getStat(context: WebDAVClientContext, filename: string, options?: StatOptions): Promise<FileStat | ResponseDataDetailed<FileStat>>;
3 changes: 3 additions & 0 deletions third-party/webdav/request.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RequestOptionsCustom, RequestOptionsWithState, Response, WebDAVClientContext, WebDAVMethodOptions } from "./types";
export declare function prepareRequestOptions(requestOptions: RequestOptionsCustom | RequestOptionsWithState, context: WebDAVClientContext, userOptions: WebDAVMethodOptions): RequestOptionsWithState;
export declare function request(requestOptions: RequestOptionsWithState): Promise<Response>;
5 changes: 5 additions & 0 deletions third-party/webdav/response.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FileStat, Response, ResponseDataDetailed, WebDAVClientContext } from "./types";
export declare function createErrorFromResponse(response: Response, prefix?: string): Error;
export declare function handleResponseCode(context: WebDAVClientContext, response: Response): Response;
export declare function processGlobFilter(files: Array<FileStat>, glob: string): Array<FileStat>;
export declare function processResponsePayload<T>(response: Response, data: T, isDetailed?: boolean): ResponseDataDetailed<T> | T;
1 change: 1 addition & 0 deletions third-party/webdav/tools/crypto.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function ha1Compute(algorithm: string, user: string, realm: string, pass: string, nonce: string, cnonce: string): string;
5 changes: 5 additions & 0 deletions third-party/webdav/tools/dav.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { DAVResult, DAVResultResponseProps, DiskQuotaAvailable, FileStat } from "../types";
export declare function parseXML(xml: string): Promise<DAVResult>;
export declare function prepareFileFromProps(props: DAVResultResponseProps, rawFilename: string, isDetailed?: boolean): FileStat;
export declare function parseStat(result: DAVResult, filename: string, isDetailed?: boolean): FileStat;
export declare function translateDiskSpace(value: string | number): DiskQuotaAvailable;
3 changes: 3 additions & 0 deletions third-party/webdav/tools/encode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare function decodeHTMLEntities(text: string): string;
export declare function fromBase64(text: string): string;
export declare function toBase64(text: string): string;
2 changes: 2 additions & 0 deletions third-party/webdav/tools/headers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Headers } from "../types";
export declare function mergeHeaders(...headerPayloads: Headers[]): Headers;
2 changes: 2 additions & 0 deletions third-party/webdav/tools/merge.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function cloneShallow<T extends Object>(obj: T): T;
export declare function merge(...args: Object[]): any;
3 changes: 3 additions & 0 deletions third-party/webdav/tools/path.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare function encodePath(path: any): string;
export declare function getAllDirectories(path: string): Array<string>;
export declare function normalisePath(pathStr: string): string;
2 changes: 2 additions & 0 deletions third-party/webdav/tools/quota.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { DAVResult, DiskQuota } from "../types";
export declare function parseQuota(result: DAVResult): DiskQuota | null;
2 changes: 2 additions & 0 deletions third-party/webdav/tools/size.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { BufferLike } from "../types";
export declare function calculateDataLength(data: string | BufferLike): number;
3 changes: 3 additions & 0 deletions third-party/webdav/tools/url.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare function extractURLPath(fullURL: string): string;
export declare function joinURL(...parts: Array<string>): string;
export declare function normaliseHREF(href: string): string;
2 changes: 2 additions & 0 deletions third-party/webdav/tools/xml.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function generateLockXML(ownerHREF: string): string;
export declare function parseGenericResponse(xml: string): Object;
237 changes: 237 additions & 0 deletions third-party/webdav/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
/// <reference types="node" />
import Stream from "stream";
export declare type AuthHeader = string;
export declare enum AuthType {
Digest = "digest",
None = "none",
Password = "password",
Token = "token"
}
export declare type BufferLike = Buffer | ArrayBuffer;
export interface CreateDirectoryOptions extends WebDAVMethodOptions {
recursive?: boolean;
}
export interface CreateReadStreamOptions extends WebDAVMethodOptions {
callback?: (response: Response) => void;
range?: {
start: number;
end?: number;
};
}
export declare type CreateWriteStreamCallback = (response: Response) => void;
export interface CreateWriteStreamOptions extends WebDAVMethodOptions {
overwrite?: boolean;
}
export interface DAVResultResponse {
href: string;
propstat: {
prop: DAVResultResponseProps;
status: string;
};
}
export interface DAVResultResponseProps {
displayname: string;
resourcetype: {
collection?: boolean;
};
getlastmodified?: string;
getetag?: string;
getcontentlength?: string;
getcontenttype?: string;
"quota-available-bytes"?: any;
"quota-used-bytes"?: string;
}
export interface DAVResult {
multistatus: {
response: Array<DAVResultResponse>;
};
}
export interface DAVResultRawMultistatus {
response: DAVResultResponse | [DAVResultResponse];
}
export interface DAVResultRaw {
multistatus: "" | DAVResultRawMultistatus | [DAVResultRawMultistatus];
}
export interface DigestContext {
username: string;
password: string;
nc: number;
algorithm: string;
hasDigestAuth: boolean;
cnonce?: string;
nonce?: string;
realm?: string;
qop?: string;
opaque?: string;
}
export interface DiskQuota {
used: number;
available: DiskQuotaAvailable;
}
export declare type DiskQuotaAvailable = "unknown" | "unlimited" | number;
export declare enum ErrorCode {
DataTypeNoLength = "data-type-no-length",
InvalidAuthType = "invalid-auth-type",
InvalidOutputFormat = "invalid-output-format",
LinkUnsupportedAuthType = "link-unsupported-auth"
}
export interface FileStat {
filename: string;
basename: string;
lastmod: string;
size: number;
type: "file" | "directory";
etag: string | null;
mime?: string;
props?: DAVResultResponseProps;
}
export interface GetDirectoryContentsOptions extends WebDAVMethodOptions {
deep?: boolean;
details?: boolean;
glob?: string;
}
export interface GetFileContentsOptions extends WebDAVMethodOptions {
details?: boolean;
format?: "binary" | "text";
onDownloadProgress?: ProgressEventCallback;
}
export interface GetQuotaOptions extends WebDAVMethodOptions {
details?: boolean;
path?: string;
}
export interface Headers {
[key: string]: string;
}
export interface LockOptions extends WebDAVMethodOptions {
refreshToken?: string;
timeout?: string;
}
export interface LockResponse {
serverTimeout: string;
token: string;
}
export interface OAuthToken {
access_token: string;
token_type: string;
refresh_token?: string;
}
export interface ProgressEvent {
loaded: number;
total: number;
}
export declare type ProgressEventCallback = (e: ProgressEvent) => void;
export interface PutFileContentsOptions extends WebDAVMethodOptions {
contentLength?: boolean | number;
overwrite?: boolean;
onUploadProgress?: UploadProgressCallback;
}
export declare type RequestDataPayload = string | Buffer | ArrayBuffer | {
[key: string]: any;
};
interface RequestOptionsBase {
data?: RequestDataPayload;
headers?: Headers;
httpAgent?: any;
httpsAgent?: any;
maxBodyLength?: number;
maxContentLength?: number;
maxRedirects?: number;
method: string;
onDownloadProgress?: ProgressEventCallback;
onUploadProgress?: ProgressEventCallback;
responseType?: string;
transformResponse?: Array<(value: any) => any>;
url?: string;
validateStatus?: (status: number) => boolean;
withCredentials?: boolean;
signal?: AbortSignal;
}
export interface RequestOptionsCustom extends RequestOptionsBase {
}
export interface RequestOptions extends RequestOptionsBase {
url: string;
}
export interface RequestOptionsWithState extends RequestOptions {
_digest?: DigestContext;
}
export interface Response {
data: ResponseData;
status: number;
headers: Headers;
statusText: string;
}
export declare type ResponseData = string | Buffer | ArrayBuffer | Object | Array<any>;
export interface ResponseDataDetailed<T> {
data: T;
headers: Headers;
status: number;
statusText: string;
}
export interface ResponseStatusValidator {
(status: number): boolean;
}
export interface StatOptions extends WebDAVMethodOptions {
details?: boolean;
}
export declare type UploadProgress = ProgressEvent;
export declare type UploadProgressCallback = ProgressEventCallback;
export interface WebDAVClient {
copyFile: (filename: string, destination: string) => Promise<void>;
createDirectory: (path: string, options?: CreateDirectoryOptions) => Promise<void>;
createReadStream: (filename: string, options?: CreateReadStreamOptions) => Stream.Readable;
createWriteStream: (filename: string, options?: CreateWriteStreamOptions, callback?: CreateWriteStreamCallback) => Stream.Writable;
customRequest: (path: string, requestOptions: RequestOptionsCustom) => Promise<Response>;
deleteFile: (filename: string) => Promise<void>;
exists: (path: string) => Promise<boolean>;
getDirectoryContents: (path: string, options?: GetDirectoryContentsOptions) => Promise<Array<FileStat> | ResponseDataDetailed<Array<FileStat>>>;
getFileContents: (filename: string, options?: GetFileContentsOptions) => Promise<BufferLike | string | ResponseDataDetailed<BufferLike | string>>;
getFileDownloadLink: (filename: string) => string;
getFileUploadLink: (filename: string) => string;
getHeaders: () => Headers;
getQuota: (options?: GetQuotaOptions) => Promise<DiskQuota | null | ResponseDataDetailed<DiskQuota | null>>;
lock: (path: string, options?: LockOptions) => Promise<LockResponse>;
moveFile: (filename: string, destinationFilename: string) => Promise<void>;
putFileContents: (filename: string, data: string | BufferLike | Stream.Readable, options?: PutFileContentsOptions) => Promise<boolean>;
setHeaders: (headers: Headers) => void;
stat: (path: string, options?: StatOptions) => Promise<FileStat | ResponseDataDetailed<FileStat>>;
unlock: (path: string, token: string, options?: WebDAVMethodOptions) => Promise<void>;
}
export interface WebDAVClientContext {
authType: AuthType;
contactHref: string;
digest?: DigestContext;
headers: Headers;
httpAgent?: any;
httpsAgent?: any;
maxBodyLength?: number;
maxContentLength?: number;
password?: string;
remotePath: string;
remoteURL: string;
token?: OAuthToken;
username?: string;
withCredentials?: boolean;
}
export interface WebDAVClientError extends Error {
status?: number;
response?: Response;
}
export interface WebDAVClientOptions {
authType?: AuthType;
contactHref?: string;
headers?: Headers;
httpAgent?: any;
httpsAgent?: any;
maxBodyLength?: number;
maxContentLength?: number;
password?: string;
token?: OAuthToken;
username?: string;
withCredentials?: boolean;
}
export interface WebDAVMethodOptions {
data?: RequestDataPayload;
headers?: Headers;
signal?: AbortSignal;
}
export {};
Loading

0 comments on commit a571b9f

Please sign in to comment.