'use strict' ; import * as vscode from 'vscode' ; import { Uri } from 'vscode' ; import { ICommand , IConfig } from '../spgo' ; import { Logger } from '../util/logger' ; import { UiHelper } from '../util/uiHelper' ; import { UrlHelper } from '../util/urlHelper' ; import { FileHelper } from '../util/fileHelper' ; import { ErrorHelper } from '../util/errorHelper' ; import { SPFileService } from '../service/spFileService' ; import { AuthenticationService } from '../service/authenticationService' ; import { WorkspaceHelper } from '../util/workspaceHelper' ; export class GetServerVersionCommand implements ICommand { param { vscode . Uri } resourcePath param { boolean } absolute execute ( fileUri , _props ? ) { try { const fileName = FileHelper . getFileName ( fileUri ) ; return UiHelper . showStatusBarProgress ( `Getting server version for:  ${ fileName }` , vscode . window . spgo . initialize ( fileUri ) . then ( ( config ) => { Logger . outputMessage ( `Getting server version for:  ${ fileName }` , vscode . window . spgo . outputChannel ) ; return AuthenticationService . verifyCredentials ( vscode . window . spgo , config , fileUri ) . then ( ( fileUri ) => this . getServerFiles ( config , fileUri ) ) . then ( ( ) => Logger . updateStatusBar ( 'File Download Complete.' , 5 ) ) ; } ) . catch ( err => ErrorHelper . handleError ( err ) ) ) ; } catch ( err ) { ErrorHelper . handleError ( err , true ) ; } } public getServerFiles ( config , fileUri ) { let fileService = new SPFileService ( config ) ; let sharePointFileUri = UrlHelper . getServerRelativeFileUri ( fileUri . fsPath , config ) ; let siteUri = WorkspaceHelper . getSiteUriForActiveWorkspace ( sharePointFileUri . toString ( ) , config ) ; if ( FileHelper . isPathFile ( fileUri ) ) { return fileService . downloadFileMajorVersion ( fileUri , config . sourceRoot ) ; } else { let folderPath = sharePointFileUri . toString ( ) . replace ( siteUri . toString ( ) , '' ) ; folderPath = UrlHelper . normalizeSlashes ( folderPath ) ; return fileService . downloadFiles ( siteUri , folderPath + '/**/*' ) ; } } }