From fc0001b6b3b263a992d521b862b5d98a389aaf74 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 22 Apr 2024 13:01:11 +0200 Subject: [PATCH] feat(webdavclient): add method for getting directory as smartfilearray --- ts/00_commitinfo_data.ts | 2 +- ts/classes.webdavclient.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 5eb2e32..6917764 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartwebdav', - version: '1.0.4', + version: '1.1.0', description: 'A TypeScript library for easy interaction with WebDAV servers, including file and directory management.' } diff --git a/ts/classes.webdavclient.ts b/ts/classes.webdavclient.ts index 420d76c..7cd0fa6 100644 --- a/ts/classes.webdavclient.ts +++ b/ts/classes.webdavclient.ts @@ -34,6 +34,18 @@ export class WebdavClient { return result as plugins.webdav.FileStat[]; } + public async getDirectoryAsSmartfileArray(pathArg: string): Promise { + 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 { console.log(`Ensuring directory at ${path}`); const pathLevels = plugins.smartpath.get.pathLevels(path);