Skip to content

Commit

Permalink
Merge pull request #128 from ardriveapp/dev
Browse files Browse the repository at this point in the history
Merge dev into master for v1.0.1 PE-649
  • Loading branch information
fedellen authored Nov 1, 2021
2 parents 1985578 + e719600 commit 67a6385
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ardrive-cli",
"version": "1.0.0",
"version": "1.0.1",
"description": "The ArDrive Command Line Interface (CLI is a Node.js application for terminal-based ArDrive workflows. It also offers utility operations for securely interacting with Arweave wallets and inspecting various Arweave blockchain conditions.",
"main": "./lib/index.js",
"bin": {
Expand Down
6 changes: 4 additions & 2 deletions src/ardrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ export class ArDrive extends ArDriveAnonymous {

const childrenFolderIds = await this.arFsDao.getPublicChildrenFolderIds({
folderId,
driveId: destFolderDriveId
driveId: destFolderDriveId,
owner
});

if (childrenFolderIds.includes(newParentFolderId)) {
Expand Down Expand Up @@ -438,7 +439,8 @@ export class ArDrive extends ArDriveAnonymous {
const childrenFolderIds = await this.arFsDao.getPrivateChildrenFolderIds({
folderId,
driveId: destFolderDriveId,
driveKey
driveKey,
owner
});

if (childrenFolderIds.includes(newParentFolderId)) {
Expand Down
59 changes: 45 additions & 14 deletions src/arfsdao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ import {
ArFSUploadPrivateFileResult,
ArFSCreateDriveResultFactory,
ArFSMoveEntityResultFactory,
ArFSUploadFileResultFactory
ArFSUploadFileResultFactory,
WithDriveKey
} from './arfs_entity_result_factory';
import {
ArFSFileOrFolderEntity,
Expand All @@ -82,7 +83,7 @@ import {
ArFSPublicFile,
ArFSPublicFolder
} from './arfs_entities';
import { ArFSDAOAnonymous } from './arfsdao_anonymous';
import { ArFSAllPublicFoldersOfDriveParams, ArFSDAOAnonymous } from './arfsdao_anonymous';
import { ArFSFileOrFolderBuilder } from './utils/arfs_builders/arfs_builders';
import { PrivateKeyData } from './private_key_data';
import { ArweaveAddress } from './arweave_address';
Expand Down Expand Up @@ -127,6 +128,9 @@ export interface UploadPublicFileParams {
export interface UploadPrivateFileParams extends UploadPublicFileParams {
driveKey: DriveKey;
}

export type ArFSAllPrivateFoldersOfDriveParams = ArFSAllPublicFoldersOfDriveParams & WithDriveKey;

export interface CreateFolderSettings {
driveId: DriveID;
rewardSettings: RewardSettings;
Expand All @@ -147,6 +151,7 @@ export interface CreatePrivateFolderSettings extends CreateFolderSettings {
interface getPublicChildrenFolderIdsParams {
folderId: FolderID;
driveId: DriveID;
owner: ArweaveAddress;
}
interface getPrivateChildrenFolderIdsParams extends getPublicChildrenFolderIdsParams {
driveKey: DriveKey;
Expand Down Expand Up @@ -688,11 +693,12 @@ export class ArFSDAO extends ArFSDAOAnonymous {
return new ArFSPrivateFileBuilder(fileId, this.arweave, driveKey, owner).build();
}

async getAllFoldersOfPrivateDrive(
driveId: DriveID,
driveKey: DriveKey,
async getAllFoldersOfPrivateDrive({
driveId,
driveKey,
owner,
latestRevisionsOnly = false
): Promise<ArFSPrivateFolder[]> {
}: ArFSAllPrivateFoldersOfDriveParams): Promise<ArFSPrivateFolder[]> {
let cursor = '';
let hasNextPage = true;
const allFolders: ArFSPrivateFolder[] = [];
Expand All @@ -703,7 +709,8 @@ export class ArFSDAO extends ArFSDAOAnonymous {
{ name: 'Drive-Id', value: driveId },
{ name: 'Entity-Type', value: 'folder' }
],
cursor
cursor,
owner
});

const response = await this.arweave.api.post(graphQLURL, gqlQuery);
Expand All @@ -726,6 +733,7 @@ export class ArFSDAO extends ArFSDAOAnonymous {
async getPrivateFilesWithParentFolderIds(
folderIDs: FolderID[],
driveKey: DriveKey,
owner: ArweaveAddress,
latestRevisionsOnly = false
): Promise<ArFSPrivateFile[]> {
let cursor = '';
Expand All @@ -738,7 +746,8 @@ export class ArFSDAO extends ArFSDAOAnonymous {
{ name: 'Parent-Folder-Id', value: folderIDs },
{ name: 'Entity-Type', value: 'file' }
],
cursor
cursor,
owner
});

const response = await this.arweave.api.post(graphQLURL, gqlQuery);
Expand Down Expand Up @@ -874,12 +883,24 @@ export class ArFSDAO extends ArFSDAOAnonymous {
async getPrivateChildrenFolderIds({
folderId,
driveId,
driveKey
driveKey,
owner
}: getPrivateChildrenFolderIdsParams): Promise<FolderID[]> {
return this.getChildrenFolderIds(folderId, await this.getAllFoldersOfPrivateDrive(driveId, driveKey, true));
return this.getChildrenFolderIds(
folderId,
await this.getAllFoldersOfPrivateDrive({ driveId, driveKey, owner, latestRevisionsOnly: true })
);
}
async getPublicChildrenFolderIds({ folderId, driveId }: getPublicChildrenFolderIdsParams): Promise<FolderID[]> {
return this.getChildrenFolderIds(folderId, await this.getAllFoldersOfPublicDrive(driveId, true));

async getPublicChildrenFolderIds({
folderId,
owner,
driveId
}: getPublicChildrenFolderIdsParams): Promise<FolderID[]> {
return this.getChildrenFolderIds(
folderId,
await this.getAllFoldersOfPublicDrive({ driveId, owner, latestRevisionsOnly: true })
);
}

/**
Expand All @@ -905,7 +926,12 @@ export class ArFSDAO extends ArFSDAOAnonymous {

// Fetch all of the folder entities within the drive
const driveIdOfFolder = folder.driveId;
const allFolderEntitiesOfDrive = await this.getAllFoldersOfPrivateDrive(driveIdOfFolder, driveKey, true);
const allFolderEntitiesOfDrive = await this.getAllFoldersOfPrivateDrive({
driveId: driveIdOfFolder,
driveKey,
owner,
latestRevisionsOnly: true
});

const hierarchy = FolderHierarchy.newFromEntities(allFolderEntitiesOfDrive);
const searchFolderIDs = hierarchy.folderIdSubtreeFromFolderId(folderId, maxDepth - 1);
Expand All @@ -920,7 +946,12 @@ export class ArFSDAO extends ArFSDAOAnonymous {
}

// Fetch all file entities within all Folders of the drive
const childrenFileEntities = await this.getPrivateFilesWithParentFolderIds(searchFolderIDs, driveKey, true);
const childrenFileEntities = await this.getPrivateFilesWithParentFolderIds(
searchFolderIDs,
driveKey,
owner,
true
);

const children = [...childrenFolderEntities, ...childrenFileEntities];

Expand Down
28 changes: 23 additions & 5 deletions src/arfsdao_anonymous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { ArweaveAddress } from './arweave_address';

export const graphQLURL = 'https://arweave.net/graphql';

export interface ArFSAllPublicFoldersOfDriveParams {
driveId: DriveID;
owner: ArweaveAddress;
latestRevisionsOnly: boolean;
}

export interface ArFSListPublicFolderParams {
folderId: FolderID;
maxDepth: number;
Expand Down Expand Up @@ -140,6 +146,7 @@ export class ArFSDAOAnonymous extends ArFSDAOType {

async getPublicFilesWithParentFolderIds(
folderIDs: FolderID[],
owner: ArweaveAddress,
latestRevisionsOnly = false
): Promise<ArFSPublicFile[]> {
let cursor = '';
Expand All @@ -152,7 +159,8 @@ export class ArFSDAOAnonymous extends ArFSDAOType {
{ name: 'Parent-Folder-Id', value: folderIDs },
{ name: 'Entity-Type', value: 'file' }
],
cursor
cursor,
owner
});

const response = await this.arweave.api.post(graphQLURL, gqlQuery);
Expand All @@ -171,7 +179,11 @@ export class ArFSDAOAnonymous extends ArFSDAOType {
return latestRevisionsOnly ? allFiles.filter(latestRevisionFilter) : allFiles;
}

async getAllFoldersOfPublicDrive(driveId: DriveID, latestRevisionsOnly = false): Promise<ArFSPublicFolder[]> {
async getAllFoldersOfPublicDrive({
driveId,
owner,
latestRevisionsOnly = false
}: ArFSAllPublicFoldersOfDriveParams): Promise<ArFSPublicFolder[]> {
let cursor = '';
let hasNextPage = true;
const allFolders: ArFSPublicFolder[] = [];
Expand All @@ -182,13 +194,15 @@ export class ArFSDAOAnonymous extends ArFSDAOType {
{ name: 'Drive-Id', value: driveId },
{ name: 'Entity-Type', value: 'folder' }
],
cursor
cursor,
owner
});

const response = await this.arweave.api.post(graphQLURL, gqlQuery);
const { data } = response.data;
const { transactions } = data;
const { edges } = transactions;

hasNextPage = transactions.pageInfo.hasNextPage;
const folders: Promise<ArFSPublicFolder>[] = edges.map(async (edge: GQLEdgeInterface) => {
const { node } = edge;
Expand Down Expand Up @@ -222,7 +236,11 @@ export class ArFSDAOAnonymous extends ArFSDAOType {

// Fetch all of the folder entities within the drive
const driveIdOfFolder = folder.driveId;
const allFolderEntitiesOfDrive = await this.getAllFoldersOfPublicDrive(driveIdOfFolder, true);
const allFolderEntitiesOfDrive = await this.getAllFoldersOfPublicDrive({
driveId: driveIdOfFolder,
owner,
latestRevisionsOnly: true
});

// Feed entities to FolderHierarchy
const hierarchy = FolderHierarchy.newFromEntities(allFolderEntitiesOfDrive);
Expand All @@ -238,7 +256,7 @@ export class ArFSDAOAnonymous extends ArFSDAOType {
}

// Fetch all file entities within all Folders of the drive
const childrenFileEntities = await this.getPublicFilesWithParentFolderIds(searchFolderIDs, true);
const childrenFileEntities = await this.getPublicFilesWithParentFolderIds(searchFolderIDs, owner, true);

const children = [...childrenFolderEntities, ...childrenFileEntities];

Expand Down

0 comments on commit 67a6385

Please sign in to comment.