Skip to content

Commit

Permalink
feat: add nodejs scripts to interact with http api
Browse files Browse the repository at this point in the history
  • Loading branch information
vasil-cf committed Dec 23, 2024
1 parent 5e32aca commit 133be56
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

"node/no-unsupported-features": "error",
"node/process-exit-as-throw": "error",
"node/shebang": "warn",
"node/shebang": "off",
"node/no-deprecated-api": "warn",
"no-useless-constructor": "warn",
"no-return-await": "off"
Expand Down
33 changes: 33 additions & 0 deletions lib/metric/deprecated-images/ack-deprecated-images.script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node

async function ackDeprecatedImages() {
try {
const count = Number(process.argv[2]);
if (Number.isNaN(count)) {
console.error('Usage: node ./ack-deprecated-images.script.js <count>');
process.exit(1);
}

const URL = 'http://0.0.0.0:8080/deprecated-images/ack';

const response = await fetch(URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ count }),
});

if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
}

const data = await response.json();
console.log(JSON.stringify(data));
} catch (error) {
console.error('Error: ', error);
process.exit(1);
}
}

ackDeprecatedImages();
20 changes: 20 additions & 0 deletions lib/metric/deprecated-images/get-deprecated-images.script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

async function getDeprecatedImages() {
try {
const URL = 'http://0.0.0.0:8080/deprecated-images';

const response = await fetch(URL);
if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
}

const data = await response.json();
console.log(JSON.stringify(data));
} catch (error) {
console.error('Error: ', error);
process.exit(1);
}
}

getDeprecatedImages();

0 comments on commit 133be56

Please sign in to comment.