Skip to content

Commit

Permalink
concurrent requests for acl and meta resources on list all
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexagod committed Jan 6, 2025
1 parent 34ea7f6 commit 040e56b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/commands/solid-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,29 @@ export default async function list(url: string, options?: ICommandOptionsList) {
if(resourceInfo) resourceInfos.push(resourceInfo)
}
}

const promiseList: Promise<ResourceInfo>[] = [];
for (let containedResourceUrl of containedResources) {
let resourceInfo = getResourceInfoFromDataset(dataset, containedResourceUrl, url);
if (resourceInfo && !resourceInfo.isDir && commandOptions.all) { // We only want to show acl files in the current dir. Aka the ones of the current dir + the ones of contained files
const headerResources = await getAclAndMetadata(containedResourceUrl, url, commandOptions.fetch)
if (headerResources.acl) {
resourceInfo.acl = headerResources.acl
resourceInfos.push(headerResources.acl)
}
if (headerResources.meta) {
resourceInfo.metadata = headerResources.meta
resourceInfos.push(headerResources.meta)
promiseList.push(new Promise((resolve, reject) => {
let resourceInfo = getResourceInfoFromDataset(dataset, containedResourceUrl, url);
if (resourceInfo && !resourceInfo.isDir && commandOptions.all) { // We only want to show acl files in the current dir. Aka the ones of the current dir + the ones of contained files
getAclAndMetadata(containedResourceUrl, url, commandOptions.fetch)
.then((headerResources) => {
if (headerResources.acl) resourceInfo.acl = headerResources.acl
if (headerResources.meta) resourceInfo.metadata = headerResources.meta
resolve(resourceInfo);
})
} else {
resolve(resourceInfo);
}
}
if (resourceInfo) resourceInfos.push(resourceInfo)
}))
}

const metadataResourceInfoList = (await Promise.all(promiseList)).filter((e) => !!e)
resourceInfos = resourceInfos.concat(metadataResourceInfoList)
metadataResourceInfoList.forEach( (resourceInfo: ResourceInfo) => {
if(resourceInfo.acl) resourceInfos.push(resourceInfo.acl)
if(resourceInfo.metadata) resourceInfos.push(resourceInfo.metadata)
});
return resourceInfos

}
1 change: 1 addition & 0 deletions src/commands/solid-perms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function listPermissions(resourceUrl: string, options?: ICommandOpt
try {
permissions.access.agent = await universalAccess.getAgentAccessAll(resourceUrl, {fetch: commandOptions.fetch})
permissions.access.public = await universalAccess.getPublicAccess(resourceUrl, {fetch: commandOptions.fetch})
console.log('PERMISSIONS', permissions)
return permissions
} catch (e) {
if (commandOptions.verbose) writeErrorString(`Could not retrieve permissions for ${resourceUrl}`, e, commandOptions)
Expand Down

0 comments on commit 040e56b

Please sign in to comment.