Update app.js
Browse files
app.js
CHANGED
|
@@ -9,29 +9,37 @@ app.get("/login", async (req, res) => {
|
|
| 9 |
return res.status(400).json({ error: "Missing ?url=" });
|
| 10 |
}
|
| 11 |
|
| 12 |
-
// Extract tgWebAppData
|
| 13 |
const urlObj = new URL(url);
|
| 14 |
const tgWebAppData = urlObj.hash.split("tgWebAppData=")[1]?.split("&")[0];
|
| 15 |
if (!tgWebAppData) {
|
| 16 |
return res.status(400).json({ error: "Invalid tgWebAppData" });
|
| 17 |
}
|
| 18 |
|
| 19 |
-
// Decode twice
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
const params = new URLSearchParams(
|
| 24 |
|
| 25 |
-
// Build initData
|
| 26 |
-
const
|
| 27 |
-
`auth_date=${params.get("auth_date")}\
|
| 28 |
-
params.get("
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
// Send to AnimeKombat API (stringified array!)
|
| 32 |
const response = await axios.post(
|
| 33 |
"https://be.animekombat.com/api/auth/login",
|
| 34 |
-
{ initData:
|
| 35 |
{
|
| 36 |
headers: {
|
| 37 |
Accept: "application/json, text/plain, */*",
|
|
@@ -41,10 +49,10 @@ app.get("/login", async (req, res) => {
|
|
| 41 |
);
|
| 42 |
|
| 43 |
res.json({
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
user: JSON.parse(params.get("user")),
|
| 48 |
});
|
| 49 |
} catch (err) {
|
| 50 |
console.error(err);
|
|
@@ -57,5 +65,5 @@ app.get("/login", async (req, res) => {
|
|
| 57 |
});
|
| 58 |
|
| 59 |
app.listen(7860, () => {
|
| 60 |
-
console.log("Server running
|
| 61 |
});
|
|
|
|
| 9 |
return res.status(400).json({ error: "Missing ?url=" });
|
| 10 |
}
|
| 11 |
|
| 12 |
+
// Extract tgWebAppData
|
| 13 |
const urlObj = new URL(url);
|
| 14 |
const tgWebAppData = urlObj.hash.split("tgWebAppData=")[1]?.split("&")[0];
|
| 15 |
if (!tgWebAppData) {
|
| 16 |
return res.status(400).json({ error: "Invalid tgWebAppData" });
|
| 17 |
}
|
| 18 |
|
| 19 |
+
// Decode twice if needed
|
| 20 |
+
let decoded = decodeURIComponent(tgWebAppData);
|
| 21 |
+
try {
|
| 22 |
+
decoded = decodeURIComponent(decoded);
|
| 23 |
+
} catch (_) {}
|
| 24 |
|
| 25 |
+
const params = new URLSearchParams(decoded);
|
| 26 |
|
| 27 |
+
// Build initData pieces
|
| 28 |
+
const block =
|
| 29 |
+
`auth_date=${params.get("auth_date")}\n` +
|
| 30 |
+
`chat_instance=${params.get("chat_instance")}\n` +
|
| 31 |
+
`chat_type=${params.get("chat_type")}\n` +
|
| 32 |
+
`signature=${params.get("signature")}\n` +
|
| 33 |
+
`user=${params.get("user")}`;
|
| 34 |
+
|
| 35 |
+
const hash = params.get("hash");
|
| 36 |
+
|
| 37 |
+
// Here: wrap array in JSON.stringify, THEN stringify again
|
| 38 |
+
const initDataString = JSON.stringify([block, hash]);
|
| 39 |
|
|
|
|
| 40 |
const response = await axios.post(
|
| 41 |
"https://be.animekombat.com/api/auth/login",
|
| 42 |
+
{ initData: initDataString }, // pass as string, not array
|
| 43 |
{
|
| 44 |
headers: {
|
| 45 |
Accept: "application/json, text/plain, */*",
|
|
|
|
| 49 |
);
|
| 50 |
|
| 51 |
res.json({
|
| 52 |
+
token: response.data.access_token,
|
| 53 |
+
type: response.data.token_type,
|
| 54 |
+
expires: response.data.expires_in,
|
| 55 |
+
user: JSON.parse(params.get("user")),
|
| 56 |
});
|
| 57 |
} catch (err) {
|
| 58 |
console.error(err);
|
|
|
|
| 65 |
});
|
| 66 |
|
| 67 |
app.listen(7860, () => {
|
| 68 |
+
console.log("Server running at http://localhost:3000");
|
| 69 |
});
|