Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
uploadFile,
uploadMultipleFiles,
listObjects,
listObjectsAndSizes,
redeemRent,
migrate,
} from "./methods";
Expand All @@ -36,6 +37,7 @@ import {
StorageAccount,
StorageAccountResponse,
ListObjectsResponse,
ListObjectsAndSizesResponse,
StorageAccountInfo,
} from "./types";
interface ShadowDrive {
Expand Down Expand Up @@ -68,6 +70,9 @@ interface ShadowDrive {
getStorageAcc?(key: web3.PublicKey): Promise<StorageAccount>;
getStorageAccs?(): Promise<StorageAccount[]>;
listObjects(key: web3.PublicKey): Promise<ListObjectsResponse>;
listObjectsAndSizes(
key: web3.PublicKey
): Promise<ListObjectsAndSizesResponse>;
makeStorageImmutable(
key: web3.PublicKey,
version: ShadowDriveVersion
Expand Down Expand Up @@ -129,6 +134,7 @@ export class ShdwDrive implements ShadowDrive {
getStorageAccount = getStorageAcc;
getStorageAccounts = getStorageAccs;
listObjects = listObjects;
listObjectsAndSizes = listObjectsAndSizes;
makeStorageImmutable = makeStorageImmutable;
reduceStorage = reduceStorage;
/**
Expand Down
2 changes: 2 additions & 0 deletions src/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import editFile from "./edit-file";
import getStorageAcc from "./get-storage-account";
import getStorageAccs from "./get-storage-accounts";
import listObjects from "./list-objects";
import listObjectsAndSizes from "./list-objects-and-sizes";
import makeStorageImmutable from "./make-storage-immutable";
import reduceStorage from "./reduce-storage";
import cancelDeleteFile from "./cancel-delete-file";
Expand All @@ -25,6 +26,7 @@ export {
getStorageAcc,
getStorageAccs,
listObjects,
listObjectsAndSizes,
makeStorageImmutable,
reduceStorage,
cancelDeleteFile,
Expand Down
17 changes: 17 additions & 0 deletions src/methods/list-objects-and-sizes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PublicKey } from "@solana/web3.js";
import fetch from "cross-fetch";

import { ListObjectsAndSizesResponse } from "../types";
import { SHDW_DRIVE_ENDPOINT } from "../utils/common";

export default function listObjectsAndSizes(
storageAccount: PublicKey
): Promise<ListObjectsAndSizesResponse> {
return fetch(`${SHDW_DRIVE_ENDPOINT}/list-objects-and-sizes`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ storageAccount: storageAccount.toBase58() }),
}).then((res) => res.json());
}
14 changes: 12 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as anchor from "@project-serum/anchor";
import { PublicKey, Transaction } from "@solana/web3.js";
import { PublicKey } from "@solana/web3.js";

export type ShadowDriveVersion = 'v1' | 'v2'
export type ShadowDriveVersion = "v1" | "v2";

export type CreateStorageResponse = {
shdw_bucket: string;
Expand Down Expand Up @@ -38,6 +38,16 @@ export type ListObjectsResponse = {
keys: string[];
};

export type ListObjectFileDetails = {
file_name: string;
size: number | bigint;
last_modified: string | Date;
};

export type ListObjectsAndSizesResponse = {
files: ListObjectFileDetails[];
};

export type StorageAccountResponse = {
publicKey: anchor.web3.PublicKey;
account: StorageAccount;
Expand Down