-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add nodejs scripts to interact with http api
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
lib/metric/deprecated-images/ack-deprecated-images.script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
lib/metric/deprecated-images/get-deprecated-images.script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |