Skip to content

Commit

Permalink
feat: update environment variable handling and add config.js for API …
Browse files Browse the repository at this point in the history
…keys
  • Loading branch information
dev1abhi committed Jan 8, 2025
1 parent c77217f commit 9e5811f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.vscode-test/
*.vsix
.env
.env
config.js
14 changes: 10 additions & 4 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const axios = require('axios');

require('dotenv').config();

const config = require('./config');

const unsplashKey = Buffer.from(config.UNSPLASH_API_KEY, 'base64').toString('utf-8');
const rapidApiKey = Buffer.from(config.RAPIDAPI_KEY, 'base64').toString('utf-8');
const rapidApiHost = Buffer.from(config.RAPIDAPI_HOST, 'base64').toString('utf-8');

//this calls searchImages and generateImage functions
function activate(context) {
// Command to search images
Expand Down Expand Up @@ -124,14 +130,14 @@ function activate(context) {
}

async function searchImages(query) {
const apiKey = process.env.UNSPLASH_API_KEY;
//const apiKey = process.env.UNSPLASH_API_KEY;
const response = await axios.get(`https://api.unsplash.com/search/photos`, {
params: {
query: query,
per_page: 5 // Number of images to retrieve
},
headers: {
Authorization: `Client-ID ${apiKey}`
Authorization: `Client-ID ${unsplashKey}`
}
});

Expand All @@ -144,8 +150,8 @@ async function generateImage(prompt) {
method: 'POST',
url: 'https://ai-image-generator10.p.rapidapi.com/image_gen_v2',
headers: {
'x-rapidapi-key': process.env.RAPIDAPI_KEY,
'x-rapidapi-host': process.env.RAPIDAPI_HOST,
'x-rapidapi-key': rapidApiKey,
'x-rapidapi-host': rapidApiHost,
'Content-Type': 'application/json'
},
data: {
Expand Down

0 comments on commit 9e5811f

Please sign in to comment.