Update app.js
Browse files
app.js
CHANGED
|
@@ -4,6 +4,7 @@ import cors from 'cors';
|
|
| 4 |
import axios from 'axios';
|
| 5 |
import dotenv from 'dotenv';
|
| 6 |
import os from 'os';
|
|
|
|
| 7 |
|
| 8 |
dotenv.config();
|
| 9 |
const app = express();
|
|
@@ -151,6 +152,37 @@ app.get('/ace', async (req, res) => {
|
|
| 151 |
}
|
| 152 |
});
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
const PORT = process.env.PORT || 7860;
|
| 155 |
|
| 156 |
app.listen(PORT, async () => {
|
|
|
|
| 4 |
import axios from 'axios';
|
| 5 |
import dotenv from 'dotenv';
|
| 6 |
import os from 'os';
|
| 7 |
+
import { io } from "socket.io-client";
|
| 8 |
|
| 9 |
dotenv.config();
|
| 10 |
const app = express();
|
|
|
|
| 152 |
}
|
| 153 |
});
|
| 154 |
|
| 155 |
+
// Fungsi sederhana untuk menghasilkan ID spinner
|
| 156 |
+
const genSpinner = () => Math.random().toString(36).substring(2, 10);
|
| 157 |
+
|
| 158 |
+
// Rute API untuk /ytdl
|
| 159 |
+
app.get("/y232", async (req, res) => {
|
| 160 |
+
const url = req.query.url;
|
| 161 |
+
if (!url) return res.status(400).send({ error: "URL is required!" });
|
| 162 |
+
|
| 163 |
+
const spinnerid = genSpinner();
|
| 164 |
+
const socket = io("https://api.y232.live");
|
| 165 |
+
|
| 166 |
+
// Emit event "limits"
|
| 167 |
+
socket.emit("limits", {});
|
| 168 |
+
|
| 169 |
+
// Emit event "getInfoEvent" dengan data
|
| 170 |
+
const data = { url, spinnerid, method: "stream" };
|
| 171 |
+
socket.emit("getInfoEvent", data);
|
| 172 |
+
|
| 173 |
+
// Tangkap event "done"
|
| 174 |
+
socket.on("done", (response) => {
|
| 175 |
+
res.status(200).send({ success: true, data: response });
|
| 176 |
+
socket.close(); // Tutup koneksi socket
|
| 177 |
+
});
|
| 178 |
+
|
| 179 |
+
// Tangkap event error dari socket
|
| 180 |
+
socket.on("error", (err) => {
|
| 181 |
+
res.status(500).send({ success: false, error: err.message });
|
| 182 |
+
socket.close();
|
| 183 |
+
});
|
| 184 |
+
});
|
| 185 |
+
|
| 186 |
const PORT = process.env.PORT || 7860;
|
| 187 |
|
| 188 |
app.listen(PORT, async () => {
|