@lumeweb/pinner 0.1.0 → 0.1.1
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/README.md +35 -18
- package/dist/cjs/adapters/pinata/index.cjs +6 -3
- package/dist/cjs/adapters/pinata/legacy/adapter.cjs +83 -0
- package/dist/cjs/adapters/pinata/legacy/adapter.cjs.map +1 -0
- package/dist/cjs/adapters/pinata/legacy/adapter.d.cts +74 -0
- package/dist/cjs/adapters/pinata/legacy/index.cjs +1 -0
- package/dist/cjs/adapters/pinata/shared/index.cjs +1 -0
- package/dist/cjs/adapters/pinata/shared/types.d.cts +218 -0
- package/dist/cjs/adapters/pinata/shared/utils.cjs +83 -0
- package/dist/cjs/adapters/pinata/shared/utils.cjs.map +1 -0
- package/dist/cjs/adapters/pinata/v2/adapter-interface.d.cts +198 -0
- package/dist/cjs/adapters/pinata/v2/adapter.cjs +636 -0
- package/dist/cjs/adapters/pinata/v2/adapter.cjs.map +1 -0
- package/dist/cjs/adapters/pinata/v2/adapter.d.cts +17 -0
- package/dist/cjs/adapters/pinata/v2/index.cjs +1 -0
- package/dist/cjs/adapters/pinata/v2/types.d.cts +308 -0
- package/dist/cjs/index.cjs +3 -1
- package/dist/cjs/index.d.cts +5 -3
- package/dist/cjs/pin/client.cjs +5 -3
- package/dist/cjs/pin/client.cjs.map +1 -1
- package/dist/cjs/pinner.cjs +6 -0
- package/dist/cjs/pinner.cjs.map +1 -1
- package/dist/cjs/pinner.d.cts +4 -0
- package/dist/cjs/types/constants.cjs +6 -1
- package/dist/cjs/types/constants.cjs.map +1 -1
- package/dist/cjs/types/pin.d.cts +4 -0
- package/dist/esm/adapters/pinata/index.d.ts +7 -4
- package/dist/esm/adapters/pinata/index.js +6 -3
- package/dist/esm/adapters/pinata/legacy/adapter.d.ts +74 -0
- package/dist/esm/adapters/pinata/legacy/adapter.js +83 -0
- package/dist/esm/adapters/pinata/legacy/adapter.js.map +1 -0
- package/dist/esm/adapters/pinata/legacy/index.d.ts +1 -0
- package/dist/esm/adapters/pinata/legacy/index.js +1 -0
- package/dist/esm/adapters/pinata/shared/index.d.ts +2 -0
- package/dist/esm/adapters/pinata/shared/index.js +1 -0
- package/dist/esm/adapters/pinata/shared/types.d.ts +218 -0
- package/dist/esm/adapters/pinata/shared/utils.d.ts +1 -0
- package/dist/esm/adapters/pinata/shared/utils.js +78 -0
- package/dist/esm/adapters/pinata/shared/utils.js.map +1 -0
- package/dist/esm/adapters/pinata/v2/adapter-interface.d.ts +198 -0
- package/dist/esm/adapters/pinata/v2/adapter.d.ts +17 -0
- package/dist/esm/adapters/pinata/v2/adapter.js +636 -0
- package/dist/esm/adapters/pinata/v2/adapter.js.map +1 -0
- package/dist/esm/adapters/pinata/v2/index.d.ts +3 -0
- package/dist/esm/adapters/pinata/v2/index.js +1 -0
- package/dist/esm/adapters/pinata/v2/types.d.ts +308 -0
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.js +3 -2
- package/dist/esm/pin/client.js +5 -3
- package/dist/esm/pin/client.js.map +1 -1
- package/dist/esm/pinner.d.ts +4 -0
- package/dist/esm/pinner.js +6 -0
- package/dist/esm/pinner.js.map +1 -1
- package/dist/esm/types/constants.js +6 -2
- package/dist/esm/types/constants.js.map +1 -1
- package/dist/esm/types/pin.d.ts +4 -0
- package/package.json +3 -3
- package/dist/cjs/adapters/pinata/adapter.cjs +0 -88
- package/dist/cjs/adapters/pinata/adapter.cjs.map +0 -1
- package/dist/cjs/adapters/pinata/adapter.d.cts +0 -35
- package/dist/cjs/adapters/pinata/builder.cjs +0 -194
- package/dist/cjs/adapters/pinata/builder.cjs.map +0 -1
- package/dist/cjs/adapters/pinata/list-builder.cjs +0 -52
- package/dist/cjs/adapters/pinata/list-builder.cjs.map +0 -1
- package/dist/cjs/types/pinata.d.cts +0 -99
- package/dist/esm/adapters/pinata/adapter.d.ts +0 -35
- package/dist/esm/adapters/pinata/adapter.js +0 -87
- package/dist/esm/adapters/pinata/adapter.js.map +0 -1
- package/dist/esm/adapters/pinata/builder.d.ts +0 -1
- package/dist/esm/adapters/pinata/builder.js +0 -187
- package/dist/esm/adapters/pinata/builder.js.map +0 -1
- package/dist/esm/adapters/pinata/list-builder.d.ts +0 -1
- package/dist/esm/adapters/pinata/list-builder.js +0 -51
- package/dist/esm/adapters/pinata/list-builder.js.map +0 -1
- package/dist/esm/types/pinata.d.ts +0 -99
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
const require_constants = require('../../../types/constants.cjs');
|
|
2
|
+
const require_utils = require('../shared/utils.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/pinata/v2/adapter.ts
|
|
5
|
+
/**
|
|
6
|
+
* Implementation of UploadBuilder
|
|
7
|
+
*/
|
|
8
|
+
var UploadBuilderImpl = class {
|
|
9
|
+
_name;
|
|
10
|
+
_keyvalues;
|
|
11
|
+
constructor(pinner, executeFn) {
|
|
12
|
+
this.pinner = pinner;
|
|
13
|
+
this.executeFn = executeFn;
|
|
14
|
+
}
|
|
15
|
+
name(name) {
|
|
16
|
+
this._name = name;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
keyvalues(keyvalues) {
|
|
20
|
+
this._keyvalues = keyvalues;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
async execute() {
|
|
24
|
+
return this.executeFn(this._name, this._keyvalues);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Implementation of FilterFiles
|
|
29
|
+
*/
|
|
30
|
+
var FilterFilesImpl = class {
|
|
31
|
+
query = {};
|
|
32
|
+
currentPageToken;
|
|
33
|
+
privacy;
|
|
34
|
+
constructor(pinner, privacy) {
|
|
35
|
+
this.pinner = pinner;
|
|
36
|
+
this.privacy = privacy;
|
|
37
|
+
}
|
|
38
|
+
name(name) {
|
|
39
|
+
this.query.name = name;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
group(group) {
|
|
43
|
+
this.query.group = group;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
cid(cid) {
|
|
47
|
+
this.query.cid = cid;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
mimeType(mimeType) {
|
|
51
|
+
this.query.mimeType = mimeType;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
order(order) {
|
|
55
|
+
this.query.order = order;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
limit(limit) {
|
|
59
|
+
this.query.limit = limit;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
cidPending(cidPending) {
|
|
63
|
+
this.query.cidPending = cidPending;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
keyvalues(keyvalues) {
|
|
67
|
+
this.query.metadata = keyvalues;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
noGroup(noGroup) {
|
|
71
|
+
this.query.noGroup = noGroup;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
pageToken(pageToken) {
|
|
75
|
+
this.query.pageToken = Number.parseInt(pageToken, 10);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
then(onfulfilled, onrejected) {
|
|
79
|
+
return this.fetchPage().then(onfulfilled, onrejected);
|
|
80
|
+
}
|
|
81
|
+
async fetchPage() {
|
|
82
|
+
return {
|
|
83
|
+
files: (await this.pinner.listPins({ limit: this.query.limit })).map((pin) => ({
|
|
84
|
+
id: pin.cid.toString(),
|
|
85
|
+
name: pin.name || null,
|
|
86
|
+
cid: pin.cid.toString(),
|
|
87
|
+
size: pin.size || 0,
|
|
88
|
+
number_of_files: 1,
|
|
89
|
+
mime_type: "application/octet-stream",
|
|
90
|
+
keyvalues: pin.metadata || {},
|
|
91
|
+
group_id: null,
|
|
92
|
+
created_at: pin.created.toISOString()
|
|
93
|
+
})),
|
|
94
|
+
next_page_token: this.currentPageToken || ""
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async *[Symbol.asyncIterator]() {
|
|
98
|
+
while (true) {
|
|
99
|
+
const items = await this.fetchPage();
|
|
100
|
+
for (const item of items.files) yield item;
|
|
101
|
+
if (!this.currentPageToken) break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async all() {
|
|
105
|
+
const allItems = [];
|
|
106
|
+
for await (const item of this) allItems.push(item);
|
|
107
|
+
return allItems;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Implementation of FilterQueue
|
|
112
|
+
*/
|
|
113
|
+
var FilterQueueImpl = class {
|
|
114
|
+
query = {};
|
|
115
|
+
currentPageToken;
|
|
116
|
+
constructor(pinner) {
|
|
117
|
+
this.pinner = pinner;
|
|
118
|
+
}
|
|
119
|
+
cid(cid) {
|
|
120
|
+
this.query.cid = cid;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
status(status) {
|
|
124
|
+
this.query.status = status;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
pageLimit(limit) {
|
|
128
|
+
this.query.limit = limit;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
pageToken(pageToken) {
|
|
132
|
+
this.query.pageToken = pageToken;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
sort(sort) {
|
|
136
|
+
this.query.sort = sort;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
then(onfulfilled, onrejected) {
|
|
140
|
+
return this.fetchPage().then(onfulfilled, onrejected);
|
|
141
|
+
}
|
|
142
|
+
async fetchPage() {
|
|
143
|
+
return {
|
|
144
|
+
jobs: (await this.pinner.listPins({ limit: this.query.limit })).map((pin) => ({
|
|
145
|
+
id: pin.cid.toString(),
|
|
146
|
+
cid: pin.cid.toString(),
|
|
147
|
+
date_queued: pin.created.toISOString(),
|
|
148
|
+
name: pin.name || "",
|
|
149
|
+
status: pin.status || "pinned",
|
|
150
|
+
keyvalues: pin.metadata || {},
|
|
151
|
+
host_nodes: [],
|
|
152
|
+
pin_policy: {
|
|
153
|
+
regions: [],
|
|
154
|
+
version: 1
|
|
155
|
+
}
|
|
156
|
+
})),
|
|
157
|
+
next_page_token: this.currentPageToken || ""
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
async *[Symbol.asyncIterator]() {
|
|
161
|
+
while (true) {
|
|
162
|
+
const items = await this.fetchPage();
|
|
163
|
+
for (const item of items.jobs) yield item;
|
|
164
|
+
if (!this.currentPageToken) break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async all() {
|
|
168
|
+
const allItems = [];
|
|
169
|
+
for await (const item of this) allItems.push(item);
|
|
170
|
+
return allItems;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Implementation of FilterGroups
|
|
175
|
+
*/
|
|
176
|
+
var FilterGroupsImpl = class {
|
|
177
|
+
currentPageToken;
|
|
178
|
+
privacy;
|
|
179
|
+
constructor(pinner, privacy) {
|
|
180
|
+
this.pinner = pinner;
|
|
181
|
+
this.privacy = privacy;
|
|
182
|
+
}
|
|
183
|
+
name(name) {
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
limit(limit) {
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
pageToken(pageToken) {
|
|
190
|
+
this.currentPageToken = pageToken;
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
isPublic(isPublic) {
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
then(onfulfilled, onrejected) {
|
|
197
|
+
return this.fetchPage().then(onfulfilled, onrejected);
|
|
198
|
+
}
|
|
199
|
+
async fetchPage() {
|
|
200
|
+
return {
|
|
201
|
+
groups: [],
|
|
202
|
+
next_page_token: this.currentPageToken || ""
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
async *[Symbol.asyncIterator]() {
|
|
206
|
+
const items = await this.fetchPage();
|
|
207
|
+
for (const item of items.groups) yield item;
|
|
208
|
+
}
|
|
209
|
+
async all() {
|
|
210
|
+
const allItems = [];
|
|
211
|
+
for await (const item of this) allItems.push(item);
|
|
212
|
+
return allItems;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Implementation of PublicUpload
|
|
217
|
+
*/
|
|
218
|
+
var PublicUploadImpl = class {
|
|
219
|
+
constructor(pinner, config) {
|
|
220
|
+
this.pinner = pinner;
|
|
221
|
+
this.config = config;
|
|
222
|
+
}
|
|
223
|
+
file(file, options) {
|
|
224
|
+
return new UploadBuilderImpl(this.pinner, async (name, keyvalues) => {
|
|
225
|
+
const result = await this.pinner.uploadAndWait(file, {
|
|
226
|
+
name: name || options?.metadata?.name,
|
|
227
|
+
keyvalues: keyvalues || options?.metadata?.keyvalues
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
id: result.cid,
|
|
231
|
+
name: file.name,
|
|
232
|
+
cid: result.cid,
|
|
233
|
+
size: result.size,
|
|
234
|
+
created_at: result.createdAt.toISOString(),
|
|
235
|
+
number_of_files: 1,
|
|
236
|
+
mime_type: file.type || "application/octet-stream",
|
|
237
|
+
group_id: null,
|
|
238
|
+
keyvalues: keyvalues || options?.metadata?.keyvalues || {},
|
|
239
|
+
vectorized: false,
|
|
240
|
+
network: "public"
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
fileArray(files, options) {
|
|
245
|
+
return new UploadBuilderImpl(this.pinner, async (name, keyvalues) => {
|
|
246
|
+
const result = await (await this.pinner.uploadDirectory(files, {
|
|
247
|
+
name: name || options?.metadata?.name,
|
|
248
|
+
keyvalues: keyvalues || options?.metadata?.keyvalues
|
|
249
|
+
})).result;
|
|
250
|
+
return {
|
|
251
|
+
id: result.cid,
|
|
252
|
+
name: name || options?.metadata?.name || "directory",
|
|
253
|
+
cid: result.cid,
|
|
254
|
+
size: result.size,
|
|
255
|
+
created_at: result.createdAt.toISOString(),
|
|
256
|
+
number_of_files: files.length,
|
|
257
|
+
mime_type: "application/octet-stream",
|
|
258
|
+
group_id: null,
|
|
259
|
+
keyvalues: keyvalues || options?.metadata?.keyvalues || {},
|
|
260
|
+
vectorized: false,
|
|
261
|
+
network: "public"
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
base64(base64String, options) {
|
|
266
|
+
return new UploadBuilderImpl(this.pinner, async (name, keyvalues) => {
|
|
267
|
+
const binaryString = atob(base64String);
|
|
268
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
269
|
+
for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
|
|
270
|
+
const blob = new Blob([bytes], { type: "application/octet-stream" });
|
|
271
|
+
const file = new File([blob], name || options?.metadata?.name || "file.bin", { type: "application/octet-stream" });
|
|
272
|
+
const result = await this.pinner.uploadAndWait(file, {
|
|
273
|
+
name: name || options?.metadata?.name,
|
|
274
|
+
keyvalues: keyvalues || options?.metadata?.keyvalues
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
id: result.cid,
|
|
278
|
+
name: file.name,
|
|
279
|
+
cid: result.cid,
|
|
280
|
+
size: result.size,
|
|
281
|
+
created_at: result.createdAt.toISOString(),
|
|
282
|
+
number_of_files: 1,
|
|
283
|
+
mime_type: "application/octet-stream",
|
|
284
|
+
group_id: null,
|
|
285
|
+
keyvalues: keyvalues || options?.metadata?.keyvalues || {},
|
|
286
|
+
vectorized: false,
|
|
287
|
+
network: "public"
|
|
288
|
+
};
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
url(url, options) {
|
|
292
|
+
return new UploadBuilderImpl(this.pinner, async () => {
|
|
293
|
+
require_utils.notSupported("URL upload");
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
json(data, options) {
|
|
297
|
+
return new UploadBuilderImpl(this.pinner, async (name, keyvalues) => {
|
|
298
|
+
const jsonString = JSON.stringify(data);
|
|
299
|
+
const file = new File([jsonString], name || options?.metadata?.name || "data.json", { type: "application/json" });
|
|
300
|
+
const result = await this.pinner.uploadAndWait(file, {
|
|
301
|
+
name: name || options?.metadata?.name,
|
|
302
|
+
keyvalues: keyvalues || options?.metadata?.keyvalues
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
id: result.cid,
|
|
306
|
+
name: file.name,
|
|
307
|
+
cid: result.cid,
|
|
308
|
+
size: result.size,
|
|
309
|
+
created_at: result.createdAt.toISOString(),
|
|
310
|
+
number_of_files: 1,
|
|
311
|
+
mime_type: "application/json",
|
|
312
|
+
group_id: null,
|
|
313
|
+
keyvalues: keyvalues || options?.metadata?.keyvalues || {},
|
|
314
|
+
vectorized: false,
|
|
315
|
+
network: "public"
|
|
316
|
+
};
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
cid(cid, options) {
|
|
320
|
+
return new UploadBuilderImpl(this.pinner, async () => {
|
|
321
|
+
const cidObj = require_utils.parseCID(cid);
|
|
322
|
+
const generator = await this.pinner.pinByHash(cidObj, {
|
|
323
|
+
name: options?.metadata?.name,
|
|
324
|
+
metadata: options?.metadata?.keyvalues
|
|
325
|
+
});
|
|
326
|
+
for await (const _ of generator);
|
|
327
|
+
return {
|
|
328
|
+
id: cid,
|
|
329
|
+
cid,
|
|
330
|
+
date_queued: (/* @__PURE__ */ new Date()).toISOString(),
|
|
331
|
+
name: options?.metadata?.name || "",
|
|
332
|
+
status: "pinned",
|
|
333
|
+
keyvalues: options?.metadata?.keyvalues || null,
|
|
334
|
+
host_nodes: null,
|
|
335
|
+
group_id: options?.groupId || null
|
|
336
|
+
};
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async createSignedURL(options) {
|
|
340
|
+
require_utils.notSupported("Signed upload URLs");
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
/**
|
|
344
|
+
* Implementation of PrivateUpload
|
|
345
|
+
*/
|
|
346
|
+
var PrivateUploadImpl = class {
|
|
347
|
+
constructor(pinner, config) {
|
|
348
|
+
this.pinner = pinner;
|
|
349
|
+
this.config = config;
|
|
350
|
+
}
|
|
351
|
+
file(file, options) {
|
|
352
|
+
return new UploadBuilderImpl(this.pinner, async () => {
|
|
353
|
+
require_utils.notSupported("Private upload");
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
fileArray(files, options) {
|
|
357
|
+
return new UploadBuilderImpl(this.pinner, async () => {
|
|
358
|
+
require_utils.notSupported("Private upload");
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
base64(base64String, options) {
|
|
362
|
+
return new UploadBuilderImpl(this.pinner, async () => {
|
|
363
|
+
require_utils.notSupported("Private upload");
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
url(url, options) {
|
|
367
|
+
return new UploadBuilderImpl(this.pinner, async () => {
|
|
368
|
+
require_utils.notSupported("Private upload");
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
json(data, options) {
|
|
372
|
+
return new UploadBuilderImpl(this.pinner, async () => {
|
|
373
|
+
require_utils.notSupported("Private upload");
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
cid(cid, options) {
|
|
377
|
+
return new UploadBuilderImpl(this.pinner, async () => {
|
|
378
|
+
require_utils.notSupported("Private upload");
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
async createSignedURL(options) {
|
|
382
|
+
require_utils.notSupported("Private upload");
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
/**
|
|
386
|
+
* Implementation of PublicFiles
|
|
387
|
+
*/
|
|
388
|
+
var PublicFilesImpl = class {
|
|
389
|
+
constructor(pinner, config) {
|
|
390
|
+
this.pinner = pinner;
|
|
391
|
+
this.config = config;
|
|
392
|
+
}
|
|
393
|
+
list() {
|
|
394
|
+
return new FilterFilesImpl(this.pinner, "public");
|
|
395
|
+
}
|
|
396
|
+
async get(id) {
|
|
397
|
+
const cidObj = require_utils.parseCID(id);
|
|
398
|
+
const pin = await this.pinner.getPinStatus(cidObj);
|
|
399
|
+
return {
|
|
400
|
+
id: pin.cid.toString(),
|
|
401
|
+
name: pin.name || null,
|
|
402
|
+
cid: pin.cid.toString(),
|
|
403
|
+
size: pin.size || 0,
|
|
404
|
+
number_of_files: 1,
|
|
405
|
+
mime_type: "application/octet-stream",
|
|
406
|
+
keyvalues: pin.metadata || {},
|
|
407
|
+
group_id: null,
|
|
408
|
+
created_at: pin.created.toISOString()
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
async delete(files) {
|
|
412
|
+
const results = [];
|
|
413
|
+
for (const file of files) {
|
|
414
|
+
await this.pinner.unpin(file);
|
|
415
|
+
results.push({
|
|
416
|
+
id: file,
|
|
417
|
+
status: "deleted"
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return results;
|
|
421
|
+
}
|
|
422
|
+
async update(options) {
|
|
423
|
+
await this.pinner.setPinMetadata(options.id, options.keyvalues || {});
|
|
424
|
+
const pin = await this.pinner.getPinStatus(require_utils.parseCID(options.id));
|
|
425
|
+
return {
|
|
426
|
+
id: pin.cid.toString(),
|
|
427
|
+
name: pin.name || null,
|
|
428
|
+
cid: pin.cid.toString(),
|
|
429
|
+
size: pin.size || 0,
|
|
430
|
+
number_of_files: 1,
|
|
431
|
+
mime_type: "application/octet-stream",
|
|
432
|
+
keyvalues: pin.metadata || {},
|
|
433
|
+
group_id: null,
|
|
434
|
+
created_at: pin.created.toISOString()
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
async addSwap(options) {
|
|
438
|
+
require_utils.notSupported("Swap CID");
|
|
439
|
+
}
|
|
440
|
+
async getSwapHistory(options) {
|
|
441
|
+
return [];
|
|
442
|
+
}
|
|
443
|
+
async deleteSwap(cid) {
|
|
444
|
+
require_utils.notSupported("Swap CID");
|
|
445
|
+
}
|
|
446
|
+
queue() {
|
|
447
|
+
return new FilterQueueImpl(this.pinner);
|
|
448
|
+
}
|
|
449
|
+
async deletePinRequest(requestId) {
|
|
450
|
+
await this.pinner.unpinByRequestId(requestId);
|
|
451
|
+
return requestId;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* Implementation of PrivateFiles
|
|
456
|
+
*/
|
|
457
|
+
var PrivateFilesImpl = class {
|
|
458
|
+
constructor(pinner, config) {
|
|
459
|
+
this.pinner = pinner;
|
|
460
|
+
this.config = config;
|
|
461
|
+
}
|
|
462
|
+
list() {
|
|
463
|
+
require_utils.notSupported("Private files");
|
|
464
|
+
}
|
|
465
|
+
async get(id) {
|
|
466
|
+
require_utils.notSupported("Private files");
|
|
467
|
+
}
|
|
468
|
+
async delete(files) {
|
|
469
|
+
require_utils.notSupported("Private files");
|
|
470
|
+
}
|
|
471
|
+
async update(options) {
|
|
472
|
+
require_utils.notSupported("Private files");
|
|
473
|
+
}
|
|
474
|
+
async addSwap(options) {
|
|
475
|
+
require_utils.notSupported("Private files");
|
|
476
|
+
}
|
|
477
|
+
async getSwapHistory(options) {
|
|
478
|
+
require_utils.notSupported("Private files");
|
|
479
|
+
}
|
|
480
|
+
async deleteSwap(cid) {
|
|
481
|
+
require_utils.notSupported("Private files");
|
|
482
|
+
}
|
|
483
|
+
queue() {
|
|
484
|
+
require_utils.notSupported("Private files");
|
|
485
|
+
}
|
|
486
|
+
async deletePinRequest(requestId) {
|
|
487
|
+
require_utils.notSupported("Private files");
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
/**
|
|
491
|
+
* Implementation of PublicGateways
|
|
492
|
+
*/
|
|
493
|
+
var PublicGatewaysImpl = class {
|
|
494
|
+
constructor(pinner, config) {
|
|
495
|
+
this.pinner = pinner;
|
|
496
|
+
this.config = config;
|
|
497
|
+
}
|
|
498
|
+
get(cid) {
|
|
499
|
+
return {
|
|
500
|
+
cid,
|
|
501
|
+
gateway: this.config?.pinataGateway || require_constants.DEFAULT_GATEWAY,
|
|
502
|
+
url: `${this.config?.pinataGateway || require_constants.DEFAULT_GATEWAY}/ipfs/${cid}`
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
async convert(url, gatewayPrefix) {
|
|
506
|
+
const gateway = gatewayPrefix || this.config?.pinataGateway || require_constants.DEFAULT_GATEWAY;
|
|
507
|
+
return url.replace("ipfs://", `${gateway}/ipfs/`);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* Implementation of PrivateGateways
|
|
512
|
+
*/
|
|
513
|
+
var PrivateGatewaysImpl = class {
|
|
514
|
+
constructor(pinner, config) {
|
|
515
|
+
this.pinner = pinner;
|
|
516
|
+
this.config = config;
|
|
517
|
+
}
|
|
518
|
+
get(cid) {
|
|
519
|
+
require_utils.notSupported("Private gateways");
|
|
520
|
+
}
|
|
521
|
+
createAccessLink(options) {
|
|
522
|
+
require_utils.notSupported("Private gateways");
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
/**
|
|
526
|
+
* Implementation of PublicGroups
|
|
527
|
+
*/
|
|
528
|
+
var PublicGroupsImpl = class {
|
|
529
|
+
constructor(pinner, config) {
|
|
530
|
+
this.pinner = pinner;
|
|
531
|
+
this.config = config;
|
|
532
|
+
}
|
|
533
|
+
async create(options) {
|
|
534
|
+
require_utils.notSupported("Groups");
|
|
535
|
+
}
|
|
536
|
+
list() {
|
|
537
|
+
return new FilterGroupsImpl(this.pinner, "public");
|
|
538
|
+
}
|
|
539
|
+
async get(options) {
|
|
540
|
+
require_utils.notSupported("Groups");
|
|
541
|
+
}
|
|
542
|
+
async addFiles(options) {
|
|
543
|
+
require_utils.notSupported("Groups");
|
|
544
|
+
}
|
|
545
|
+
async removeFiles(options) {
|
|
546
|
+
require_utils.notSupported("Groups");
|
|
547
|
+
}
|
|
548
|
+
async update(options) {
|
|
549
|
+
require_utils.notSupported("Groups");
|
|
550
|
+
}
|
|
551
|
+
async delete(options) {
|
|
552
|
+
require_utils.notSupported("Groups");
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
/**
|
|
556
|
+
* Implementation of PrivateGroups
|
|
557
|
+
*/
|
|
558
|
+
var PrivateGroupsImpl = class {
|
|
559
|
+
constructor(pinner, config) {
|
|
560
|
+
this.pinner = pinner;
|
|
561
|
+
this.config = config;
|
|
562
|
+
}
|
|
563
|
+
async create(options) {
|
|
564
|
+
require_utils.notSupported("Private groups");
|
|
565
|
+
}
|
|
566
|
+
list() {
|
|
567
|
+
require_utils.notSupported("Private groups");
|
|
568
|
+
}
|
|
569
|
+
async get(options) {
|
|
570
|
+
require_utils.notSupported("Private groups");
|
|
571
|
+
}
|
|
572
|
+
async addFiles(options) {
|
|
573
|
+
require_utils.notSupported("Private groups");
|
|
574
|
+
}
|
|
575
|
+
async removeFiles(options) {
|
|
576
|
+
require_utils.notSupported("Private groups");
|
|
577
|
+
}
|
|
578
|
+
async update(options) {
|
|
579
|
+
require_utils.notSupported("Private groups");
|
|
580
|
+
}
|
|
581
|
+
async delete(options) {
|
|
582
|
+
require_utils.notSupported("Private groups");
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
/**
|
|
586
|
+
* Implementation of Analytics
|
|
587
|
+
*/
|
|
588
|
+
var AnalyticsImpl = class {
|
|
589
|
+
async requests(query) {
|
|
590
|
+
return { data: [] };
|
|
591
|
+
}
|
|
592
|
+
async bandwidth(query) {
|
|
593
|
+
return {
|
|
594
|
+
total_requests: 0,
|
|
595
|
+
total_bandwidth: 0,
|
|
596
|
+
time_periods: []
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
/**
|
|
601
|
+
* Create Pinata Adapter
|
|
602
|
+
*
|
|
603
|
+
* @param pinner - Pinner client instance
|
|
604
|
+
* @param config - Pinata configuration
|
|
605
|
+
* @returns PinataAdapter
|
|
606
|
+
*/
|
|
607
|
+
function pinataAdapter(pinner, config) {
|
|
608
|
+
const effectiveConfig = config || {};
|
|
609
|
+
return {
|
|
610
|
+
config: effectiveConfig,
|
|
611
|
+
updateConfig(newConfig) {
|
|
612
|
+
Object.assign(effectiveConfig, newConfig);
|
|
613
|
+
},
|
|
614
|
+
upload: {
|
|
615
|
+
public: new PublicUploadImpl(pinner, effectiveConfig),
|
|
616
|
+
private: new PrivateUploadImpl(pinner, effectiveConfig)
|
|
617
|
+
},
|
|
618
|
+
files: {
|
|
619
|
+
public: new PublicFilesImpl(pinner, effectiveConfig),
|
|
620
|
+
private: new PrivateFilesImpl(pinner, effectiveConfig)
|
|
621
|
+
},
|
|
622
|
+
gateways: {
|
|
623
|
+
public: new PublicGatewaysImpl(pinner, effectiveConfig),
|
|
624
|
+
private: new PrivateGatewaysImpl(pinner, effectiveConfig)
|
|
625
|
+
},
|
|
626
|
+
groups: {
|
|
627
|
+
public: new PublicGroupsImpl(pinner, effectiveConfig),
|
|
628
|
+
private: new PrivateGroupsImpl(pinner, effectiveConfig)
|
|
629
|
+
},
|
|
630
|
+
analytics: new AnalyticsImpl()
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
//#endregion
|
|
635
|
+
exports.pinataAdapter = pinataAdapter;
|
|
636
|
+
//# sourceMappingURL=adapter.cjs.map
|