mirror of
https://github.com/coder/code-server.git
synced 2026-05-09 22:07:26 +02:00
Merge commit 'be3e8236086165e5e45a5a10783823874b3f3ebd' as 'lib/vscode'
This commit is contained in:
18
lib/vscode/src/vs/platform/download/common/download.ts
Normal file
18
lib/vscode/src/vs/platform/download/common/download.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
|
||||
export const IDownloadService = createDecorator<IDownloadService>('downloadService');
|
||||
|
||||
export interface IDownloadService {
|
||||
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
download(uri: URI, to: URI, cancellationToken?: CancellationToken): Promise<void>;
|
||||
|
||||
}
|
||||
42
lib/vscode/src/vs/platform/download/common/downloadIpc.ts
Normal file
42
lib/vscode/src/vs/platform/download/common/downloadIpc.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. 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 {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. 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 {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
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 || resource.scheme === Schemas.vscodeRemote) {
|
||||
// Intentionally only support this for file|remote<->file|remote scenarios
|
||||
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);
|
||||
throw new Error(`Expected 200, got back ${context.res.statusCode} instead.\n\n${message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user