Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions Tolu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Redefined JavaScript Code

```javascript

import fetch from 'node-fetch';
import fs from 'fs';
import chalk from 'chalk';
import { HttpsProxyAgent } from 'https-proxy-agent';
import { banner } from './utils/banner.js';
import { logger } from './utils/logger.js';
import getToken from './getToken.js';

// Utility: Read lines from file
const readLines = (filename) => fs.readFileSync(filename, 'utf8').split('\n').map(l => l.trim()).filter(Boolean);

// Random quality generator between 60 - 99
const randomQuality = () => Math.floor(Math.random() * 40) + 60;

// Fetch wrapper with retry
const fetchWithRetry = async (url, options, retries = 5, delay = 1000) => {
for (let attempt = 0; attempt < retries; attempt++) {
try {
const res = await fetch(url, options);
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
return await res.json();
} catch (err) {
if (attempt === retries - 1) throw err;
await new Promise(r => setTimeout(r, delay));
}
}
};

// Bandwidth sharing
const shareBandwidth = async (token, proxy) => {
const quality = randomQuality();
const agent = new HttpsProxyAgent(proxy);
try {
const data = await fetchWithRetry('https://api.openloop.so/bandwidth/share', {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ quality }),
agent
});
if (data?.data?.balances?.POINT) {
logger(
`Bandwidth shared: ${chalk.yellow(data.message)} | Score: ${chalk.yellow(quality)} | Earnings: ${chalk.yellow(data.data.balances.POINT)}`
);
}
} catch (e) {
logger(`Failed to share bandwidth: ${e.message}`, 'error');
}
};

// Mission fetching
const fetchMissions = async (token, proxy) => {
const agent = new HttpsProxyAgent(proxy);
try {
const res = await fetch('https://api.openloop.so/missions', {
method: 'GET',
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
agent
});

if (res.status === 401) {
logger('Token expired. Refreshing...', 'warn');
await getToken();
return null;
}
if (!res.ok) throw new Error(`Failed missions fetch: ${res.statusText}`);
return (await res.json()).data;
} catch (e) {
logger(`Error fetching missions: ${e.message}`, 'error');
return null;
}
};

// Mission completion
const completeMission = async (missionId, token, proxy) => {
const agent = new HttpsProxyAgent(proxy);
try {
const data = await fetchWithRetry(`https://api.openloop.so/missions/${missionId}/complete`, {
method: 'GET',
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
agent
});
logger(`Mission ${missionId} completed: ${data.message}`, 'info');
return data;
} catch (e) {
logger(`Failed mission ${missionId}: ${e.message}`, 'error');
}
};

// Worker per token
const processToken = async (token, proxy) => {
const missions = await fetchMissions(token, proxy);
if (missions?.missions) {
const available = missions.missions.filter(m => m.status === 'available').map(m => m.missionId);
logger(`Available missions: ${available.length}`, 'info');
for (const id of available) await completeMission(id, token, proxy);
}
await shareBandwidth(token, proxy);
};

// Main loop
const run = async () => {
logger(banner, 'debug');
logger('Starting bandwidth & mission handler...');

const tokens = readLines('token.txt');
const proxies = readLines('proxy.txt');

const loop = async () => {
for (let i = 0; i < tokens.length; i++) {
const proxy = proxies[i % proxies.length];
await processToken(tokens[i], proxy);
}
};

await loop();
setInterval(loop, 60 * 1000);
};

run();

```