#85619 Enable following
- getting all refs - resolving content for a ref - deleting a resource
This commit is contained in:
parent
014ddafc91
commit
36141fa1f3
6 changed files with 141 additions and 6 deletions
|
@ -52,7 +52,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
|
|||
import { IUserDataSyncService, IUserDataSyncStoreService, registerConfiguration, IUserDataSyncLogService, IUserDataSyncUtilService, ISettingsSyncService, IUserDataSyncEnablementService } from 'vs/platform/userDataSync/common/userDataSync';
|
||||
import { UserDataSyncService } from 'vs/platform/userDataSync/common/userDataSyncService';
|
||||
import { UserDataSyncStoreService } from 'vs/platform/userDataSync/common/userDataSyncStoreService';
|
||||
import { UserDataSyncChannel, UserDataSyncUtilServiceClient, SettingsSyncChannel, UserDataAutoSyncChannel } from 'vs/platform/userDataSync/common/userDataSyncIpc';
|
||||
import { UserDataSyncChannel, UserDataSyncUtilServiceClient, SettingsSyncChannel, UserDataAutoSyncChannel, UserDataSyncStoreServiceChannel } from 'vs/platform/userDataSync/common/userDataSyncIpc';
|
||||
import { IElectronService } from 'vs/platform/electron/node/electron';
|
||||
import { LoggerService } from 'vs/platform/log/node/loggerService';
|
||||
import { UserDataSyncLogService } from 'vs/platform/userDataSync/common/userDataSyncLog';
|
||||
|
@ -219,6 +219,10 @@ async function main(server: Server, initData: ISharedProcessInitData, configurat
|
|||
const authTokenChannel = new AuthenticationTokenServiceChannel(authTokenService);
|
||||
server.registerChannel('authToken', authTokenChannel);
|
||||
|
||||
const userDataSyncStoreService = accessor.get(IUserDataSyncStoreService);
|
||||
const userDataSyncStoreServiceChannel = new UserDataSyncStoreServiceChannel(userDataSyncStoreService);
|
||||
server.registerChannel('userDataSyncStoreService', userDataSyncStoreServiceChannel);
|
||||
|
||||
const settingsSyncService = accessor.get(ISettingsSyncService);
|
||||
const settingsSyncChannel = new SettingsSyncChannel(settingsSyncService);
|
||||
server.registerChannel('settingsSync', settingsSyncChannel);
|
||||
|
|
|
@ -151,6 +151,9 @@ export interface IUserDataSyncStoreService {
|
|||
write(key: ResourceKey, content: string, ref: string | null, source?: SyncSource): Promise<string>;
|
||||
manifest(): Promise<IUserDataManifest | null>;
|
||||
clear(): Promise<void>;
|
||||
getAllRefs(key: ResourceKey): Promise<string[]>;
|
||||
resolveContent(key: ResourceKey, ref: string): Promise<string | null>;
|
||||
delete(key: ResourceKey): Promise<void>;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { IServerChannel, IChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IUserDataSyncService, IUserDataSyncUtilService, ISettingsSyncService, IUserDataAutoSyncService } from 'vs/platform/userDataSync/common/userDataSync';
|
||||
import { IUserDataSyncService, IUserDataSyncUtilService, ISettingsSyncService, IUserDataAutoSyncService, IUserDataSyncStoreService } from 'vs/platform/userDataSync/common/userDataSync';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IStringDictionary } from 'vs/base/common/collections';
|
||||
import { FormattingOptions } from 'vs/base/common/jsonFormatter';
|
||||
|
@ -131,3 +131,20 @@ export class UserDataSyncUtilServiceClient implements IUserDataSyncUtilService {
|
|||
|
||||
}
|
||||
|
||||
export class UserDataSyncStoreServiceChannel implements IServerChannel {
|
||||
|
||||
constructor(private readonly service: IUserDataSyncStoreService) { }
|
||||
|
||||
listen(_: unknown, event: string): Event<any> {
|
||||
throw new Error(`Event not found: ${event}`);
|
||||
}
|
||||
|
||||
call(context: any, command: string, args?: any): Promise<any> {
|
||||
switch (command) {
|
||||
case 'getAllRefs': return this.service.getAllRefs(args[0]);
|
||||
case 'resolveContent': return this.service.resolveContent(args[0], args[1]);
|
||||
case 'delete': return this.service.delete(args[0]);
|
||||
}
|
||||
throw new Error('Invalid call');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Disposable, } from 'vs/base/common/lifecycle';
|
||||
import { IUserData, IUserDataSyncStoreService, UserDataSyncErrorCode, IUserDataSyncStore, getUserDataSyncStore, SyncSource, UserDataSyncStoreError, IUserDataSyncLogService, IUserDataManifest } from 'vs/platform/userDataSync/common/userDataSync';
|
||||
import { IUserData, IUserDataSyncStoreService, UserDataSyncErrorCode, IUserDataSyncStore, getUserDataSyncStore, SyncSource, UserDataSyncStoreError, IUserDataSyncLogService, IUserDataManifest, ResourceKey } from 'vs/platform/userDataSync/common/userDataSync';
|
||||
import { IRequestService, asText, isSuccess, asJson } from 'vs/platform/request/common/request';
|
||||
import { joinPath } from 'vs/base/common/resources';
|
||||
import { joinPath, relativePath } from 'vs/base/common/resources';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { IHeaders, IRequestOptions, IRequestContext } from 'vs/base/parts/request/common/request';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IAuthenticationTokenService } from 'vs/platform/authentication/common/authentication';
|
||||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
export class UserDataSyncStoreService extends Disposable implements IUserDataSyncStoreService {
|
||||
|
||||
|
@ -30,7 +31,58 @@ export class UserDataSyncStoreService extends Disposable implements IUserDataSyn
|
|||
this.userDataSyncStore = getUserDataSyncStore(productService, configurationService);
|
||||
}
|
||||
|
||||
async read(key: string, oldValue: IUserData | null, source?: SyncSource): Promise<IUserData> {
|
||||
async getAllRefs(key: ResourceKey): Promise<string[]> {
|
||||
if (!this.userDataSyncStore) {
|
||||
throw new Error('No settings sync store url configured.');
|
||||
}
|
||||
|
||||
const uri = joinPath(this.userDataSyncStore.url, 'resource', key);
|
||||
const headers: IHeaders = {};
|
||||
|
||||
const context = await this.request({ type: 'GET', url: uri.toString(), headers }, undefined, CancellationToken.None);
|
||||
|
||||
if (!isSuccess(context)) {
|
||||
throw new UserDataSyncStoreError('Server returned ' + context.res.statusCode, UserDataSyncErrorCode.Unknown, undefined);
|
||||
}
|
||||
|
||||
const resources: string[] = await asJson<string[]>(context) || [];
|
||||
return resources.map(resource => relativePath(uri, URI.parse(resource))!);
|
||||
}
|
||||
|
||||
async resolveContent(key: ResourceKey, ref: string): Promise<string | null> {
|
||||
if (!this.userDataSyncStore) {
|
||||
throw new Error('No settings sync store url configured.');
|
||||
}
|
||||
|
||||
const url = joinPath(this.userDataSyncStore.url, 'resource', key, ref).toString();
|
||||
const headers: IHeaders = {};
|
||||
|
||||
const context = await this.request({ type: 'GET', url, headers }, undefined, CancellationToken.None);
|
||||
|
||||
if (!isSuccess(context)) {
|
||||
throw new UserDataSyncStoreError('Server returned ' + context.res.statusCode, UserDataSyncErrorCode.Unknown, undefined);
|
||||
}
|
||||
|
||||
const content = await asText(context);
|
||||
return content;
|
||||
}
|
||||
|
||||
async delete(key: ResourceKey): Promise<void> {
|
||||
if (!this.userDataSyncStore) {
|
||||
throw new Error('No settings sync store url configured.');
|
||||
}
|
||||
|
||||
const url = joinPath(this.userDataSyncStore.url, 'resource', key).toString();
|
||||
const headers: IHeaders = {};
|
||||
|
||||
const context = await this.request({ type: 'DELETE', url, headers }, undefined, CancellationToken.None);
|
||||
|
||||
if (!isSuccess(context)) {
|
||||
throw new UserDataSyncStoreError('Server returned ' + context.res.statusCode, UserDataSyncErrorCode.Unknown, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
async read(key: ResourceKey, oldValue: IUserData | null, source?: SyncSource): Promise<IUserData> {
|
||||
if (!this.userDataSyncStore) {
|
||||
throw new Error('No settings sync store url configured.');
|
||||
}
|
||||
|
@ -62,7 +114,7 @@ export class UserDataSyncStoreService extends Disposable implements IUserDataSyn
|
|||
return { ref, content };
|
||||
}
|
||||
|
||||
async write(key: string, data: string, ref: string | null, source?: SyncSource): Promise<string> {
|
||||
async write(key: ResourceKey, data: string, ref: string | null, source?: SyncSource): Promise<string> {
|
||||
if (!this.userDataSyncStore) {
|
||||
throw new Error('No settings sync store url configured.');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { SyncSource, IUserDataSyncStoreService, IUserDataSyncStore, getUserDataSyncStore, ResourceKey, IUserData, IUserDataManifest } from 'vs/platform/userDataSync/common/userDataSync';
|
||||
import { ISharedProcessService } from 'vs/platform/ipc/electron-browser/sharedProcessService';
|
||||
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
|
||||
export class UserDataSyncStoreService implements IUserDataSyncStoreService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
private readonly channel: IChannel;
|
||||
readonly userDataSyncStore: IUserDataSyncStore | undefined;
|
||||
|
||||
constructor(
|
||||
@ISharedProcessService sharedProcessService: ISharedProcessService,
|
||||
@IProductService productService: IProductService,
|
||||
@IConfigurationService configurationService: IConfigurationService
|
||||
) {
|
||||
this.channel = sharedProcessService.getChannel('userDataSyncStoreService');
|
||||
this.userDataSyncStore = getUserDataSyncStore(productService, configurationService);
|
||||
}
|
||||
|
||||
read(key: ResourceKey, oldValue: IUserData | null, source?: SyncSource): Promise<IUserData> {
|
||||
throw new Error('Not Supported');
|
||||
}
|
||||
|
||||
write(key: ResourceKey, content: string, ref: string | null, source?: SyncSource): Promise<string> {
|
||||
throw new Error('Not Supported');
|
||||
}
|
||||
|
||||
manifest(): Promise<IUserDataManifest | null> {
|
||||
throw new Error('Not Supported');
|
||||
}
|
||||
|
||||
clear(): Promise<void> {
|
||||
throw new Error('Not Supported');
|
||||
}
|
||||
|
||||
getAllRefs(key: ResourceKey): Promise<string[]> {
|
||||
return this.channel.call('getAllRefs', [key]);
|
||||
}
|
||||
|
||||
resolveContent(key: ResourceKey, ref: string): Promise<string | null> {
|
||||
return this.channel.call('resolveContent', [key, ref]);
|
||||
}
|
||||
|
||||
delete(key: ResourceKey): Promise<void> {
|
||||
return this.channel.call('delete', [key]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerSingleton(IUserDataSyncStoreService, UserDataSyncStoreService);
|
|
@ -52,6 +52,7 @@ import 'vs/workbench/services/workspaces/electron-browser/workspaceEditingServic
|
|||
import 'vs/workbench/services/userDataSync/electron-browser/userDataSyncService';
|
||||
import 'vs/workbench/services/userDataSync/electron-browser/settingsSyncService';
|
||||
import 'vs/workbench/services/userDataSync/electron-browser/userDataAutoSyncService';
|
||||
import 'vs/workbench/services/userDataSync/electron-browser/userDataSyncStoreService';
|
||||
import 'vs/workbench/services/authentication/electron-browser/authenticationTokenService';
|
||||
import 'vs/workbench/services/authentication/browser/authenticationService';
|
||||
import 'vs/workbench/services/host/electron-browser/desktopHostService';
|
||||
|
|
Loading…
Reference in a new issue