-
Notifications
You must be signed in to change notification settings - Fork 3
/
fetch-inscription-testdata.js
43 lines (35 loc) · 1.15 KB
/
fetch-inscription-testdata.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
const https = require('https');
const readline = require('readline');
const fs = require('fs');
const path = require('path');
const mime = require('mime-types');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Please enter the inscription ID: ', (inscriptionId) => {
const url = `https://ordinals.com/content/${inscriptionId}`;
https.get(url, (res) => {
let dataChunks = [];
const contentType = res.headers['content-type'];
const extension = mime.extension(contentType) || 'unknown';
res.on('data', (chunk) => {
dataChunks.push(chunk);
});
res.on('end', () => {
const buffer = Buffer.concat(dataChunks);
const dir = path.join(__dirname, 'testdata');
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const filePath = path.join(dir, `inscription_${inscriptionId}.${extension}`);
fs.writeFile(filePath, buffer, (err) => {
if (err) throw err;
console.log(`The inscription file content was saved to ${filePath}`);
});
});
}).on('error', (err) => {
console.error('Error: ' + err.message);
});
rl.close();
});