Get shared files and folders
There are two methods of retrieving folders and files shared between users. A query to obtain files and folders shared by the user (user-created nodes) secrecyClient.cloud.sharedNodes
and another query to obtain files and folders shared with the user. (files not created by the user) secrecyClient.cloud.nodesSharedWithMe
.
Get files and folders shared with me
The secrecyClient.cloud.nodesSharedWithMe
retrieves files and folders that have been shared with the user.
It takes a single parameter,NodeType
, which can be either "FILE" or "FOLDER" optionally filtering by type the request.
cloud.ts
// "FILE" | "FOLDER"
import { type NodeType } from '@secrecy/lib';
const getFilesAndFoldersSharedWithMe = async (
nodeType?: NodeType
): Promise<Node<NodeBreadcrumbItem, Record<string, unknown>>[] | null> => {
// First we need to check if the secrecyClient is available
if (!secrecyClient) {
return null;
}
try {
if (nodeType) {
const nodesSharedWithMe =
await secrecyClient.cloud.nodesSharedWithMe(nodeType);
return nodesSharedWithMe;
}
const [nodesSharedWithMeFolder, nodesSharedWithMeFile] = await Promise.all([
secrecyClient.cloud.nodesSharedWithMe('FOLDER'),
secrecyClient.cloud.nodesSharedWithMe('FILE'),
]);
return [...nodesSharedWithMeFolder, ...nodesSharedWithMeFile];
} catch (error) {
console.error(error);
return null;
}
};
Get files and folders shared by me
The secrecyClient.cloud.sharedNodes
retrieves files and folders that have been shared by the user.
cloud.ts
// "FILE" | "FOLDER"
import { type NodeType } from '@secrecy/lib';
const getFilesAndFoldersSharedByMe = async (): Promise<
Node<NodeBreadcrumbItem, Record<string, unknown>>[] | null
> => {
// First we need to check if the secrecyClient is available
if (!secrecyClient) {
return null;
}
try {
const sharedNodes = await secrecyClient.cloud.sharedNodes();
return sharedNodes;
} catch (error) {
console.error(error);
return null;
}
};