'use strict' ; import * as vscode from 'vscode' ; import { Uri } from 'vscode' ; import { Logger } from '../util/logger' ; import { UiHelper } from '../util/uiHelper' ; import { ICommand , IConfig } from '../spgo' ; import { UrlHelper } from '../util/urlHelper' ; import { ErrorHelper } from '../util/errorHelper' ; import { SPFileService } from '../service/spFileService' ; import { WorkspaceHelper } from '../util/workspaceHelper' ; import { AuthenticationService } from '../service/authenticationService' ; export class RetrieveFolderCommand implements ICommand { param { vscode . Uri } resourcePath param { boolean } absolute execute ( _fileUri , _props ? ) { try { return UiHelper . showStatusBarProgress ( 'Downloading files' , WorkspaceHelper . getActiveWorkspaceUri ( ) . then ( ( activeWorkspace ) => vscode . window . spgo . initialize ( activeWorkspace ) ) . then ( ( config ) => { return AuthenticationService . verifyCredentials ( vscode . window . spgo , config ) . then ( ( ) => this . downloadFiles ( config ) ) . then ( ( ) => Logger . updateStatusBar ( 'File Download Complete.' , 5 ) ) ; } ) . catch ( err => ErrorHelper . handleError ( err ) ) ) ; } catch ( err ) { ErrorHelper . handleError ( err , true ) ; } } public downloadFiles ( config ) { Logger . outputMessage ( 'Starting folder download...' , vscode . window . spgo . outputChannel ) ; let options = { ignoreFocusOut : true , placeHolder : '/site/relative/path/to/folder' , prompt : 'Enter a site relative path to the folder or file you would like to download. WARNING: This will overwrite all local files!!' , } ; return vscode . window . showInputBox ( options ) . then ( result => { let fileService = new SPFileService ( config ) ; let remoteFolderUri = config . sharePointSiteUrl + UrlHelper . ensureLeadingWebSlash ( result ) ; let siteUri = WorkspaceHelper . getSiteUriForActiveWorkspace ( remoteFolderUri , config ) ; let remoteFolder = remoteFolderUri . replace ( siteUri . toString ( ) , '' ) ; let localFolder = remoteFolder ; try { return fileService . downloadFiles ( siteUri , remoteFolder ) . then ( ( downloadResults ) => { Logger . outputMessage ( `Successfully downloaded ${ downloadResults . length } files to: ${ localFolder }` , vscode . window . spgo . outputChannel ) ; } ) ; } catch ( ex ) { ErrorHelper . handleError ( ex ) ; } } ) ; } }