-
Notifications
You must be signed in to change notification settings - Fork 4
/
structural-delete-index.js
45 lines (42 loc) · 1.29 KB
/
structural-delete-index.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
const configuration = require('./configuration.json');
const fetch = require('node-fetch');
const readline = require('node:readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
function askForConfirmation() {
return new Promise((resolve) => {
rl.question('Are you sure you want to proceed? (yes/no) ', (answer) => {
resolve(answer.trim().toLowerCase() === 'yes');
});
});
}
(async () => {
const confirmed = await askForConfirmation();
try {
if (confirmed) {
const host = configuration.api.host || 'localhost:8080';
const protocol = configuration.api.protocol || 'http';
const adminToken = configuration.api.tokens.admin;
const options = {
headers: {
Authorization: `Bearer ${adminToken}`,
},
};
const url = `${protocol}://${host}/api/admin/index/structural`;
const deleteIndex = await fetch(url, { method: 'DELETE', ...options });
console.log(`Deleting Index: ${url}`);
if (deleteIndex.status === 404) {
console.log('Index not found, nothing to delete');
} else {
const res = await deleteIndex.json();
console.log(res);
}
}
} catch (e) {
console.log('Index does not exist');
} finally {
rl.close();
}
})();