-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patharchiver.js
151 lines (136 loc) · 3.81 KB
/
archiver.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const path = require('path');
const axios = require('axios');
const config = require('./config');
async function register(xid, cid) {
try {
const response = await axios.post(`${config.archiver}/api/v1/register`, { xid: xid, cid: cid });
return response.data.txid;
}
catch (error) {
console.error(`register error: ${error}`);
}
}
async function notarize(xid, cid, maxFee) {
try {
const response = await axios.post(`${config.archiver}/api/v1/notarize`, { xid: xid, cid: cid, maxFee: maxFee });
return response.data.txid;
}
catch (error) {
console.error(`notarize error: ${error}`);
}
}
async function replaceByFee(txid, maxFee) {
try {
const response = await axios.post(`${config.archiver}/api/v1/replaceByFee`, { txid: txid, maxFee: maxFee });
return response.data.txid;
}
catch (error) {
console.error(`replaceByFee error: ${error}`);
}
}
async function certify(txid) {
try {
const response = await axios.post(`${config.archiver}/api/v1/certify`, { txid: txid });
return response.data;
}
catch (error) {
console.error(`certify error: ${error}`);
}
}
async function walletinfo() {
try {
const response = await axios.get(`${config.archiver}/api/v1/walletinfo`);
return response.data;
}
catch (error) {
console.error(`walletinfo error: ${error}`);
}
}
async function ready() {
try {
const response = await axios.get(`${config.archiver}/api/v1/ready`);
return response.data.ready;
}
catch (error) {
console.error(`ready error: ${error}`);
}
}
// Function to add all changes, commit, and push
async function commitChanges(event) {
try {
const commitMessage = JSON.stringify(event);
const response = await axios.post(`${config.archiver}/api/v1/commit`, { message: commitMessage });
const commit = response.data;
if (commit.error) {
console.error(`commitChanges error: ${commit.error}`);
}
else if (commit.githash) {
const hash = commit.githash.substring(0, 8);
console.log(`Commit: ${commitMessage} (${hash})`);
return commit.githash;
}
}
catch (error) {
console.error(`commitChanges error: ${error.response.data?.error || error}`);
}
}
async function pushChanges() {
try {
const response = await axios.get(`${config.archiver}/api/v1/push`);
const push = response.data;
if (push.error) {
console.error(`pushChanges error: ${push.error}`);
}
}
catch (error) {
console.error(`pushChanges error: ${error}`);
}
}
async function getLogs() {
try {
const response = await axios.get(`${config.archiver}/api/v1/logs`);
const data = response.data;
if (data.error) {
console.error(`getLogs error: ${data.error}`);
}
else {
return data.logs;
}
}
catch (error) {
console.error(`getLogs error: ${error}`);
}
}
async function pinAsset(xid) {
try {
const assetPath = path.join(config.assets, xid);
const response = await axios.get(`${config.archiver}/api/v1/pin/${assetPath}`);
const ipfs = response.data;
return ipfs;
}
catch (error) {
console.error(`pinAsset error: ${error}`);
}
}
async function tweet(message) {
try {
const response = await axios.post(`${config.archiver}/api/v1/tweet`, { message: message });
return response.data;
}
catch (error) {
console.error(`tweet error: ${error}`);
}
}
module.exports = {
replaceByFee,
certify,
commitChanges,
getLogs,
notarize,
pinAsset,
pushChanges,
ready,
register,
tweet,
walletinfo,
};