Compare commits

..

No commits in common. "master" and "v1.0.3" have entirely different histories.

3 changed files with 8 additions and 45 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/smartwebdav", "name": "@push.rocks/smartwebdav",
"version": "1.1.2", "version": "1.0.3",
"private": false, "private": false,
"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.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -29,12 +29,12 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://code.foss.global/push.rocks/smartwebdav.git" "url": "git+https://code.foss.global/push.rocks/smartwebdav.git"
}, },
"bugs": { "bugs": {
"url": "https://code.foss.global/push.rocks/smartwebdav/issues" "url": "https://code.foss.global/push.rocks/smartwebdav/issues"
}, },
"homepage": "https://code.foss.global/push.rocks/smartwebdav", "homepage": "https://code.foss.global/push.rocks/smartwebdav#readme",
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
], ],

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartwebdav', name: '@push.rocks/smartwebdav',
version: '1.1.2', version: '1.0.3',
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,9 +1,8 @@
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 {
serverUrl: string; serverUrl: string;
authType?: plugins.webdav.AuthType; authType: plugins.webdav.AuthType;
username?: string; username?: string;
password?: string; password?: string;
} }
@ -12,11 +11,7 @@ export class WebdavClient {
wdClient: plugins.webdav.WebDAVClient; wdClient: plugins.webdav.WebDAVClient;
constructor(optionsArg: IWebdavClientOptions) { constructor(optionsArg: IWebdavClientOptions) {
this.wdClient = plugins.webdav.createClient(optionsArg.serverUrl, { this.wdClient = plugins.webdav.createClient(optionsArg.serverUrl, {
...optionsArg.authType ? { authType: optionsArg.authType,
authType: optionsArg.authType,
} : {
authType: plugins.webdav.AuthType.Password,
},
...(optionsArg.username ...(optionsArg.username
? { ? {
username: optionsArg.username, username: optionsArg.username,
@ -35,18 +30,6 @@ export class WebdavClient {
return result as plugins.webdav.FileStat[]; return result as plugins.webdav.FileStat[];
} }
public async getDirectoryAsSmartfileArray(pathArg: string): Promise<plugins.smartfile.SmartFile[]> {
const directoryListing = await this.listDirectory(pathArg);
const smartfileArray: plugins.smartfile.SmartFile[] = [];
for (const file of directoryListing) {
const fileContents = (await this.wdClient.getFileContents(file.filename, {
format: 'binary',
})) as Buffer;
smartfileArray.push(await plugins.smartfile.SmartFile.fromBuffer(file.filename, fileContents));
}
return smartfileArray;
}
public async ensureDirectory(path: string): Promise<void> { public async ensureDirectory(path: string): Promise<void> {
console.log(`Ensuring directory at ${path}`); console.log(`Ensuring directory at ${path}`);
const pathLevels = plugins.smartpath.get.pathLevels(path); const pathLevels = plugins.smartpath.get.pathLevels(path);
@ -113,27 +96,7 @@ export class WebdavClient {
await this.wdClient.moveFile(sourcePathArg, targetPathArg); await this.wdClient.moveFile(sourcePathArg, targetPathArg);
} }
public async deleteFile(pathArg: string, checkNotDirectory = true) { public async deleteDirectory(pathArg: string) {
if (!(await this.wdClient.exists(pathArg))) {
throw new Error(`Path does not exist`);
}
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);
} }
public async deleteDirectory(pathArg: string) {
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';
}
} }