shogun-relay-sdk 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/ipfs.d.ts +14 -0
- package/dist/modules/ipfs.js +28 -0
- package/package.json +1 -1
package/dist/modules/ipfs.d.ts
CHANGED
|
@@ -4,6 +4,20 @@ export declare class IpfsModule {
|
|
|
4
4
|
constructor(client: ApiClient);
|
|
5
5
|
getStatus(): Promise<any>;
|
|
6
6
|
uploadFile(fileBuffer: Buffer, filename: string, contentType: string, userAddress?: string): Promise<any>;
|
|
7
|
+
/**
|
|
8
|
+
* Upload multiple files as a directory to IPFS
|
|
9
|
+
* Maintains directory structure using relative paths
|
|
10
|
+
*
|
|
11
|
+
* @param files Array of file objects with buffer, filename, path, and contentType
|
|
12
|
+
* @param userAddress Optional user address for authentication
|
|
13
|
+
* @returns Promise with directory CID and file information
|
|
14
|
+
*/
|
|
15
|
+
uploadDirectory(files: Array<{
|
|
16
|
+
buffer: Buffer;
|
|
17
|
+
filename: string;
|
|
18
|
+
path: string;
|
|
19
|
+
contentType?: string;
|
|
20
|
+
}>, userAddress?: string): Promise<any>;
|
|
7
21
|
cat(cid: string): Promise<Buffer>;
|
|
8
22
|
pinAdd(cid: string): Promise<any>;
|
|
9
23
|
pinRm(cid: string): Promise<any>;
|
package/dist/modules/ipfs.js
CHANGED
|
@@ -26,6 +26,34 @@ class IpfsModule {
|
|
|
26
26
|
headers: headers,
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Upload multiple files as a directory to IPFS
|
|
31
|
+
* Maintains directory structure using relative paths
|
|
32
|
+
*
|
|
33
|
+
* @param files Array of file objects with buffer, filename, path, and contentType
|
|
34
|
+
* @param userAddress Optional user address for authentication
|
|
35
|
+
* @returns Promise with directory CID and file information
|
|
36
|
+
*/
|
|
37
|
+
async uploadDirectory(files, userAddress) {
|
|
38
|
+
if (!files || files.length === 0) {
|
|
39
|
+
throw new Error("At least one file is required for directory upload");
|
|
40
|
+
}
|
|
41
|
+
const form = new form_data_1.default();
|
|
42
|
+
// Add all files to FormData maintaining directory structure
|
|
43
|
+
files.forEach((file) => {
|
|
44
|
+
form.append("files", file.buffer, {
|
|
45
|
+
filename: file.path, // Use path to maintain directory structure
|
|
46
|
+
contentType: file.contentType || "application/octet-stream",
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
const headers = form.getHeaders();
|
|
50
|
+
if (userAddress) {
|
|
51
|
+
headers["x-user-address"] = userAddress;
|
|
52
|
+
}
|
|
53
|
+
return this.client.post("/api/v1/ipfs/upload-directory", form, {
|
|
54
|
+
headers: headers,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
29
57
|
async cat(cid) {
|
|
30
58
|
return this.client.get(`/api/v1/ipfs/cat/${cid}`, {
|
|
31
59
|
responseType: "arraybuffer",
|
package/package.json
CHANGED