mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 01:25:36 -05:00
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { UriHandler, Uri, window, Disposable, commands } from 'vscode';
|
|
import { dispose } from './util';
|
|
import * as querystring from 'querystring';
|
|
|
|
const schemes = new Set(['file', 'git', 'http', 'https', 'ssh']);
|
|
|
|
export class GitProtocolHandler implements UriHandler {
|
|
|
|
private disposables: Disposable[] = [];
|
|
|
|
constructor() {
|
|
this.disposables.push(window.registerUriHandler(this));
|
|
}
|
|
|
|
handleUri(uri: Uri): void {
|
|
switch (uri.path) {
|
|
case '/clone': this.clone(uri);
|
|
}
|
|
}
|
|
|
|
private clone(uri: Uri): void {
|
|
const data = querystring.parse(uri.query);
|
|
|
|
if (!data.url) {
|
|
console.warn('Failed to open URI:', uri);
|
|
return;
|
|
}
|
|
|
|
if (Array.isArray(data.url) && data.url.length === 0) {
|
|
console.warn('Failed to open URI:', uri);
|
|
return;
|
|
}
|
|
|
|
let cloneUri: Uri;
|
|
try {
|
|
cloneUri = Uri.parse(Array.isArray(data.url) ? data.url[0] : data.url, true);
|
|
if (!schemes.has(cloneUri.scheme.toLowerCase())) {
|
|
throw new Error('Unsupported scheme.');
|
|
}
|
|
}
|
|
catch (ex) {
|
|
console.warn('Invalid URI:', uri);
|
|
return;
|
|
}
|
|
|
|
commands.executeCommand('git.clone', cloneUri.toString(true));
|
|
}
|
|
|
|
dispose(): void {
|
|
this.disposables = dispose(this.disposables);
|
|
}
|
|
}
|