-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : add function to download and add image in video
- Loading branch information
1 parent
a98c3b2
commit 2b3473c
Showing
4 changed files
with
82 additions
and
78 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import axios from 'axios' | ||
import fs from 'fs' | ||
export const downloadImages = async (queries: any) => { | ||
for (const query of queries) { | ||
const name = query.timestamp.split('->')[0].trim() | ||
const { data } = await axios.get(`https://api.unsplash.com/search/photos?query=${query.Query}&page=1`, { | ||
headers: { | ||
Authorization: `Client-ID ${process.env.UNSPLASH_ACCESS_KEY}`, | ||
}, | ||
}) | ||
const url = data.results[0].urls.thumb | ||
const response = await axios.get(url, { | ||
responseType: 'stream', | ||
}) | ||
await response.data.pipe(fs.createWriteStream(`${name}.jpg`)) | ||
} | ||
} |
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
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
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