summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-06-28 18:00:44 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-06-28 18:00:44 +0530
commit251ff2f06d8e118e3e81b0458d284fbf62af1934 (patch)
tree6196cb60fb134dc631446516a5ee0b367b21f370
parent8329db0b28cf1a65350daf5505f375cc000383e7 (diff)
downloadinsta-local-251ff2f06d8e118e3e81b0458d284fbf62af1934.tar.gz
insta-local-251ff2f06d8e118e3e81b0458d284fbf62af1934.tar.bz2
insta-local-251ff2f06d8e118e3e81b0458d284fbf62af1934.zip
adding the influencer page and adding the funcitons in it
-rw-r--r--client/package-lock.json21
-rw-r--r--client/package.json1
-rw-r--r--client/src/Influencers.js28
-rw-r--r--server/server.js25
4 files changed, 52 insertions, 23 deletions
diff --git a/client/package-lock.json b/client/package-lock.json
index a6fa0c1..8efb06a 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -12,6 +12,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.7.2",
+ "dotenv": "^16.4.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.24.0",
@@ -7763,12 +7764,15 @@
}
},
"node_modules/dotenv": {
- "version": "10.0.0",
- "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
- "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
+ "version": "16.4.5",
+ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
+ "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"license": "BSD-2-Clause",
"engines": {
- "node": ">=10"
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://dotenvx.com"
}
},
"node_modules/dotenv-expand": {
@@ -16403,6 +16407,15 @@
}
}
},
+ "node_modules/react-scripts/node_modules/dotenv": {
+ "version": "10.0.0",
+ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
+ "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
+ "license": "BSD-2-Clause",
+ "engines": {
+ "node": ">=10"
+ }
+ },
"node_modules/read-cache": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz",
diff --git a/client/package.json b/client/package.json
index 70e70ca..71228a9 100644
--- a/client/package.json
+++ b/client/package.json
@@ -7,6 +7,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.7.2",
+ "dotenv": "^16.4.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.24.0",
diff --git a/client/src/Influencers.js b/client/src/Influencers.js
index a72d654..cfa28d9 100644
--- a/client/src/Influencers.js
+++ b/client/src/Influencers.js
@@ -1,16 +1,18 @@
import React, { useState, useEffect, useCallback } from 'react';
import axios from 'axios';
+require('dotenv').config();
-function Influencers({ adminPassword }) {
+function Influencers() {
const [profiles, setProfiles] = useState([]);
const [newProfile, setNewProfile] = useState('');
+ const adminPassword = process.env.ADMIN_PASSWROD;
+
const fetchProfiles = useCallback(async () => {
try {
- const response = await axios.get('http://localhost:5001/profiles', {
- headers: { Authorization: `Bearer ${adminPassword}` }
+ const response = await axios.get('http://localhost:5001/influencers', {
+ headers: { 'x-admin-password': adminPassword }
});
- console.log('Fetched profiles:', response.data);
setProfiles(response.data);
} catch (error) {
console.error('Error fetching profiles:', error);
@@ -23,11 +25,13 @@ function Influencers({ adminPassword }) {
const addProfile = async () => {
try {
+ const updatedProfiles = [...profiles, newProfile];
await axios.post(
- 'http://localhost:5001/profiles',
- { username: newProfile },
- { headers: { Authorization: `Bearer ${adminPassword}` } }
+ 'http://localhost:5001/influencers',
+ { profiles: updatedProfiles },
+ { headers: { 'x-admin-password': adminPassword } }
);
+ setProfiles(updatedProfiles);
setNewProfile('');
fetchProfiles();
} catch (error) {
@@ -42,10 +46,10 @@ function Influencers({ adminPassword }) {
formData.append('file', file);
try {
- await axios.post('http://localhost:5001/upload', formData, {
+ await axios.post('http://localhost:5001/import-influencers', formData, {
headers: {
'Content-Type': 'multipart/form-data',
- Authorization: `Bearer ${adminPassword}`
+ 'x-admin-password': adminPassword
}
});
fetchProfiles();
@@ -57,8 +61,8 @@ function Influencers({ adminPassword }) {
const exportJson = async () => {
try {
- const response = await axios.get('http://localhost:5001/export', {
- headers: { Authorization: `Bearer ${adminPassword}` },
+ const response = await axios.get('http://localhost:5001/export-influencers', {
+ headers: { 'x-admin-password': adminPassword },
responseType: 'blob'
});
const url = window.URL.createObjectURL(new Blob([response.data]));
@@ -82,12 +86,14 @@ function Influencers({ adminPassword }) {
placeholder="Enter Instagram username"
/>
<button onClick={addProfile}>Add</button>
+
<h3>Current Influencers</h3>
<ul>
{profiles.map((profile, index) => (
<li key={index}>{profile}</li>
))}
</ul>
+
<h3>Import/Export Influencers</h3>
<input
type="file"
diff --git a/server/server.js b/server/server.js
index b795846..5f714e4 100644
--- a/server/server.js
+++ b/server/server.js
@@ -1,4 +1,3 @@
-require('dotenv').config(); // Add this line at the top
const express = require('express');
const { exec } = require('child_process');
const path = require('path');
@@ -9,7 +8,7 @@ const bodyParser = require('body-parser');
const app = express();
const port = 5001;
-const adminPassword = process.env.ADMIN_PASSWORD; // Use environment variable
+const adminPassword = process.env.ADMIN_PASSWORD;
app.use(express.json());
app.use(cors());
@@ -114,15 +113,25 @@ const authenticate = (req, res, next) => {
// Endpoint to get influencers
app.get('/influencers', authenticate, (req, res) => {
- const influencers = JSON.parse(fs.readFileSync(path.join(__dirname, 'influencers.json'), 'utf8')).profiles;
- res.json(influencers);
+ try {
+ const influencersData = JSON.parse(fs.readFileSync(path.join(__dirname, 'influencers.json'), 'utf8'));
+ res.json(influencersData.profiles);
+ } catch (error) {
+ console.error('Error fetching influencers:', error);
+ res.status(500).json({ error: 'Error fetching influencers' });
+ }
});
-// Endpoint to update influencers
+// Endpoint to update influencersData
app.post('/influencers', authenticate, (req, res) => {
- const { profiles } = req.body;
- fs.writeFileSync(path.join(__dirname, 'influencers.json'), JSON.stringify({ profiles }, null, 2));
- res.status(200).json({ message: 'Influencers updated successfully' });
+ try {
+ const { profiles } = req.body;
+ const influencersData = { profiles };
+ fs.writeFileSync(path.join(__dirname, 'influencers.json'), JSON.stringify(updatedData, null, 2));
+ } catch (error) {
+ console.error('Error updating influencers:', error);
+ res.status(500).json({ error: 'Error updating influencers' });
+ }
});
// Endpoint to export influencers JSON