mirror of
https://github.com/5vl/AutomatedCats.git
synced 2025-07-08 22:47:01 +00:00
Create get_image.js
This commit is contained in:
parent
fb7a2cb37c
commit
8acb6b6291
22
get_image.js
Normal file
22
get_image.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// To use any npm package on Pipedream, just import it
|
||||||
|
import axios from "axios"
|
||||||
|
import Path from 'path'
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
async run({ steps, $ }) {
|
||||||
|
let url = ""
|
||||||
|
await axios.get("https://api.thecatapi.com/v1/images/search?mime_types=jpg,png&api_key=API_KEY").then((res) => {
|
||||||
|
url = res.data[0].url
|
||||||
|
})
|
||||||
|
const path = Path.resolve('/tmp', 'cat.jpg')
|
||||||
|
|
||||||
|
const { data } = await axios({
|
||||||
|
method: 'GET',
|
||||||
|
url,
|
||||||
|
responseType: 'arraybuffer',
|
||||||
|
})
|
||||||
|
fs.writeFileSync(path, data)
|
||||||
|
return url
|
||||||
|
},
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user