diff --git a/controller/src/classes/Controller.ts b/controller/src/classes/Controller.ts index 5b2d343..753ddd9 100644 --- a/controller/src/classes/Controller.ts +++ b/controller/src/classes/Controller.ts @@ -195,15 +195,33 @@ export class Controller> const configs: SubjectConfig[] = Object.values(this.subjectConfigs); const index = await this.store.getCurrentIndex(); - const resourcesToSkip = index.items.filter(i => i.resource.includes(containerUrl)); + const resourcesToSkip = index.items.filter(i => { + if (!i.resource.includes(containerUrl)) { + return false; + } + const strippedURI = i.resource.replace(containerUrl, ""); + const slashIdx = strippedURI.indexOf("/"); + if (slashIdx < 0) { + return true; + } + return !strippedURI.includes("/", slashIdx + 1) + }); const results = await Promise.allSettled(configs.map(c => c.manager.getContainerPermissionList(containerUrl, resourcesToSkip.map(i => i.resource)))) + const resourcesToClean = resourcesToSkip.filter(r => r.isEnabled).map(r => r.resource); if (results.length !== 0) { index.items.push(...results.reduce]>[]>((arr, v) => { if (v.status === "fulfilled") { // Check if the resourceUrl is already present before pushing it into the array v.value.forEach((r) => { + for (let i = 0; i < resourcesToClean.length; i++) { + const rtc = resourcesToClean[i]; + if (r.resourceUrl.includes(rtc)) { + resourcesToClean.splice(i, 1); + i--; + } + } // @ts-expect-error arr.push(...r.permissionsPerSubject.map(p => ({ id: crypto.randomUUID(), @@ -217,10 +235,19 @@ export class Controller> } return arr; }, [])); - - await this.store.saveToRemoteIndex(); } + await Promise.allSettled(resourcesToClean.map(async r => { + for (let i = 0; i < index.items.length; i++) { + let entry = index.items[i]; + if (!entry.resource.includes(r)) { + continue + } + index.items.splice(i, 1); + } + })); + + await this.store.saveToRemoteIndex(); return index.items.reduce[]>((arr, v) => { const resourcePath = v.resource.replace(containerUrl, ""); diff --git a/controller/src/classes/permissionManager/inrupt/InruptPermissionManager.ts b/controller/src/classes/permissionManager/inrupt/InruptPermissionManager.ts index e063dc4..1d9bf12 100644 --- a/controller/src/classes/permissionManager/inrupt/InruptPermissionManager.ts +++ b/controller/src/classes/permissionManager/inrupt/InruptPermissionManager.ts @@ -83,11 +83,18 @@ export abstract class InruptPermissionManager !resourceToSkip?.includes(r.url)) - .map(async (resource) => ({ - resourceUrl: resource.url, - permissionsPerSubject: await this.getRemotePermissions(resource.url) - })) + .map(async (resource) => { + if (resourceToSkip.includes(resource.url)) { + return { + resourceUrl: resource.url, + permissionsPerSubject: [], + } + } + return { + resourceUrl: resource.url, + permissionsPerSubject: await this.getRemotePermissions(resource.url) + } + }) ) return results.reduce[]>((arr, v) => { if (v.status == "fulfilled") { diff --git a/controller/src/types/modules.ts b/controller/src/types/modules.ts index 47d3019..f299986 100644 --- a/controller/src/types/modules.ts +++ b/controller/src/types/modules.ts @@ -77,7 +77,9 @@ export interface IPermissionManager>> { deletePermissions>(resource: string, subject: T[K]): Promise getRemotePermissions>(resourceUrl: string): Promise[]> /** - * Retrieve the permissions of the resources in this container. + * Retrieve the permissions of the resources in this container. + * It will add the skipped resources to the returning object but without the permissions assignments. + * As this is necessary to clean-up the index * Will probably work for a resource, but not guaranteed. Use getRemotePermissions for that */ getContainerPermissionList(containerUrl: string, resourceToSkip?: string[]): Promise[]>