Skip to content

Commit

Permalink
Merge pull request #243 from ardriveapp/PE-6440-files-in-private-driv…
Browse files Browse the repository at this point in the history
…e-appearing-as-public-when-uploaded-via-cli

fix(list-folders)
  • Loading branch information
thiagocarvalhodev authored Jul 24, 2024
2 parents 346f25d + 1c197eb commit 4807f7c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 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-core-js",
"version": "2.0.5",
"version": "2.0.6",
"description": "ArDrive Core contains the essential back end application features to support the ArDrive CLI and Desktop apps, such as file management, Permaweb upload/download, wallet management and other common functions.",
"main": "./lib/exports.js",
"types": "./lib/exports.d.ts",
Expand Down
33 changes: 24 additions & 9 deletions src/arfs/arfsdao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1528,16 +1528,31 @@ export class ArFSDAO extends ArFSDAOAnonymous {
const { edges } = transactions;
hasNextPage = transactions.pageInfo.hasNextPage;

const folders: Promise<ArFSPrivateFolder>[] = edges.map(async (edge: GQLEdgeInterface) => {
cursor = edge.cursor;
const { node } = edge;
const folderBuilder = ArFSPrivateFolderBuilder.fromArweaveNode(node, this.gatewayApi, driveKey);
// Build the folder so that we don't add something invalid to the cache
const folder = await folderBuilder.build(node);
const cacheKey = { folderId: folder.entityId, owner, driveKey };
return this.caches.privateFolderCache.put(cacheKey, Promise.resolve(folder));
const folderPromises: Promise<ArFSPrivateFolder | null>[] = edges.map(async (edge: GQLEdgeInterface) => {
try {
cursor = edge.cursor;
const { node } = edge;
const folderBuilder = ArFSPrivateFolderBuilder.fromArweaveNode(node, this.gatewayApi, driveKey);
// Build the folder so that we don't add something invalid to the cache
const folder = await folderBuilder.build(node);
const cacheKey = { folderId: folder.entityId, owner, driveKey };
return this.caches.privateFolderCache.put(cacheKey, Promise.resolve(folder));
} catch (e) {
// If the folder is broken, skip it
if (e instanceof SyntaxError) {
console.error(`Error building folder. Skipping... Error: ${e}`);
return null;
}

throw e;
}
});
allFolders.push(...(await Promise.all(folders)));

const folders = await Promise.all(folderPromises);

// Filter out null values
const validFolders = folders.filter((f) => f !== null) as ArFSPrivateFolder[];
allFolders.push(...(await Promise.all(validFolders)));
}

return latestRevisionsOnly ? allFolders.filter(latestRevisionFilter) : allFolders;
Expand Down
31 changes: 25 additions & 6 deletions src/arfs/arfsdao_anonymous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,32 @@ export class ArFSDAOAnonymous extends ArFSDAOType {
const { edges } = transactions;

hasNextPage = transactions.pageInfo.hasNextPage;
const folders: Promise<ArFSPublicFolder>[] = edges.map(async (edge: GQLEdgeInterface) => {
const folderPromises = edges.map(async (edge: GQLEdgeInterface) => {
const { node } = edge;
cursor = edge.cursor;
const folderBuilder = ArFSPublicFolderBuilder.fromArweaveNode(node, this.gatewayApi);
const folder = await folderBuilder.build(node);
const cacheKey = { folderId: folder.entityId, owner };
return this.caches.publicFolderCache.put(cacheKey, Promise.resolve(folder));
try {
const folderBuilder = ArFSPublicFolderBuilder.fromArweaveNode(node, this.gatewayApi);
const folder = await folderBuilder.build(node);
const cacheKey = { folderId: folder.entityId, owner };
await this.caches.publicFolderCache.put(cacheKey, Promise.resolve(folder));
return folder;
} catch (e) {
// If the folder is broken, skip it
if (e instanceof SyntaxError) {
console.error(`Error building folder. Skipping... Error: ${e}`);
return null;
}

throw e;
}
});
allFolders.push(...(await Promise.all(folders)));

const folders = await Promise.all(folderPromises);

// Filter out null values
const validFolders = folders.filter((folder) => folder !== null) as ArFSPublicFolder[];

allFolders.push(...validFolders);
}
return latestRevisionsOnly ? allFolders.filter(latestRevisionFilter) : allFolders;
}
Expand All @@ -338,6 +355,7 @@ export class ArFSDAOAnonymous extends ArFSDAOType {

// Fetch all of the folder entities within the drive
const driveIdOfFolder = folder.driveId;

const allFolderEntitiesOfDrive = await this.getAllFoldersOfPublicDrive({
driveId: driveIdOfFolder,
owner,
Expand Down Expand Up @@ -375,6 +393,7 @@ export class ArFSDAOAnonymous extends ArFSDAOType {
}

const entitiesWithPath = children.map((entity) => publicEntityWithPathsFactory(entity, hierarchy));

return entitiesWithPath;
}

Expand Down

0 comments on commit 4807f7c

Please sign in to comment.