fix(core): update

This commit is contained in:
Philipp Kunz 2024-04-22 18:57:39 +02:00
parent 825167af68
commit b0152e1fe4
2 changed files with 17 additions and 4 deletions

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartwebdav', name: '@push.rocks/smartwebdav',
version: '1.1.1', version: '1.1.2',
description: 'A TypeScript library for easy interaction with WebDAV servers, including file and directory management.' description: 'A TypeScript library for easy interaction with WebDAV servers, including file and directory management.'
} }

View File

@ -1,3 +1,4 @@
import type { isFile } from '@push.rocks/smartpath/dist_ts/smartpath.check.js';
import * as plugins from './plugins.js'; import * as plugins from './plugins.js';
export interface IWebdavClientOptions { export interface IWebdavClientOptions {
@ -113,9 +114,11 @@ export class WebdavClient {
} }
public async deleteFile(pathArg: string, checkNotDirectory = true) { public async deleteFile(pathArg: string, checkNotDirectory = true) {
const stat = (await this.wdClient.stat(pathArg)) as plugins.webdav.FileStat; if (!(await this.wdClient.exists(pathArg))) {
if (checkNotDirectory && stat.type === 'directory') { throw new Error(`Path does not exist`);
throw new Error(`Cannot delete a directory using deleteFile method. Use deleteDirectory instead.`); }
if (checkNotDirectory && (await this.isDirecory(pathArg))) {
throw new Error(`Path is a directory, not a file`);
} }
await this.wdClient.deleteFile(pathArg); await this.wdClient.deleteFile(pathArg);
} }
@ -123,4 +126,14 @@ export class WebdavClient {
public async deleteDirectory(pathArg: string) { public async deleteDirectory(pathArg: string) {
await this.deleteFile(pathArg, false); await this.deleteFile(pathArg, false);
} }
public async isFile(pathArg: string) {
const stat = (await this.wdClient.stat(pathArg)) as plugins.webdav.FileStat;
return stat.type === 'file';
}
public async isDirecory(pathArg: string) {
const stat = (await this.wdClient.stat(pathArg)) as plugins.webdav.FileStat;
return stat.type === 'directory';
}
} }