mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
add machine id header
This commit is contained in:
@@ -8,14 +8,28 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
|
||||
import { FileAccess, Schemas } from 'vs/base/common/network';
|
||||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { IHeaders } from 'vs/base/parts/request/common/request';
|
||||
import { getServiceMachineId } from 'vs/platform/serviceMachineId/common/serviceMachineId';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
|
||||
class ExtensionResourceLoaderService implements IExtensionResourceLoaderService {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
private readonly _extensionGalleryResourceAuthority: string | undefined;
|
||||
|
||||
constructor(
|
||||
@IFileService private readonly _fileService: IFileService
|
||||
) { }
|
||||
@IFileService private readonly _fileService: IFileService,
|
||||
@IProductService productService: IProductService,
|
||||
@IStorageService private readonly _storageService: IStorageService,
|
||||
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
|
||||
) {
|
||||
if (productService.extensionsGallery) {
|
||||
this._extensionGalleryResourceAuthority = this._getExtensionResourceAuthority(URI.parse(productService.extensionsGallery.resourceUrlTemplate));
|
||||
}
|
||||
}
|
||||
|
||||
async readExtensionResource(uri: URI): Promise<string> {
|
||||
uri = FileAccess.asBrowserUri(uri);
|
||||
@@ -25,13 +39,32 @@ class ExtensionResourceLoaderService implements IExtensionResourceLoaderService
|
||||
return result.value.toString();
|
||||
}
|
||||
|
||||
const response = await fetch(uri.toString(true));
|
||||
let headers: IHeaders = {};
|
||||
if (this._extensionGalleryResourceAuthority && this._extensionGalleryResourceAuthority === this._getExtensionResourceAuthority(uri)) {
|
||||
const machineId = await this._getServiceMachineId();
|
||||
headers['X-Machine-Id'] = machineId;
|
||||
}
|
||||
|
||||
const response = await fetch(uri.toString(true), { headers });
|
||||
if (response.status !== 200) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
return response.text();
|
||||
|
||||
}
|
||||
|
||||
private _serviceMachineIdPromise: Promise<string> | undefined;
|
||||
private _getServiceMachineId(): Promise<string> {
|
||||
if (!this._serviceMachineIdPromise) {
|
||||
this._serviceMachineIdPromise = getServiceMachineId(this._environmentService, this._fileService, this._storageService);
|
||||
}
|
||||
return this._serviceMachineIdPromise;
|
||||
}
|
||||
|
||||
private _getExtensionResourceAuthority(uri: URI): string | undefined {
|
||||
const index = uri.authority.indexOf('.');
|
||||
return index !== -1 ? uri.authority.substring(index + 1) : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IExtensionResourceLoaderService, ExtensionResourceLoaderService);
|
||||
|
||||
Reference in New Issue
Block a user