fix(core): update
This commit is contained in:
commit
6a4d029dfe
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
20
.gitignore
vendored
Normal file
20
.gitignore
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
33
npmextra.json
Normal file
33
npmextra.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartwebdav",
|
||||
"description": "A TypeScript library for easy interaction with WebDAV servers, including file and directory management.",
|
||||
"npmPackagename": "@push.rocks/smartwebdav",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks",
|
||||
"keywords": [
|
||||
"WebDAV client",
|
||||
"file upload",
|
||||
"directory management",
|
||||
"remote file system",
|
||||
"smartfile integration",
|
||||
"TypeScript library",
|
||||
"node.js",
|
||||
"smartpath",
|
||||
"authentication",
|
||||
"secure file transfer"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
65
package.json
Normal file
65
package.json
Normal file
@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "@push.rocks/smartwebdav",
|
||||
"version": "1.0.2",
|
||||
"private": false,
|
||||
"description": "A TypeScript library for easy interaction with WebDAV servers, including file and directory management.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Task Venture Capital GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "(tsdoc)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.25",
|
||||
"@git.zone/tsbundle": "^2.0.5",
|
||||
"@git.zone/tsrun": "^1.2.46",
|
||||
"@git.zone/tstest": "^1.0.44",
|
||||
"@push.rocks/qenv": "^6.0.5",
|
||||
"@push.rocks/tapbundle": "^5.0.15",
|
||||
"@types/node": "^20.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@push.rocks/smartfile": "^11.0.14",
|
||||
"@push.rocks/smartpath": "^5.0.16",
|
||||
"webdav": "^5.5.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://code.foss.global/push.rocks/smartwebdav.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://code.foss.global/push.rocks/smartwebdav/issues"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/smartwebdav#readme",
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"keywords": [
|
||||
"WebDAV client",
|
||||
"file upload",
|
||||
"directory management",
|
||||
"remote file system",
|
||||
"smartfile integration",
|
||||
"TypeScript library",
|
||||
"node.js",
|
||||
"smartpath",
|
||||
"authentication",
|
||||
"secure file transfer"
|
||||
]
|
||||
}
|
4770
pnpm-lock.yaml
generated
Normal file
4770
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
* a abstraction package for the webdav package that enables compatibility with the @push.rocks/smartfile ecosystem
|
149
readme.md
Normal file
149
readme.md
Normal file
@ -0,0 +1,149 @@
|
||||
# @push.rocks/smartwebdav
|
||||
|
||||
A package for interacting with WebDAV servers, providing easy file and directory operations.
|
||||
|
||||
## Install
|
||||
|
||||
To install `@push.rocks/smartwebdav` in your project, use npm or Yarn as follows:
|
||||
|
||||
```shell
|
||||
npm install @push.rocks/smartwebdav
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```shell
|
||||
yarn add @push.rocks/smartwebdav
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The `@push.rocks/smartwebdav` package offers a high-level abstraction for interacting with WebDAV servers. It integrates seamlessly with the `@push.rocks/smartfile` ecosystem for file handling, and `@push.rocks/smartpath` for path operations, providing a straightforward interface for file and directory operations on a remote WebDAV server.
|
||||
|
||||
First, you must import the package and other necessary libraries in your TypeScript file:
|
||||
|
||||
```typescript
|
||||
import { WebdavClient, authType } from '@push.rocks/smartwebdav';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
```
|
||||
|
||||
### Creating a WebDAV Client Instance
|
||||
|
||||
Before performing any operations, create an instance of `WebdavClient`. You need to provide server details including the URL, authentication type, and credentials (if required).
|
||||
|
||||
```typescript
|
||||
const webdavClient = new WebdavClient({
|
||||
serverUrl: 'https://your.webdavserver.com/',
|
||||
authType: authType.Password,
|
||||
username: 'your_username',
|
||||
password: 'your_password'
|
||||
});
|
||||
```
|
||||
|
||||
### Listing Directory Contents
|
||||
|
||||
To list the contents of a directory on your WebDAV server:
|
||||
|
||||
```typescript
|
||||
async function listDirectoryContents() {
|
||||
const contents = await webdavClient.listDirectory('/path/to/directory');
|
||||
console.log(contents);
|
||||
}
|
||||
|
||||
listDirectoryContents();
|
||||
```
|
||||
|
||||
### Creating Directories
|
||||
|
||||
Ensure a directory exists (creating it and its parents if necessary):
|
||||
|
||||
```typescript
|
||||
async function ensureDirectory() {
|
||||
await webdavClient.ensureDirectory('/path/to/ensure');
|
||||
console.log('Directory ensured.');
|
||||
}
|
||||
|
||||
ensureDirectory();
|
||||
```
|
||||
|
||||
### Uploading Files
|
||||
|
||||
Uploading files is made easy by integrating with the `@push.rocks/smartfile` package. This allows for uploading from various sources like local files, buffers, and more.
|
||||
|
||||
```typescript
|
||||
async function uploadFiles() {
|
||||
const smartFiles = await smartfile.smartfileLocal.getSmartfileArrayFromGlob([
|
||||
'path/to/local/files/**/*'
|
||||
]);
|
||||
|
||||
await webdavClient.uploadSmartFileArray(smartFiles);
|
||||
console.log('Files uploaded successfully.');
|
||||
}
|
||||
|
||||
uploadFiles();
|
||||
```
|
||||
|
||||
### Deleting Files and Directories
|
||||
|
||||
You can also delete specific files or entire directories:
|
||||
|
||||
```typescript
|
||||
async function deleteDirectory() {
|
||||
await webdavClient.deleteDirectory('/path/to/delete');
|
||||
console.log('Directory deleted.');
|
||||
}
|
||||
|
||||
deleteDirectory();
|
||||
```
|
||||
|
||||
### Moving Files
|
||||
|
||||
Moving files from one location to another is also supported:
|
||||
|
||||
```typescript
|
||||
async function moveFile() {
|
||||
await webdavClient.move('/path/to/file.txt', '/new/path/to/file.txt');
|
||||
console.log('File moved.');
|
||||
}
|
||||
|
||||
moveFile();
|
||||
```
|
||||
|
||||
### Handling Errors
|
||||
|
||||
When performing WebDAV operations, it's crucial to handle potential errors. This can involve retrying operations or logging errors for later analysis. For instance, ensuring directory creation could include error handling as follows:
|
||||
|
||||
```typescript
|
||||
async function ensureDirectorySafe() {
|
||||
try {
|
||||
await webdavClient.ensureDirectory('/path/to/ensure');
|
||||
console.log('Directory ensured safely.');
|
||||
} catch (error) {
|
||||
console.error('Failed to ensure directory:', error);
|
||||
// Implement retry logic or error handling here
|
||||
}
|
||||
}
|
||||
|
||||
ensureDirectorySafe();
|
||||
```
|
||||
|
||||
By leveraging `@push.rocks/smartwebdav`, developers can simplify complex WebDAV interactions, making it easier to manage remote file and directory operations in TypeScript applications. The combination of easy-to-use methods and integration with powerful file handling packages provides a robust solution for working with WebDAV servers.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
36
test/test.ts
Normal file
36
test/test.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartwebdav from '../ts/index.js'
|
||||
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
let webdavClient: smartwebdav.WebdavClient;
|
||||
|
||||
tap.test('should', async () => {
|
||||
webdavClient = new smartwebdav.WebdavClient({
|
||||
serverUrl: await testQenv.getEnvVarOnDemand('SERVER_URL'),
|
||||
authType: smartwebdav.authType.Password,
|
||||
password: await testQenv.getEnvVarOnDemand('SERVER_TOKEN'),
|
||||
});
|
||||
|
||||
const directoryListed = await webdavClient.listDirectory('/testdir');
|
||||
console.log(directoryListed);
|
||||
});
|
||||
|
||||
tap.test('should upload smartfiles', async () => {
|
||||
const smartfile1 = await smartfile.SmartFile.fromString('./testdir/so/awesome/hello.txt', 'hello there', 'utf8');
|
||||
const smartfile2 = await smartfile.SmartFile.fromString('./testdir/so/awesome/hello2.txt', 'hello there 2', 'utf8');
|
||||
|
||||
await webdavClient.uploadSmartFileArray([smartfile1, smartfile2]);
|
||||
});
|
||||
|
||||
tap.test('should ensure directory', async () => {
|
||||
await webdavClient.ensureDirectory('/testdir/another/dirctory');
|
||||
})
|
||||
|
||||
tap.test('should delete a directory', async () => {
|
||||
await webdavClient.deleteDirectory('/testdir/another');
|
||||
})
|
||||
|
||||
export default tap.start()
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartwebdav',
|
||||
version: '1.0.3',
|
||||
description: 'A TypeScript library for easy interaction with WebDAV servers, including file and directory management.'
|
||||
}
|
102
ts/classes.webdavclient.ts
Normal file
102
ts/classes.webdavclient.ts
Normal file
@ -0,0 +1,102 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export interface IWebdavClientOptions {
|
||||
serverUrl: string;
|
||||
authType: plugins.webdav.AuthType;
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
export class WebdavClient {
|
||||
wdClient: plugins.webdav.WebDAVClient;
|
||||
constructor(optionsArg: IWebdavClientOptions) {
|
||||
this.wdClient = plugins.webdav.createClient(optionsArg.serverUrl, {
|
||||
authType: optionsArg.authType,
|
||||
...(optionsArg.username
|
||||
? {
|
||||
username: optionsArg.username,
|
||||
}
|
||||
: {}),
|
||||
...(optionsArg.password
|
||||
? {
|
||||
password: optionsArg.password,
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
|
||||
public async listDirectory(pathArg: string) {
|
||||
const result = await this.wdClient.getDirectoryContents('/');
|
||||
return result as plugins.webdav.FileStat[];
|
||||
}
|
||||
|
||||
public async ensureDirectory(path: string): Promise<void> {
|
||||
console.log(`Ensuring directory at ${path}`);
|
||||
const pathLevels = plugins.smartpath.get.pathLevels(path);
|
||||
let pathTrace = ``;
|
||||
for (const pathLevel of pathLevels) {
|
||||
pathTrace += `/${pathLevel}`;
|
||||
try {
|
||||
const exists = await this.wdClient.exists(pathTrace);
|
||||
if (!exists) {
|
||||
await this.wdClient.createDirectory(pathTrace);
|
||||
console.log(`Directory created at ${pathTrace}`);
|
||||
} else {
|
||||
console.log(`Directory already exists at ${pathTrace}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error ensuring directory: ${error}`);
|
||||
throw error; // Re-throw to handle it according to your application's logic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async ensureEmptyDirectory(path: string): Promise<void> {
|
||||
console.log(`Ensuring empty directory at ${path}`);
|
||||
try {
|
||||
const exists = await this.wdClient.exists(path);
|
||||
if (!exists) {
|
||||
await this.wdClient.createDirectory(path);
|
||||
console.log(`Directory created at ${path}`);
|
||||
} else {
|
||||
console.log(`Directory already exists at ${path}`);
|
||||
const directoryListing = await this.listDirectory(path);
|
||||
for (const file of directoryListing) {
|
||||
await this.wdClient.deleteFile(file.filename);
|
||||
}
|
||||
console.log(`Directory emptied at ${path}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error ensuring directory: ${error}`);
|
||||
throw error; // Re-throw to handle it according to your application's logic
|
||||
}
|
||||
}
|
||||
|
||||
private async prepareFileName(fileName: string) {
|
||||
fileName.startsWith('../') ? (fileName = fileName.slice(1)) : null;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public async uploadSmartFileArray(smartfileArrayArg: plugins.smartfile.SmartFile[]) {
|
||||
for (const smartfileArg of smartfileArrayArg) {
|
||||
const cleanFileName = await this.prepareFileName(smartfileArg.relative);
|
||||
await this.ensureDirectory(plugins.smartpath.get.dirname(cleanFileName));
|
||||
await this.wdClient.putFileContents(cleanFileName, smartfileArg.contents);
|
||||
}
|
||||
}
|
||||
|
||||
public async deleteSmartfileArray(smartfileArrayArg: plugins.smartfile.SmartFile[]) {
|
||||
for (const smartfileArg of smartfileArrayArg) {
|
||||
const cleanFileName = await this.prepareFileName(smartfileArg.relative);
|
||||
await this.wdClient.deleteFile(cleanFileName);
|
||||
}
|
||||
}
|
||||
|
||||
public async move(sourcePathArg: string, targetPathArg: string) {
|
||||
await this.wdClient.moveFile(sourcePathArg, targetPathArg);
|
||||
}
|
||||
|
||||
public async deleteDirectory(pathArg: string) {
|
||||
await this.wdClient.deleteFile(pathArg);
|
||||
}
|
||||
}
|
4
ts/index.ts
Normal file
4
ts/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import * as plugins from './plugins.js';
|
||||
export * from './classes.webdavclient.js';
|
||||
|
||||
export const authType = plugins.webdav.AuthType;
|
15
ts/plugins.ts
Normal file
15
ts/plugins.ts
Normal file
@ -0,0 +1,15 @@
|
||||
// @push.rocks scope
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartpath from '@push.rocks/smartpath'
|
||||
|
||||
export {
|
||||
smartfile,
|
||||
smartpath,
|
||||
}
|
||||
|
||||
// third party scope
|
||||
import * as webdav from 'webdav';
|
||||
|
||||
export {
|
||||
webdav,
|
||||
}
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user