提交 7b926ed9 编写于 作者: S Sandeep Somavarapu

Implement download service using request service

上级 9f492373
......@@ -8,13 +8,31 @@
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IDownloadService } from 'vs/platform/download/common/download';
import { IRequestService } from 'vs/platform/request/node/request';
import { Schemas } from 'vs/base/common/network';
import { copy } from 'vs/base/node/pfs';
import { download, asText } from 'vs/base/node/request';
export class DownloadService implements IDownloadService {
_serviceBrand: any;
constructor(
@IRequestService private requestService: IRequestService
) { }
download(from: URI, to: string): TPromise<void> {
throw new Error('Not supported');
if (from.scheme === Schemas.file) {
return copy(from.fsPath, to);
}
return this.requestService.request({ url: from.path })
.then(context => {
if (context.res.statusCode === 200) {
return download(to, context);
}
return asText(context)
.then(message => TPromise.wrapError(new Error(`Expected 200, got back ${context.res.statusCode} instead.\n\n${message}`)));
});
}
}
\ No newline at end of file
......@@ -97,6 +97,8 @@ import { SearchHistoryService } from 'vs/workbench/services/search/node/searchHi
import { MulitExtensionManagementService } from 'vs/platform/extensionManagement/common/multiExtensionManagement';
import { ExtensionManagementServerService } from 'vs/workbench/services/extensions/node/extensionManagementServerService';
import { DownloadServiceChannel } from 'vs/platform/download/node/downloadIpc';
import { IDownloadService } from 'vs/platform/download/common/download';
import { DownloadService } from 'vs/platform/download/node/downloadService';
/**
* Services that we require for the Shell
......@@ -389,6 +391,7 @@ export class WorkbenchShell extends Disposable {
serviceCollection.set(IExtensionEnablementService, extensionEnablementService);
serviceCollection.set(IRequestService, new SyncDescriptor(RequestService));
serviceCollection.set(IDownloadService, new SyncDescriptor(DownloadService));
this.extensionService = instantiationService.createInstance(ExtensionService);
serviceCollection.set(IExtensionService, this.extensionService);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册