import * as querystring from 'querystring' ; import * as vscode from 'vscode' ; import { callWithTelemetryAndErrorHandling , IActionContext } from 'vscode-azureextensionui' ; import { ext } from '../extensionVariables' ; import { localize } from '../localize' ; import { getWorkspaceSetting } from '../vsCodeConfig/settings' ; import { setupProjectFolder } from './setupProjectFolder' ; export enum HandleUriActions { downloadContentAndSetupProject = 'downloadContentAndSetupProject' } export async function handleUri ( uri ) { await callWithTelemetryAndErrorHandling ( 'azureFunctions.handleUri' , async ( context ) => { const enableOpenFromPortal = getWorkspaceSetting < boolean > ( 'enableOpenFromPortal' ) ; if ( enableOpenFromPortal ) { const parsedQuery = querystring . parse ( uri . query ) ; const action = getRequiredQueryParameter ( parsedQuery , 'action' ) ; if ( action === HandleUriActions . downloadContentAndSetupProject ) { const isLoggedIn = await ext . azureAccountTreeItem . getIsLoggedIn ( ) ; if ( ! isLoggedIn ) { await vscode . commands . executeCommand ( 'azure-account.login' ) ; } const filePathUri = await context . ui . showOpenDialog ( { canSelectFolders : true , canSelectFiles : false , canSelectMany : false } ) ; await setupProjectFolder ( uri , filePathUri [ 0 ] , context ) ; } else { throw new RangeError ( localize ( 'invalidAction' , 'Invalid action "{0}".' , action ) ) ; } } else { throw new Error ( localize ( 'featureNotSupported' , 'Download content and setup project feature is not supported for this extension version.' ) ) ; } } ) ; } export function getRequiredQueryParameter ( parsedQuery , key ) { const value = parsedQuery [ key ] ; if ( value && typeof value === 'string' ) { return value ; } else { throw new Error ( localize ( 'missingQueryParam' , 'Missing query parameter "{0}".' , key ) ) ; } }