Skip to content

Commit

Permalink
Merge pull request #176 from NetSepio/main
Browse files Browse the repository at this point in the history
Merging main into prod
  • Loading branch information
vaibhavvvvv authored Feb 6, 2025
2 parents 26d78c1 + 2a7e908 commit 6dde688
Show file tree
Hide file tree
Showing 11 changed files with 723 additions and 541 deletions.
13 changes: 4 additions & 9 deletions components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,8 @@ const Navbar = ({ isHome }) => {
const fetchData = async () => {
try {
const getRandomNumber = () => Math.floor(Math.random() * 1000);
const apiUrl = `https://api.multiavatar.com/${getRandomNumber()}`;

const response = await axios.get(apiUrl);
const svgDataUri = `data:image/svg+xml,${encodeURIComponent(
response.data
)}`;
setAvatarUrl(svgDataUri);
const imageUrl = `https://robohash.org/${getRandomNumber()}`;
setAvatarUrl(imageUrl);
} catch (error) {
console.error("Error fetching avatar:", error.message);
}
Expand Down Expand Up @@ -768,7 +763,7 @@ const Navbar = ({ isHome }) => {
<img
src={avatarUrl}
alt="Avatar"
className="w-10 ml-auto"
className="w-10 ml-auto bg-white"
/>
)}
</div>
Expand Down Expand Up @@ -818,7 +813,7 @@ const Navbar = ({ isHome }) => {
<img
src={avatarUrl}
alt="Avatar"
className="w-10 ml-auto"
className="w-10 ml-auto bg-white"
/>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/NodesData.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const NodesData = () => {
const fetchNodesData = async () => {
try {
const response = await axios.get(
`${EREBRUS_GATEWAY_URL}/api/v1.0/nodes/all`,
`${EREBRUS_GATEWAY_URL}api/v1.0/nodes/all`,
{
headers: {
Accept: "application/json, text/plain, /",
Expand Down
2 changes: 1 addition & 1 deletion components/NodesDataDvpnUser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const NodesData = () => {

const fetchNodesData = async () => {
try {
const response = await axios.get(`${EREBRUS_GATEWAY_URL}/api/v1.0/nodes/all`);
const response = await axios.get(`${EREBRUS_GATEWAY_URL}api/v1.0/nodes/all`);

console.log("API Response:", response.data);

Expand Down
17 changes: 9 additions & 8 deletions components/loginComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,8 @@ const LoginComponent = () => {
const fetchData = async () => {
try {
const getRandomNumber = () => Math.floor(Math.random() * 1000);
const apiUrl = `https://api.multiavatar.com/${getRandomNumber()}`;

const response = await axios.get(apiUrl);
const svgDataUri = `data:image/svg+xml,${encodeURIComponent(
response.data
)}`;
setAvatarUrl(svgDataUri);
const imageUrl = `https://robohash.org/${getRandomNumber()}`;
setAvatarUrl(imageUrl);
} catch (error) {
console.error("Error fetching avatar:", error.message);
}
Expand Down Expand Up @@ -309,7 +304,13 @@ const LoginComponent = () => {
Log out
</button>
{avatarUrl && (
<img src={avatarUrl} alt="Avatar" className="w-10 ml-auto" />
<div className="w-10 h-10 rounded-full bg-white flex items-center justify-center">
<img
src={avatarUrl}
alt="Avatar1"
className="w-8 h-8 rounded-full object-contain border-2 border-white bg-white"
/>
</div>
)}
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion components/walrus/SaveToWalrusButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const SaveToWalrusButton: React.FC<SaveToWalrusButtonProps> = ({ configFile, vpn
try {
// Save to Walrus
const walrusResponse = await axios.put(
'https://publisher-devnet.walrus.space/v1/store',
'https://publisher.walrus-testnet.walrus.space',
configFile,
{
params: { epochs: 5 },
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"js-cookie": "^3.0.5",
"leaflet": "^1.9.4",
"mapbox-gl": "^3.5.2",
"multiparty": "^4.2.3",
"next": "13.4.7",
"nft.storage": "^7.1.1",
"petra-plugin-wallet-adapter": "^0.3.0",
Expand Down
58 changes: 58 additions & 0 deletions pages/api/uploadToIPFS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import multiparty from "multiparty";
import fs from "fs";
import FormData from "form-data";

export const config = {
api: {
bodyParser: false,
},
};

export default async function handler(req, res) {
if (req.method !== "POST") {
return res.status(405).json({ error: "Method Not Allowed" });
}

const form = new multiparty.Form();

form.parse(req, async (err, fields, files) => {
if (err) {
console.error("Error parsing file:", err);
return res.status(500).json({ error: "File parsing error" });
}

const file = files.file ? files.file[0] : null;
if (!file) {
return res.status(400).json({ error: "No file uploaded" });
}

try {
const fileBuffer = fs.readFileSync(file.path); // Read file as Buffer
const formData = new FormData();
formData.append("file", fileBuffer, file.originalFilename);

console.log("Uploading file to IPFS...");

const response = await fetch("https://api.ipfs.myriadflow.com/api/v0/add", {
method: "POST",
body: formData.getBuffer(),
headers: {
...formData.getHeaders(),
},
});

const text = await response.text(); // Capture raw response
console.log("IPFS Response:", text);

if (!response.ok) {
throw new Error(`IPFS upload failed: ${text}`);
}

const data = JSON.parse(text);
return res.status(200).json(data);
} catch (error) {
console.error("Upload Error:", error.message);
return res.status(500).json({ error: error.message });
}
});
}
171 changes: 171 additions & 0 deletions pages/deploy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { useState } from 'react';
import axios from 'axios';

// Create axios instance with custom config
const api = axios.create({
baseURL: 'https://35.227.177.48:8443',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
timeout: 300000, // 5 minutes
// For development only - remove in production
httpsAgent: new (require('https').Agent)({
rejectUnauthorized: false
})
});

export default function DeploymentForm() {
const [formData, setFormData] = useState({
project_name: '',
git_url: '',
env_vars: ''
});
const [deployedUrl, setDeployedUrl] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError(null);
setDeployedUrl(null);

try {
// Parse environment variables
const envVars = formData.env_vars
.split('\n')
.filter(line => line.trim())
.reduce((acc, line) => {
const [key, ...values] = line.split('=');
if (key && values.length > 0) {
acc[key.trim()] = values.join('=').trim();
}
return acc;
}, {} as Record<string, string>);

// Make the API call
const response = await api.post('/deploy', {
git_url: formData.git_url,
project_name: formData.project_name,
port: "3000",
env_vars: envVars
});

if (response.data.status === 'success') {
// Use the URL from the response directly
setDeployedUrl(response.data.url);
} else {
throw new Error(response.data.error || 'Deployment failed');
}
} catch (err) {
console.error('Deployment failed:', err);
setError(
err.response?.data?.error ||
err.message ||
'Failed to deploy. Please try again.'
);
} finally {
setLoading(false);
}
};

return (
<div className="max-w-2xl mx-auto p-6">
<h1 className="text-2xl font-bold mb-6">Deploy Project</h1>

<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-white text-sm font-medium mb-1">
Project Name
</label>
<input
type="text"
value={formData.project_name}
onChange={(e) => setFormData(prev => ({...prev, project_name: e.target.value}))}
className="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500"
required
pattern="[a-z0-9-]+"
title="Only lowercase letters, numbers, and hyphens are allowed"
/>
</div>

<div>
<label className="block text-white text-sm font-medium mb-1">
GitHub URL
</label>
<input
type="url"
value={formData.git_url}
onChange={(e) => setFormData(prev => ({...prev, git_url: e.target.value}))}
className="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500"
required
pattern="https://github\.com/.*"
title="Must be a valid GitHub URL"
/>
</div>

<div>
<label className="block text-white text-sm font-medium mb-1">
Environment Variables (optional)
</label>
<textarea
value={formData.env_vars}
onChange={(e) => setFormData(prev => ({...prev, env_vars: e.target.value}))}
className="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500"
placeholder="KEY=value&#10;ANOTHER_KEY=another_value"
rows={4}
/>
<p className="text-sm text-gray-400 mt-1">
One variable per line in KEY=value format
</p>
</div>

<button
type="submit"
disabled={loading}
className={`w-full py-2 px-4 rounded transition-colors ${
loading
? 'bg-blue-300 cursor-not-allowed'
: 'bg-blue-500 hover:bg-blue-600'
} text-white`}
>
{loading ? (
<span className="flex items-center justify-center">
<svg className="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
Deploying...
</span>
) : 'Deploy'}
</button>
</form>

{error && (
<div className="mt-6 p-4 bg-red-50 border border-red-200 rounded">
<h2 className="text-lg font-medium text-red-800 mb-2">Deployment Failed</h2>
<p className="text-red-600">{error}</p>
</div>
)}

{deployedUrl && (
<div className="mt-6 p-4 bg-green-50 border border-green-200 rounded">
<h2 className="text-lg font-medium text-green-800 mb-2">Deployment Successful!</h2>
<p className="mb-2 text-gray-600">Your application has been deployed successfully.</p>
<a
href={deployedUrl}
target="_blank"
rel="noopener noreferrer"
className="text-blue-500 hover:underline break-all flex items-center"
>
{deployedUrl}
<svg className="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
</svg>
</a>
</div>
)}
</div>
);
}
2 changes: 1 addition & 1 deletion pages/mint.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const isSendableNetwork = (connected, network) => {
return connected && network?.toLowerCase() === mynetwork.toLowerCase();
};

const QUICKNODE_RPC = process.env.NEXT_PUBLIC_SOLANA_RPC_URL;
const QUICKNODE_RPC = process.env.NEXT_PUBLIC_SOLANA_RPC_URL || "https://api.devnet.solana.com";
const umi = createUmi(QUICKNODE_RPC).use(bundlrUploader());


Expand Down
Loading

0 comments on commit 6dde688

Please sign in to comment.