-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-posting-api.js
More file actions
177 lines (149 loc) Β· 4.61 KB
/
Copy pathtest-posting-api.js
File metadata and controls
177 lines (149 loc) Β· 4.61 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env node
/**
* Test script for Skatehive Posting API endpoints
*
* Usage:
* node test-posting-api.js blog
* node test-posting-api.js feed
*/
const API_URL = process.env.API_URL || 'http://localhost:3000';
const API_KEY = process.env.SKATEHIVE_API_KEY;
const HIVE_USERNAME = process.env.HIVE_USERNAME;
const POSTING_KEY = process.env.HIVE_POSTING_KEY;
if (!API_KEY) {
console.error('β Missing SKATEHIVE_API_KEY environment variable');
console.log('Set it with: export SKATEHIVE_API_KEY="your-key-here"');
process.exit(1);
}
if (!HIVE_USERNAME) {
console.error('β Missing HIVE_USERNAME environment variable');
console.log('Set it with: export HIVE_USERNAME="yourhiveusername"');
process.exit(1);
}
if (!POSTING_KEY) {
console.error('β Missing HIVE_POSTING_KEY environment variable');
console.log('Set it with: export HIVE_POSTING_KEY="5K..."');
process.exit(1);
}
async function testComposeBlog() {
console.log('π§ͺ Testing POST /api/v2/composeBlog');
const data = {
author: HIVE_USERNAME,
posting_key: POSTING_KEY,
title: `Test Blog Post ${Date.now()}`,
body: `## Test Blog Post
This is a test post created via the Skatehive API.
### Features
- Markdown support
- IPFS images
- Beneficiaries
- Tags
**Posted at:** ${new Date().toISOString()}
**Posted by:** ${HIVE_USERNAME}

`,
thumbnail: 'https://i.imgur.com/placeholder.jpg',
tags: ['test', 'skateboarding', 'hive-173115', 'api'],
images: ['https://i.imgur.com/placeholder.jpg'],
beneficiaries: [
{
account: 'skatehacker',
weight: 500 // 5%
}
]
};
try {
const response = await fetch(`${API_URL}/api/v2/composeBlog`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
const result = await response.json();
if (response.ok) {
console.log('β
Success!');
console.log('π Post URL:', result.data.url);
console.log('π Hive URL:', result.data.hive_url);
console.log('π Transaction ID:', result.data.transaction_id);
} else {
console.log('β Failed');
console.log('Error:', result.error);
if (result.details) {
console.log('Details:', result.details);
}
}
return result;
} catch (error) {
console.error('β Request failed:', error.message);
throw error;
}
}
async function testPostFeed() {
console.log('π§ͺ Testing POST /api/v2/postFeed');
const data = {
author: HIVE_USERNAME,
posting_key: POSTING_KEY,
body: `Just landed my first kickflip! πΉ
#skateboarding #progress #test
Posted via Skatehive API at ${new Date().toLocaleTimeString()} by @${HIVE_USERNAME}`,
images: [
'https://i.imgur.com/placeholder.jpg'
]
};
try {
const response = await fetch(`${API_URL}/api/v2/postFeed`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
const result = await response.json();
if (response.ok) {
console.log('β
Success!');
console.log('π Post URL:', result.data.url);
console.log('π Hive URL:', result.data.hive_url);
console.log('π Transaction ID:', result.data.transaction_id);
console.log('π€ Parent:', `${result.data.parent_author}/${result.data.parent_permlink}`);
} else {
console.log('β Failed');
console.log('Error:', result.error);
if (result.details) {
console.log('Details:', result.details);
}
}
return result;
} catch (error) {
console.error('β Request failed:', error.message);
throw error;
}
}
// Main
const command = process.argv[2];
if (command === 'blog') {
testComposeBlog().catch(() => process.exit(1));
} else if (command === 'feed') {
testPostFeed().catch(() => process.exit(1));
} else {
console.log(`
Usage: node test-posting-api.js <command>
Commands:
blog Test composeBlog endpoint (full blog post)
feed Test postFeed endpoint (snap/short post)
Environment:
API_URL API base URL (default: http://localhost:3000)
SKATEHIVE_API_KEY Your API key (required)
HIVE_USERNAME Your Hive username (required)
HIVE_POSTING_KEY Your Hive posting key (required)
Examples:
export SKATEHIVE_API_KEY="your-api-key-here"
export HIVE_USERNAME="yourhiveusername"
export HIVE_POSTING_KEY="5K..."
node test-posting-api.js blog
node test-posting-api.js feed
`);
process.exit(1);
}