Compare commits
	
		
			6 Commits
		
	
	
		
			v1.0.3
			...
			825167af68
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 825167af68 | |||
| ba559e4304 | |||
| a6d67b22af | |||
| fc0001b6b3 | |||
| 3805d361d7 | |||
| 18f5a05c1d | 
@@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "@push.rocks/smartwebdav",
 | 
					  "name": "@push.rocks/smartwebdav",
 | 
				
			||||||
  "version": "1.0.3",
 | 
					  "version": "1.1.1",
 | 
				
			||||||
  "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",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,6 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
export const commitinfo = {
 | 
					export const commitinfo = {
 | 
				
			||||||
  name: '@push.rocks/smartwebdav',
 | 
					  name: '@push.rocks/smartwebdav',
 | 
				
			||||||
  version: '1.0.3',
 | 
					  version: '1.1.1',
 | 
				
			||||||
  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.'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@ 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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -11,7 +11,11 @@ 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,
 | 
				
			||||||
@@ -30,6 +34,18 @@ 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);
 | 
				
			||||||
@@ -96,7 +112,15 @@ export class WebdavClient {
 | 
				
			|||||||
    await this.wdClient.moveFile(sourcePathArg, targetPathArg);
 | 
					    await this.wdClient.moveFile(sourcePathArg, targetPathArg);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public async deleteDirectory(pathArg: string) {
 | 
					  public async deleteFile(pathArg: string, checkNotDirectory = true) {
 | 
				
			||||||
 | 
					    const stat = (await this.wdClient.stat(pathArg)) as plugins.webdav.FileStat;
 | 
				
			||||||
 | 
					    if (checkNotDirectory && stat.type === 'directory') {
 | 
				
			||||||
 | 
					      throw new Error(`Cannot delete a directory using deleteFile method. Use deleteDirectory instead.`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    await this.wdClient.deleteFile(pathArg);
 | 
					    await this.wdClient.deleteFile(pathArg);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public async deleteDirectory(pathArg: string) {
 | 
				
			||||||
 | 
					    await this.deleteFile(pathArg, false);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user