mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-04-01 17:40:30 -04:00
Merge from vscode e1d3dd53d17fb1529a002e4d6fb066db0a0bd385 (#6460)
* Merge from vscode e1d3dd53d17fb1529a002e4d6fb066db0a0bd385 * fix servers icon * fix tests
This commit is contained in:
@@ -13,6 +13,6 @@ export interface IDownloadService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
download(uri: URI, to?: string, cancellationToken?: CancellationToken): Promise<string>;
|
||||
download(uri: URI, to: URI, cancellationToken?: CancellationToken): Promise<void>;
|
||||
|
||||
}
|
||||
|
||||
42
src/vs/platform/download/common/downloadIpc.ts
Normal file
42
src/vs/platform/download/common/downloadIpc.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IDownloadService } from 'vs/platform/download/common/download';
|
||||
import { IURITransformer } from 'vs/base/common/uriIpc';
|
||||
|
||||
export class DownloadServiceChannel implements IServerChannel {
|
||||
|
||||
constructor(private readonly service: IDownloadService) { }
|
||||
|
||||
listen(_: unknown, event: string, arg?: any): Event<any> {
|
||||
throw new Error('Invalid listen');
|
||||
}
|
||||
|
||||
call(context: any, command: string, args?: any): Promise<any> {
|
||||
switch (command) {
|
||||
case 'download': return this.service.download(URI.revive(args[0]), URI.revive(args[1]));
|
||||
}
|
||||
throw new Error('Invalid call');
|
||||
}
|
||||
}
|
||||
|
||||
export class DownloadServiceChannelClient implements IDownloadService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(private channel: IChannel, private getUriTransformer: () => IURITransformer | null) { }
|
||||
|
||||
async download(from: URI, to: URI): Promise<void> {
|
||||
const uriTransfomer = this.getUriTransformer();
|
||||
if (uriTransfomer) {
|
||||
from = uriTransfomer.transformOutgoingURI(from);
|
||||
to = uriTransfomer.transformOutgoingURI(to);
|
||||
}
|
||||
await this.channel.call('download', [from, to]);
|
||||
}
|
||||
}
|
||||
36
src/vs/platform/download/common/downloadService.ts
Normal file
36
src/vs/platform/download/common/downloadService.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IDownloadService } from 'vs/platform/download/common/download';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IRequestService, asText } from 'vs/platform/request/common/request';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
|
||||
export class DownloadService implements IDownloadService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(
|
||||
@IRequestService private readonly requestService: IRequestService,
|
||||
@IFileService private readonly fileService: IFileService
|
||||
) { }
|
||||
|
||||
async download(resource: URI, target: URI, cancellationToken: CancellationToken = CancellationToken.None): Promise<void> {
|
||||
if (resource.scheme === Schemas.file) {
|
||||
await this.fileService.copy(resource, target);
|
||||
return;
|
||||
}
|
||||
const options = { type: 'GET', url: resource.toString() };
|
||||
const context = await this.requestService.request(options, cancellationToken);
|
||||
if (context.res.statusCode === 200) {
|
||||
await this.fileService.writeFile(target, context.stream);
|
||||
} else {
|
||||
const message = await asText(context);
|
||||
return Promise.reject(new Error(`Expected 200, got back ${context.res.statusCode} instead.\n\n${message}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user