-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollections.js
94 lines (83 loc) · 2.27 KB
/
collections.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const https = require("https");
const fs = require("fs");
const FormData = require("form-data");
const fetch = require("node-fetch");
const key = `YOUR_API_KEY`;
const fileCID = `YOUR_FILE_CID`; // test CID: bafybeicgpnok4bl2rkf4ceojlb376henq6f6ufwqqvyyzmuo4xloxypuwm
async function run() {
// Creating the collection
const createCol = await fetch("https://api.estuary.tech/collections/create", {
method: "POST",
body: JSON.stringify({
description: "a collection made for testing",
name: "test-collection",
}),
headers: {
Authorization: `Bearer ${key}`,
},
});
const createColRes = await createCol.json();
console.log(createColRes);
/* NOTE (PHIL) Success looks like this:
{
createdAt: '2022-09-06T20:57:12.382233061Z',
uuid: 'e11632d2-b36c-4a43-93a9-5b644a832b93',
name: 'cats',
description: 'test-collection',
userId: 243,
cid: ''
}
*/
// Adding a file to the collection
const colAdd = await fetch(
"https://api.estuary.tech/collections/add-content",
{
method: "POST",
body: JSON.stringify({
cids: [fileCID],
coluuid: createColRes.uuid,
}),
headers: {
Authorization: `Bearer ${key}`,
},
}
);
const colAddRes = await colAdd.json();
console.log(colAddRes);
/* NOTE (PHIL) Success looks like this:
{}
*/
// Adding a file with a path to the collection
const colAddPath = await fetch("https://api.estuary.tech/content/add-ipfs", {
method: "POST",
body: JSON.stringify({
filename: "nature-6.mp4",
root: fileCID,
coluuid: createColRes.uuid,
dir: "/test-dir/nature-6.mp4",
}),
headers: {
Authorization: `Bearer ${key}`,
},
});
const colAddPathRes = await colAddPath.json();
console.log(colAddPathRes);
/* NOTE (PHIL) Success looks like this:
{
requestid: '36533869',
status: 'queued',
created: '2022-09-06T22:10:18.678637745Z',
delegates: [
'/ip4/3.134.223.177/tcp/6745/p2p/12D3KooWN8vAoGd6eurUSidcpLYguQiGZwt4eVgDvbgaS7kiGTup'
],
info: {},
pin: {
cid: 'bafkreibsr2w7ngsu755olsprptddoyihhpiaz7awqoaiad6uob7esjcb6i',
name: 'nature-6.mp4',
origins: [],
meta: {}
}
}
*/
}
run();