fix(plugin): remediate ML-07 R2 findings
This commit is contained in:
@@ -84,14 +84,17 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
|
||||
});
|
||||
},
|
||||
setEnabled(projectId, pluginId, enabled) {
|
||||
const generation = loadGeneration;
|
||||
return operation(`enabled:${projectId}:${pluginId}`, async () => {
|
||||
const projection = await deps.setEnabled(projectId, pluginId, enabled);
|
||||
let dataService = get().projectId === projectId ? get().dataService : null;
|
||||
if (generation !== loadGeneration || get().projectId !== projectId) return;
|
||||
let dataService = get().dataService;
|
||||
const item = projection.items.find(({ id }) => id === pluginId);
|
||||
if (!enabled) {
|
||||
dataService = null;
|
||||
} else if (item?.settingsSurface === 'data-service' && item.backend.status === 'ready') {
|
||||
const inspected = await deps.inspectDataService();
|
||||
if (generation !== loadGeneration || get().projectId !== projectId) return;
|
||||
if (inspected.success && inspected.data) dataService = inspected.data;
|
||||
}
|
||||
set({
|
||||
@@ -100,34 +103,47 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
|
||||
});
|
||||
},
|
||||
configure(collections) {
|
||||
const projectId = get().projectId;
|
||||
const generation = loadGeneration;
|
||||
return operation('data-service:configure', async () => {
|
||||
const result = await deps.configureDataService(collections);
|
||||
if (!result.success || !result.data) throw new Error(result.error || '开发数据空间创建失败');
|
||||
if (generation !== loadGeneration || get().projectId !== projectId) return;
|
||||
set({ dataService: result.data, error: null });
|
||||
if (get().projectId) await get().load(get().projectId as string);
|
||||
if (projectId) await get().load(projectId);
|
||||
});
|
||||
},
|
||||
reset() {
|
||||
const projectId = get().projectId;
|
||||
const generation = loadGeneration;
|
||||
return operation('data-service:reset', async () => {
|
||||
const result = await deps.resetDataService();
|
||||
if (!result.success || !result.data) throw new Error(result.error || '开发数据重置失败');
|
||||
if (generation !== loadGeneration || get().projectId !== projectId) return;
|
||||
set({ dataService: result.data });
|
||||
});
|
||||
},
|
||||
removeCollection(collection) {
|
||||
const projectId = get().projectId;
|
||||
const generation = loadGeneration;
|
||||
return operation(`data-service:collection:${collection}`, async () => {
|
||||
const result = await deps.removeCollection(collection);
|
||||
if (!result.success) throw new Error(result.error || '移除 collection 失败');
|
||||
if (generation !== loadGeneration || get().projectId !== projectId) return;
|
||||
const inspected = await deps.inspectDataService();
|
||||
if (generation !== loadGeneration || get().projectId !== projectId) return;
|
||||
if (inspected.success && inspected.data) set({ dataService: inspected.data });
|
||||
});
|
||||
},
|
||||
removeProject() {
|
||||
const projectId = get().projectId;
|
||||
const generation = loadGeneration;
|
||||
return operation('data-service:remove-project', async () => {
|
||||
const result = await deps.removeProject();
|
||||
if (!result.success) throw new Error(result.error || '删除开发数据空间失败');
|
||||
if (generation !== loadGeneration || get().projectId !== projectId) return;
|
||||
set({ dataService: null });
|
||||
if (get().projectId) await get().load(get().projectId as string);
|
||||
if (projectId) await get().load(projectId);
|
||||
});
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user