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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const axios = require('axios');
|
| 3 |
+
const FormData = require('form-data');
|
| 4 |
+
const fs = require('fs');
|
| 5 |
+
const path = require('path');
|
| 6 |
+
|
| 7 |
+
const app = express();
|
| 8 |
+
const PORT = 7860;
|
| 9 |
+
app.get('/addsong', async (req, res) => {
|
| 10 |
+
const youtubeUrl = req.query.url;
|
| 11 |
+
if (!youtubeUrl) return res.status(400).send('No URL provided.');
|
| 12 |
+
|
| 13 |
+
try {
|
| 14 |
+
const ytdlResponse = await axios.get(
|
| 15 |
+
`https://ccproject.serv00.net/ytdl2.php?url=${encodeURIComponent(youtubeUrl)}`,
|
| 16 |
+
{ headers: { 'User-Agent': 'Mozilla/5.1' } }
|
| 17 |
+
);
|
| 18 |
+
|
| 19 |
+
const data = ytdlResponse.data;
|
| 20 |
+
if (!data.download || !data.title) return res.status(400).send('Invalid response from YTDL API.');
|
| 21 |
+
|
| 22 |
+
const downloadUrl = data.download;
|
| 23 |
+
const title = data.title;
|
| 24 |
+
const timestamp = Date.now();
|
| 25 |
+
const filename = `${timestamp}.mp3`;
|
| 26 |
+
const filePath = path.join(__dirname, filename);
|
| 27 |
+
|
| 28 |
+
const fileDownload = await axios({
|
| 29 |
+
method: 'get',
|
| 30 |
+
url: downloadUrl,
|
| 31 |
+
responseType: 'stream',
|
| 32 |
+
headers: { 'User-Agent': 'Mozilla/5.1' }
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
const writer = fs.createWriteStream(filePath);
|
| 36 |
+
fileDownload.data.pipe(writer);
|
| 37 |
+
|
| 38 |
+
await new Promise((resolve, reject) => {
|
| 39 |
+
writer.on('finish', resolve);
|
| 40 |
+
writer.on('error', reject);
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
const form = new FormData();
|
| 44 |
+
form.append('file', fs.createReadStream(filePath));
|
| 45 |
+
|
| 46 |
+
const uploadResponse = await axios.post(
|
| 47 |
+
'https://ccproject.serv00.net/cc.php',
|
| 48 |
+
form,
|
| 49 |
+
{ headers: { ...form.getHeaders(), 'User-Agent': 'Mozilla/5.1' } }
|
| 50 |
+
);
|
| 51 |
+
|
| 52 |
+
if (!uploadResponse.data.url) {
|
| 53 |
+
fs.unlinkSync(filePath);
|
| 54 |
+
return res.status(400).send('Invalid response from upload API.');
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
const uploadedUrl = uploadResponse.data.url;
|
| 58 |
+
const addSongApi = `http://gdphps.ccproject.serv00.net/dashboard/api/addSong.php?download=${encodeURIComponent(uploadedUrl)}&author=GdphMusicGD&name=${encodeURIComponent(title)}`;
|
| 59 |
+
const finalResponse = await axios.get(addSongApi, {
|
| 60 |
+
headers: { 'User-Agent': 'Mozilla/5.1' }
|
| 61 |
+
});
|
| 62 |
+
|
| 63 |
+
fs.unlinkSync(filePath);
|
| 64 |
+
res.send(finalResponse.data);
|
| 65 |
+
|
| 66 |
+
} catch (error) {
|
| 67 |
+
res.status(500).send(error.toString());
|
| 68 |
+
}
|
| 69 |
+
});
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
app.get("/api/catbox", async (req, res) => {
|
| 73 |
+
const url = req.query.url;
|
| 74 |
+
if (!url) return res.status(400).json({ error: "Missing 'url' parameter" });
|
| 75 |
+
|
| 76 |
+
try {
|
| 77 |
+
const saveDir = path.join(__dirname, "public");
|
| 78 |
+
if (!fs.existsSync(saveDir)) fs.mkdirSync(saveDir, { recursive: true });
|
| 79 |
+
|
| 80 |
+
const timestamp = Date.now();
|
| 81 |
+
const filePath = path.join(saveDir, `${timestamp}.mp3`);
|
| 82 |
+
|
| 83 |
+
const response = await axios.get(url, { responseType: "arraybuffer" });
|
| 84 |
+
fs.writeFileSync(filePath, response.data);
|
| 85 |
+
|
| 86 |
+
const form = new FormData();
|
| 87 |
+
form.append("reqtype", "fileupload");
|
| 88 |
+
form.append("userhash", "");
|
| 89 |
+
form.append("fileToUpload", fs.createReadStream(filePath));
|
| 90 |
+
|
| 91 |
+
const uploadResponse = await axios.post("https://catbox.moe/user/api.php", form, {
|
| 92 |
+
headers: {
|
| 93 |
+
...form.getHeaders(),
|
| 94 |
+
"User-Agent": "Mozilla/5.0",
|
| 95 |
+
"Accept": "application/json",
|
| 96 |
+
"Accept-Encoding": "gzip, deflate, br, zstd",
|
| 97 |
+
"sec-ch-ua-platform": '"Android"',
|
| 98 |
+
"cache-control": "no-cache",
|
| 99 |
+
"sec-ch-ua": '"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
|
| 100 |
+
"sec-ch-ua-mobile": "?1",
|
| 101 |
+
"x-requested-with": "XMLHttpRequest",
|
| 102 |
+
"dnt": "1",
|
| 103 |
+
"origin": "https://catbox.moe",
|
| 104 |
+
"sec-fetch-site": "same-origin",
|
| 105 |
+
"sec-fetch-mode": "cors",
|
| 106 |
+
"sec-fetch-dest": "empty",
|
| 107 |
+
"referer": "https://catbox.moe/",
|
| 108 |
+
"accept-language": "en-US,en;q=0.9",
|
| 109 |
+
"priority": "u=1, i"
|
| 110 |
+
}
|
| 111 |
+
});
|
| 112 |
+
|
| 113 |
+
fs.unlink(filePath, () => {});
|
| 114 |
+
res.json({ fileUrl: uploadResponse.data.trim() });
|
| 115 |
+
} catch (error) {
|
| 116 |
+
res.status(500).json({ error: "Failed to upload file", details: error.message });
|
| 117 |
+
}
|
| 118 |
+
});
|
| 119 |
+
const cheerio = require('cheerio');
|
| 120 |
+
const categoryEmojiMap = {
|
| 121 |
+
"Night icon": "🌙",
|
| 122 |
+
"Gear icon": "⚙️",
|
| 123 |
+
"Egg icon": "🥚",
|
| 124 |
+
"Cosmetics icon": "💅",
|
| 125 |
+
"Honey icon": "🍯",
|
| 126 |
+
"Seeds icon": "🌱"
|
| 127 |
+
};
|
| 128 |
+
|
| 129 |
+
async function getStockItems() {
|
| 130 |
+
const url = 'https://growagarden.gg/stocks';
|
| 131 |
+
try {
|
| 132 |
+
const { data } = await axios.get(url);
|
| 133 |
+
const $ = cheerio.load(data);
|
| 134 |
+
|
| 135 |
+
const stocks = [];
|
| 136 |
+
|
| 137 |
+
$('article.group.relative.rounded-lg.border-border\\/40.bg-card\\/20.p-4.transition-all.duration-300.hover\\:shadow-xl.hover\\:shadow-primary\\/10').each((i, parentElem) => {
|
| 138 |
+
const stockCategory = $(parentElem).find('h2.text-lg.font-semibold').text().trim();
|
| 139 |
+
const svgAriaLabel = $(parentElem).find('svg').attr('aria-label');
|
| 140 |
+
const categoryEmoji = categoryEmojiMap[svgAriaLabel] || '';
|
| 141 |
+
|
| 142 |
+
const items = [];
|
| 143 |
+
|
| 144 |
+
$(parentElem).find('article.group.relative.flex.items-center.gap-3.rounded-lg.border.bg-background\\/50.p-3.transition-all.duration-300.hover\\:scale-\\[1\\.02\\].hover\\:bg-background\\/80').each((j, itemElem) => {
|
| 145 |
+
const itemName = $(itemElem).find('h3.text-sm.font-medium').text().trim();
|
| 146 |
+
const itemEmoji = $(itemElem).find('div.absolute.-bottom-1.-right-1.rounded-full.border.border-border\\/50.bg-background\\/80.p-0.5.text-lg.shadow-sm').text().trim();
|
| 147 |
+
items.push({
|
| 148 |
+
name: itemName,
|
| 149 |
+
emoji: itemEmoji,
|
| 150 |
+
id: `${stockCategory.toLowerCase().replace(/\s+/g, '-')}-${i}-${j}`
|
| 151 |
+
});
|
| 152 |
+
});
|
| 153 |
+
|
| 154 |
+
stocks.push({
|
| 155 |
+
category: stockCategory,
|
| 156 |
+
categoryEmoji: categoryEmoji,
|
| 157 |
+
items: items,
|
| 158 |
+
count: items.length
|
| 159 |
+
});
|
| 160 |
+
});
|
| 161 |
+
|
| 162 |
+
return {
|
| 163 |
+
success: true,
|
| 164 |
+
lastUpdated: new Date().toISOString(),
|
| 165 |
+
data: stocks.filter(stock =>
|
| 166 |
+
["Night Stock", "Gear Stock", "Egg Stock", "Cosmetics Stock", "Honey Stock", "Seeds Stock"]
|
| 167 |
+
.includes(stock.category)
|
| 168 |
+
)
|
| 169 |
+
};
|
| 170 |
+
|
| 171 |
+
} catch (error) {
|
| 172 |
+
console.error(`Error fetching stock data: ${error}`);
|
| 173 |
+
return {
|
| 174 |
+
success: false,
|
| 175 |
+
error: error.message,
|
| 176 |
+
message: "Failed to fetch stock data"
|
| 177 |
+
};
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
app.get('/grow', async (req, res) => {
|
| 182 |
+
try {
|
| 183 |
+
const stockData = await getStockItems();
|
| 184 |
+
res.json(stockData);
|
| 185 |
+
} catch (error) {
|
| 186 |
+
console.error('Error in /grow route:', error);
|
| 187 |
+
res.status(500).json({
|
| 188 |
+
success: false,
|
| 189 |
+
error: error.message,
|
| 190 |
+
message: "Internal server error"
|
| 191 |
+
});
|
| 192 |
+
}
|
| 193 |
+
});
|
| 194 |
+
const { spawn } = require("child_process");
|
| 195 |
+
|
| 196 |
+
const botFiles = [
|
| 197 |
+
"bot.js"
|
| 198 |
+
];
|
| 199 |
+
|
| 200 |
+
function startBot(file) {
|
| 201 |
+
console.log(`Starting bot: ${file}`);
|
| 202 |
+
const child = spawn("node", ["--trace-warnings", "--async-stack-traces", file], {
|
| 203 |
+
cwd: __dirname,
|
| 204 |
+
stdio: "inherit",
|
| 205 |
+
shell: true,
|
| 206 |
+
});
|
| 207 |
+
|
| 208 |
+
child.on("close", (codeExit) => {
|
| 209 |
+
console.log(`Bot process (${file}) exited with code: ${codeExit}`);
|
| 210 |
+
if (codeExit !== 0) {
|
| 211 |
+
setTimeout(() => startBot(file), 3000);
|
| 212 |
+
}
|
| 213 |
+
});
|
| 214 |
+
|
| 215 |
+
child.on("error", (error) => {
|
| 216 |
+
console.error(`An error occurred starting the bot (${file}): ${error}`);
|
| 217 |
+
});
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
botFiles.forEach(startBot);
|
| 221 |
+
// Spotify part api nowiybru
|
| 222 |
+
/*
|
| 223 |
+
const SPOTIFY_API = {
|
| 224 |
+
BASE: 'https://api.spotify.com/v1',
|
| 225 |
+
AUTH: 'https://accounts.spotify.com/api/token',
|
| 226 |
+
CLIENT_ID: 'b0cdfaef5b0b401299244ef88df29ffb',
|
| 227 |
+
CLIENT_SECRET: '3e5949b78a214aecb2558b861911c1a9'
|
| 228 |
+
};
|
| 229 |
+
|
| 230 |
+
const FAB_DL_API = 'https://api.fabdl.com';
|
| 231 |
+
|
| 232 |
+
let spotifyToken = null;
|
| 233 |
+
let tokenExpiry = null;
|
| 234 |
+
|
| 235 |
+
async function getSpotifyToken() {
|
| 236 |
+
if (spotifyToken && Date.now() < tokenExpiry) {
|
| 237 |
+
return spotifyToken;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
try {
|
| 241 |
+
const authString = Buffer.from(`${SPOTIFY_API.CLIENT_ID}:${SPOTIFY_API.CLIENT_SECRET}`).toString('base64');
|
| 242 |
+
const response = await axios.post(SPOTIFY_API.AUTH, 'grant_type=client_credentials', {
|
| 243 |
+
headers: {
|
| 244 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
| 245 |
+
'Authorization': `Basic ${authString}`
|
| 246 |
+
}
|
| 247 |
+
});
|
| 248 |
+
spotifyToken = response.data.access_token;
|
| 249 |
+
tokenExpiry = Date.now() + (response.data.expires_in * 1000);
|
| 250 |
+
return spotifyToken;
|
| 251 |
+
} catch (error) {
|
| 252 |
+
console.error(error);
|
| 253 |
+
throw new Error('Failed to get Spotify token');
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
function formatDuration(ms) {
|
| 258 |
+
const minutes = Math.floor(ms / 60000);
|
| 259 |
+
const seconds = Math.floor((ms % 60000) / 1000);
|
| 260 |
+
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
app.get('/api/spotify', async (req, res) => {
|
| 264 |
+
try {
|
| 265 |
+
const { url, search } = req.query;
|
| 266 |
+
|
| 267 |
+
if (url) {
|
| 268 |
+
const token = await getSpotifyToken();
|
| 269 |
+
const trackId = url.split('/').pop().split('?')[0];
|
| 270 |
+
const trackResponse = await axios.get(`${SPOTIFY_API.BASE}/tracks/${trackId}`, {
|
| 271 |
+
headers: { 'Authorization': `Bearer ${token}` }
|
| 272 |
+
});
|
| 273 |
+
|
| 274 |
+
const fabResponse = await axios.get(`${FAB_DL_API}/spotify/get?url=${url}`);
|
| 275 |
+
const downloadResponse = await axios.get(
|
| 276 |
+
`${FAB_DL_API}/spotify/mp3-convert-task/${fabResponse.data.result.gid}/${fabResponse.data.result.id}`
|
| 277 |
+
);
|
| 278 |
+
|
| 279 |
+
res.json({
|
| 280 |
+
title: trackResponse.data.name,
|
| 281 |
+
artist: trackResponse.data.artists.map(a => a.name).join(', '),
|
| 282 |
+
duration: formatDuration(trackResponse.data.duration_ms),
|
| 283 |
+
cover: trackResponse.data.album.images[0]?.url,
|
| 284 |
+
downloadUrl: `${FAB_DL_API}${downloadResponse.data.result.download_url}`
|
| 285 |
+
});
|
| 286 |
+
|
| 287 |
+
} else if (search) {
|
| 288 |
+
const token = await getSpotifyToken();
|
| 289 |
+
const searchResponse = await axios.get(
|
| 290 |
+
`${SPOTIFY_API.BASE}/search?q=${encodeURIComponent(search)}&type=track&limit=10`,
|
| 291 |
+
{ headers: { 'Authorization': `Bearer ${token}` } }
|
| 292 |
+
);
|
| 293 |
+
|
| 294 |
+
const tracks = searchResponse.data.tracks.items.map(track => ({
|
| 295 |
+
id: track.id,
|
| 296 |
+
title: track.name,
|
| 297 |
+
artist: track.artists.map(a => a.name).join(', '),
|
| 298 |
+
duration: formatDuration(track.duration_ms),
|
| 299 |
+
cover: track.album.images[0]?.url,
|
| 300 |
+
url: track.external_urls.spotify
|
| 301 |
+
}));
|
| 302 |
+
|
| 303 |
+
res.json(tracks);
|
| 304 |
+
} else {
|
| 305 |
+
res.status(400).json({ error: 'Missing url or search parameter' });
|
| 306 |
+
}
|
| 307 |
+
} catch (error) {
|
| 308 |
+
console.error(error);
|
| 309 |
+
res.status(500).json({ error: 'Internal server error' });
|
| 310 |
+
}
|
| 311 |
+
});
|
| 312 |
+
*/
|
| 313 |
+
app.listen(PORT, () => {
|
| 314 |
+
console.log(`Server running at http://localhost:${PORT}`);
|
| 315 |
+
});
|