This repository was archived by the owner on Oct 12, 2023. It is now read-only.
forked from aave/aave-ui
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpin-pinata.js
More file actions
81 lines (72 loc) · 2.26 KB
/
pin-pinata.js
File metadata and controls
81 lines (72 loc) · 2.26 KB
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
const pinataSDK = require('@pinata/sdk');
const cid = require('multiformats/cid');
const PIN_ALIAS = process.env.PIN_ALIAS || 'AaveIPFSFrontend';
const BUILD_LOCATION = process.env.BUILD_LOCATION || './build';
const PINATA_API_KEY = process.env.PINATA_API_KEY;
const PINATA_SECRET_KEY = process.env.PINATA_SECRET_KEY;
if (!PINATA_SECRET_KEY || !PINATA_API_KEY) {
console.log('PINATA_SECRET_KEY and PINATA_API_KEY should be specified');
process.exit(1);
}
const cleanupAndPin = async () => {
const pinata = pinataSDK(PINATA_API_KEY, PINATA_SECRET_KEY);
try {
await pinata.testAuthentication();
console.log('Auth successful');
console.log(`Cleaning up the previous pins for ${PIN_ALIAS}`);
try {
const previousPins = await pinata.pinList({
metadata: { name: PIN_ALIAS },
status: 'pinned',
});
if (previousPins.count) {
for (let pin of previousPins.rows) {
try {
await pinata.unpin(pin.ipfs_pin_hash);
console.log(`${pin.ipfs_pin_hash} - deleted`);
} catch (e) {
console.log(`Failed to unpin ${pin.ipfs_pin_hash} with error`, e);
process.exit(1);
}
}
}
} catch (e) {
console.log('Failed to get a list of existing pins with error', e);
process.exit(1);
}
console.log('Uploading the latest build');
try {
const result = await pinata.pinFromFS(BUILD_LOCATION, {
pinataMetadata: {
name: PIN_ALIAS,
},
pinataOptions: {
customPinPolicy: {
regions: [
{
id: 'FRA1',
desiredReplicationCount: 1,
},
{
id: 'NYC1',
desiredReplicationCount: 1,
},
],
},
},
});
return result.IpfsHash;
} catch (e) {
console.log('Pinning was failed with error', e);
process.exit(1);
}
} catch (e) {
console.log('Pinata auth was failed with error', e);
process.exit(1);
}
};
cleanupAndPin().then((hash) => {
console.log(`::set-output name=hash::${hash}`);
const base32_cid = cid.CID.parse(hash).toV1().toString();
console.log(`::set-output name=uri::https://${base32_cid}.ipfs.cf-ipfs.com/`);
});