4 Commits

Author SHA1 Message Date
a6d67b22af 1.1.0 2024-04-22 13:01:11 +02:00
fc0001b6b3 feat(webdavclient): add method for getting directory as smartfilearray 2024-04-22 13:01:11 +02:00
3805d361d7 1.0.4 2024-04-20 21:41:30 +02:00
18f5a05c1d fix(core): update 2024-04-20 21:41:30 +02:00
3 changed files with 20 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartwebdav",
"version": "1.0.3",
"version": "1.1.0",
"private": false,
"description": "A TypeScript library for easy interaction with WebDAV servers, including file and directory management.",
"main": "dist_ts/index.js",

View File

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

View File

@ -2,7 +2,7 @@ import * as plugins from './plugins.js';
export interface IWebdavClientOptions {
serverUrl: string;
authType: plugins.webdav.AuthType;
authType?: plugins.webdav.AuthType;
username?: string;
password?: string;
}
@ -11,7 +11,11 @@ export class WebdavClient {
wdClient: plugins.webdav.WebDAVClient;
constructor(optionsArg: IWebdavClientOptions) {
this.wdClient = plugins.webdav.createClient(optionsArg.serverUrl, {
authType: optionsArg.authType,
...optionsArg.authType ? {
authType: optionsArg.authType,
} : {
authType: plugins.webdav.AuthType.Password,
},
...(optionsArg.username
? {
username: optionsArg.username,
@ -30,6 +34,18 @@ export class WebdavClient {
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> {
console.log(`Ensuring directory at ${path}`);
const pathLevels = plugins.smartpath.get.pathLevels(path);