Update index.js
Browse files
index.js
CHANGED
|
@@ -12,45 +12,41 @@ app.use('/temp', express.static(tempDir));
|
|
| 12 |
app.use(express.json());
|
| 13 |
|
| 14 |
app.get("/", (req, res) => {
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
});
|
| 25 |
|
| 26 |
async function downloadImage(url) {
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
throw error;
|
| 38 |
-
}
|
| 39 |
}
|
| 40 |
|
| 41 |
async function downloadVideo(url) {
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
throw error;
|
| 53 |
-
}
|
| 54 |
}
|
| 55 |
|
| 56 |
const generateRandomIP = () => {
|
|
@@ -271,74 +267,68 @@ async function igdl4(url) {
|
|
| 271 |
}
|
| 272 |
|
| 273 |
const getInstagramDownloadLinks = async (url) => {
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
};
|
| 291 |
|
| 292 |
app.get('/igdl', async (req, res) => {
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
}
|
| 307 |
-
let result = await getInstagramDownloadLinks(url);
|
| 308 |
-
let result_upload = {
|
| 309 |
-
title: result?.title || 'untitled',
|
| 310 |
-
media: []
|
| 311 |
-
}
|
| 312 |
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
}
|
| 339 |
});
|
| 340 |
|
| 341 |
-
|
|
|
|
| 342 |
app.listen(PORT, () => {
|
| 343 |
-
|
| 344 |
-
});
|
|
|
|
| 12 |
app.use(express.json());
|
| 13 |
|
| 14 |
app.get("/", (req, res) => {
|
| 15 |
+
res.type("json");
|
| 16 |
+
const keluaran = {
|
| 17 |
+
success: true,
|
| 18 |
+
author: "Nex",
|
| 19 |
+
data: {
|
| 20 |
+
igdl: "/igdl"
|
| 21 |
+
},
|
| 22 |
+
};
|
| 23 |
+
res.send(keluaran);
|
| 24 |
});
|
| 25 |
|
| 26 |
async function downloadImage(url) {
|
| 27 |
+
try {
|
| 28 |
+
const response = await axios.get(url, { responseType: 'arraybuffer' });
|
| 29 |
+
const randomCode = Math.random().toString(36).substring(7);
|
| 30 |
+
const imagePath = `downloaded_image_${randomCode}.png`;
|
| 31 |
+
fs.writeFileSync(path.join(tempDir, "/" + imagePath), Buffer.from(response.data, 'binary'));
|
| 32 |
+
return imagePath;
|
| 33 |
+
} catch (error) {
|
| 34 |
+
console.error('Error downloading image:', error.message);
|
| 35 |
+
throw error;
|
| 36 |
+
}
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
async function downloadVideo(url) {
|
| 40 |
+
try {
|
| 41 |
+
const response = await axios.get(url, { responseType: 'arraybuffer' });
|
| 42 |
+
const randomCode = Math.random().toString(36).substring(7);
|
| 43 |
+
const videoPath = `downloaded_video_${randomCode}.mp4`;
|
| 44 |
+
fs.writeFileSync(path.join(tempDir, "/" + videoPath), Buffer.from(response.data, 'binary'));
|
| 45 |
+
return videoPath;
|
| 46 |
+
} catch (error) {
|
| 47 |
+
console.error('Error downloading video:', error.message);
|
| 48 |
+
throw error;
|
| 49 |
+
}
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
|
| 52 |
const generateRandomIP = () => {
|
|
|
|
| 267 |
}
|
| 268 |
|
| 269 |
const getInstagramDownloadLinks = async (url) => {
|
| 270 |
+
let result = await igdl1(url);
|
| 271 |
+
if (!result) {
|
| 272 |
+
result = await igdl2(url);
|
| 273 |
+
}
|
| 274 |
+
if (!result) {
|
| 275 |
+
result = await igdl3(url);
|
| 276 |
+
}
|
| 277 |
+
if (!result) {
|
| 278 |
+
result = await igdl4(url);
|
| 279 |
+
}
|
| 280 |
+
if (!result) {
|
| 281 |
+
result = {
|
| 282 |
+
message: "all server error"
|
| 283 |
+
};
|
| 284 |
+
}
|
| 285 |
+
return result;
|
| 286 |
};
|
| 287 |
|
| 288 |
app.get('/igdl', async (req, res) => {
|
| 289 |
+
try {
|
| 290 |
+
const { url } = req.query;
|
| 291 |
+
if (!url) {
|
| 292 |
+
return res.status(400).json({ error: 'Parameter url is required' });
|
| 293 |
+
}
|
| 294 |
+
if (!/https?:\/\/(www\.)?instagram\.com\/(p|reel|tv)/.test(url)) {
|
| 295 |
+
return res.status(400).json({ error: "Example: https://www.instagram.com/p/Cz1fTwMJFpx/?igsh=MXRrY2g4eWNucGoyZg==" });
|
| 296 |
+
}
|
| 297 |
+
let result = await getInstagramDownloadLinks(url);
|
| 298 |
+
let result_upload = {
|
| 299 |
+
title: result?.title || 'untitled',
|
| 300 |
+
media: []
|
| 301 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
+
for (let item of result.urls) {
|
| 304 |
+
if (item.type === "image") {
|
| 305 |
+
let unduh = await downloadImage(item.url);
|
| 306 |
+
result_upload.media.push({ type: item.type, path: unduh, url_path: `http://${process.env.SPACE_HOST}/temp/${path.basename(unduh)}` });
|
| 307 |
+
} else if (item.type === "video") {
|
| 308 |
+
let unduh = await downloadVideo(item.url);
|
| 309 |
+
result_upload.media.push({ type: item.type, path: unduh, url_path: `http://${process.env.SPACE_HOST}/temp/${path.basename(unduh)}` });
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
res.json(result_upload);
|
| 314 |
+
|
| 315 |
+
for (let item of result_upload.media) {
|
| 316 |
+
try {
|
| 317 |
+
await new Promise(resolve => setTimeout(resolve, 10 * 60 * 1000)); // 10 minutes
|
| 318 |
+
await fs.unlink(item.path);
|
| 319 |
+
console.log(`File ${item.path} deleted.`);
|
| 320 |
+
} catch (error) {
|
| 321 |
+
console.error(`Error deleting file ${item.path}:`, error);
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
} catch (error) {
|
| 325 |
+
console.error('Error processing request:', error);
|
| 326 |
+
res.status(500).json({ error: 'Failed to process request\n' + error});
|
| 327 |
+
}
|
|
|
|
| 328 |
});
|
| 329 |
|
| 330 |
+
|
| 331 |
+
const hostname = `http://${process.env.SPACE_HOST}`; // Ganti dengan host yang sesuai
|
| 332 |
app.listen(PORT, () => {
|
| 333 |
+
console.log(`Server is running on http://${hostname}:${PORT}`);
|
| 334 |
+
});
|