Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lightapis/userscript-with-webdav

Connect WebDAV in the Tampermonkey/Violentmonkey script
https://github.com/lightapis/userscript-with-webdav

tampermonkey userscript violentmonkey webdav

Last synced: 9 days ago
JSON representation

Connect WebDAV in the Tampermonkey/Violentmonkey script

Awesome Lists containing this project

README

        

# userscript-with-webdav

Connect WebDAV in the Tampermonkey/Violentmonkey script.

## Installation

in userscript:

```jsvascript
// @require https://cdn.jsdelivr.net/npm/userscript-with-webdav@latest/index.iife.js
// @grant GM_xmlhttpRequest
// @connect *
```

or embed:

```shell
npm install userscript-with-webdav
```

## Usage

Example:

```typescript
// When embed:
import Webdav from 'userscript-with-webdav';

(async () => {
const wh = new Webdav('', '', '');

// download
try {
const res = await wh.download('path/to/your/file');
console.log('status:', res.status);
console.log('data:', res.data);
} catch (err) {
if (err instanceof Webdav.NotFound) {
console.error('file does not exist');
} else if (err instanceof Webdav.Unauthorized) {
console.error('authentication failed');
}
}

// upload
try {
await wh.upload('path/to/your/file', '');
} catch (err) {
if (err instanceof Webdav.Forbidden) {
console.error('permission error');
}
}
})();
```

## Type

```typescript
declare class Webdav {
static InternalError: typeof InternalError;
static Unauthorized: typeof Unauthorized;
static Forbidden: typeof Forbidden;
static NotFound: typeof NotFound;
static Redirection: typeof Redirection;
static ClientSideError: typeof ClientSideError;
static ServerSideError: typeof ServerSideError;
/**
* Constructor
* @param domainURL WebDAV domain
* @param user User name
* @param password User password
*/
constructor(domainURL?: string, user?: string, password?: string);
/**
* Generate validation request header
* @returns Verification request header
*/
updateConfig(domainURL: string, user: string, password: string): void;
/**
* Download file content
* @param fileURL Relative file URL
* @returns Response
*/
download(fileURL: string): Promise;
/**
* Upload file content
* @param fileURL Relative file URL
* @param data Data
* @returns Response
*/
upload(fileURL: string, data: string): Promise;
}

declare interface ConnectionResponse {
/** Response status code */
status: number;
/** Response data */
data: string;
}
```

## License

[MIT](./LICENSE)