Skip to content

Commit

Permalink
feat(gql): use wallet for owner_address when available for public l…
Browse files Browse the repository at this point in the history
…ist commands PE-6232
  • Loading branch information
fedellen committed Jun 3, 2024
1 parent fca36b1 commit bd21f97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/commands/list_drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,26 @@ new CLICommand({
const rootFolderId = drive.rootFolderId;
const withKeys = await parameters.getParameterValue(WithKeysParameter, (value) => !!value);

// We have the drive id from deriving a key, we can derive the owner
const driveOwner = await arDrive.getOwnerForDriveId(driveId);

children = await arDrive.listPrivateFolder({
folderId: rootFolderId,
driveKey,
maxDepth,
includeRoot: true,
owner: driveOwner,
owner: await wallet.getAddress(),
withKeys
});
} else {
const arDrive = cliArDriveAnonymousFactory({ arweave });
const drive = await arDrive.getPublicDrive({ driveId });

// Use wallet for owner if available to improve GQL query performance
const owner = (await (await parameters.getOptionalWallet())?.getAddress()) ?? undefined;

const drive = await arDrive.getPublicDrive({
driveId,
owner
});
const rootFolderId = drive.rootFolderId;
children = await arDrive.listPublicFolder({ folderId: rootFolderId, maxDepth, includeRoot: true });
children = await arDrive.listPublicFolder({ folderId: rootFolderId, maxDepth, includeRoot: true, owner });
}

const sortedChildren = children.sort((a, b) => alphabeticalOrder(a.path, b.path)) as (
Expand Down
18 changes: 13 additions & 5 deletions src/commands/list_folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,21 @@ new CLICommand({
const driveKey = await parameters.getDriveKey({ driveId });
const withKeys = await parameters.getParameterValue(WithKeysParameter, (value) => !!value);

// We have the drive id from deriving a key, we can derive the owner
const driveOwner = await arDrive.getOwnerForDriveId(driveId);

children = await arDrive.listPrivateFolder({ folderId, driveKey, maxDepth, owner: driveOwner, withKeys });
children = await arDrive.listPrivateFolder({
folderId,
driveKey,
maxDepth,
owner: await wallet.getAddress(),
withKeys
});
} else {
const arDrive = cliArDriveAnonymousFactory({ arweave });
children = await arDrive.listPublicFolder({ folderId, maxDepth });
children = await arDrive.listPublicFolder({
folderId,
maxDepth,
// Use wallet for owner if available to improve GQL query performance
owner: await (await parameters.getOptionalWallet())?.getAddress()
});
}

const sortedChildren = children.sort((a, b) => alphabeticalOrder(a.path, b.path)) as (
Expand Down

0 comments on commit bd21f97

Please sign in to comment.