Spaces:
Paused
Paused
- fnc/apis.js +47 -88
fnc/apis.js
CHANGED
|
@@ -1,22 +1,13 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
}
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
const ig = require("../lib/ig");
|
| 12 |
-
const {
|
| 13 |
-
spotifyTrack,
|
| 14 |
-
spotifyPlaylist
|
| 15 |
-
} = require("../lib/spotify");
|
| 16 |
-
const yt = require("../lib/ytdl");
|
| 17 |
-
const kwaii = require("../lib/kuaishou");
|
| 18 |
-
const qq = require("../lib/qqm");
|
| 19 |
-
const fesnuk = require("../lib/fb");
|
| 20 |
|
| 21 |
const IGr = /^(https?:\/\/)?(www\.)?instagram\.com\/.*$/i;
|
| 22 |
const SCr = /^(https?:\/\/)?(www\.|m\.)?(on\.|)soundcloud\.com\/[^\s]+$/i;
|
|
@@ -27,19 +18,9 @@ const YTr = /(?:http(?:s|):\/\/|)(?:(?:www\.|)?(?:music\.)?youtube(?:-nocookie|)
|
|
| 27 |
const Kr = /^https?:\/\/v\.kuaishou\.com\/[a-zA-Z0-9]+$/i;
|
| 28 |
const QQMr = /^https:\/\/c6\.y\.qq\.com\/base\/fcgi-bin\/u\?__=[a-zA-Z0-9]+$/;
|
| 29 |
const TwTr = /^https?:\/\/(www\.)?(twitter|x)\.com\/[^\/]+\/status\/\d+\/?$/i;
|
| 30 |
-
|
| 31 |
-
const allowX = [
|
| 32 |
-
|
| 33 |
-
"www.x.com",
|
| 34 |
-
"twitter.com",
|
| 35 |
-
"www.twitter.com"
|
| 36 |
-
]
|
| 37 |
-
const allowedFacebookHosts = [
|
| 38 |
-
"facebook.com",
|
| 39 |
-
"www.facebook.com",
|
| 40 |
-
"m.facebook.com",
|
| 41 |
-
"fb.com"
|
| 42 |
-
];
|
| 43 |
|
| 44 |
/**
|
| 45 |
* @param {string} response
|
|
@@ -50,24 +31,18 @@ async function checkCaptcha(response) {
|
|
| 50 |
url.searchParams.set("secret", "6Ldr6_cqAAAAAApmQtOImEUOVLq8cAIFUZuuRSrM");
|
| 51 |
url.searchParams.set("response", response);
|
| 52 |
|
| 53 |
-
const res = await fetch(url, {
|
| 54 |
-
method: "POST"
|
| 55 |
-
});
|
| 56 |
-
|
| 57 |
return await res.json();
|
| 58 |
}
|
| 59 |
|
| 60 |
/** @type {Map<string, any>} */
|
| 61 |
const yt_info = new Map();
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
return res.status(400).json({
|
| 69 |
-
error: "URL diperlukan."
|
| 70 |
-
});
|
| 71 |
}
|
| 72 |
|
| 73 |
let parsedUrl;
|
|
@@ -77,89 +52,73 @@ module.exports = async function(req, res) {
|
|
| 77 |
return res.status(400).json({ error: "URL tidak valid." });
|
| 78 |
}
|
| 79 |
|
| 80 |
-
|
| 81 |
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
| 82 |
-
|
| 83 |
}
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
}
|
| 91 |
|
| 92 |
console.log(parsedUrl);
|
| 93 |
let ress;
|
| 94 |
try {
|
| 95 |
-
if(IGr.test(url)) {
|
| 96 |
ress = await ig(url);
|
| 97 |
ress.type = "instagram";
|
| 98 |
-
} else if(SCr.test(url)) {
|
| 99 |
ress = await soundcloud(url);
|
| 100 |
ress.type = "soundcloud";
|
| 101 |
-
} else if(Ser.test(url)) {
|
| 102 |
ress = await spotifyPlaylist(url);
|
| 103 |
ress.type = "spotifyPlaylist";
|
| 104 |
-
} else if(TTr.test(url)) {
|
| 105 |
ress = await ttt(url);
|
| 106 |
ress.type = "tiktok";
|
| 107 |
-
} else if(Sr.test(url)) {
|
| 108 |
ress = await spotifyTrack(url);
|
| 109 |
ress.type = "spotify";
|
| 110 |
-
} else if(QQMr.test(url)) {
|
| 111 |
ress = await qq(url);
|
| 112 |
ress.type = "qq";
|
| 113 |
-
} else if(allowedFacebookHosts.includes(parsedUrl.hostname)) {
|
| 114 |
ress = await fesnuk(url);
|
| 115 |
-
ress.type = "facebook"
|
| 116 |
-
} else if(allowX.includes(parsedUrl.hostname)) {
|
| 117 |
ress = await twit(url);
|
| 118 |
-
ress.type = "twitter"
|
| 119 |
-
} else if(YTr.test(url)) {
|
| 120 |
-
const format = String(
|
| 121 |
-
req.headers["x-selected-format"] ||
|
| 122 |
-
""
|
| 123 |
-
).trim();
|
| 124 |
const [, id] = YTr.exec(url);
|
| 125 |
|
| 126 |
-
if(!format) {
|
| 127 |
-
ress = (
|
| 128 |
-
yt_info.has(id)
|
| 129 |
-
? yt_info.get(id)
|
| 130 |
-
: await yt.getInfo(url)
|
| 131 |
-
);
|
| 132 |
yt_info.set(id, ress);
|
| 133 |
ress.type = "yt_info";
|
| 134 |
} else {
|
| 135 |
-
const type =
|
| 136 |
-
format === "audio"
|
| 137 |
-
? "Audio"
|
| 138 |
-
: "Video"
|
| 139 |
-
);
|
| 140 |
ress = await yt[`get${type}`](url, format);
|
| 141 |
}
|
| 142 |
-
} else if(Kr.test(url)) {
|
| 143 |
ress = await kwaii(url);
|
| 144 |
ress.type = "kwaii";
|
| 145 |
} else {
|
| 146 |
-
ress = {
|
| 147 |
-
status: 400,
|
| 148 |
-
message: "failed request"
|
| 149 |
-
};
|
| 150 |
}
|
| 151 |
} catch (e) {
|
| 152 |
console.log(e);
|
| 153 |
-
ress = {
|
| 154 |
-
status: 404,
|
| 155 |
-
message: e.message
|
| 156 |
-
};
|
| 157 |
}
|
| 158 |
|
| 159 |
-
if(Buffer.isBuffer(ress)) {
|
| 160 |
const { mime } = await fileTypeFromBuffer(ress);
|
| 161 |
res.setHeader("Content-Type", mime);
|
| 162 |
res.setHeader("Content-Length", ress.length);
|
| 163 |
}
|
|
|
|
| 164 |
return res.status(ress.status || 200).send(ress.data || ress);
|
| 165 |
-
}
|
|
|
|
| 1 |
+
import { fileTypeFromBuffer } from "file-type";
|
| 2 |
+
import twit from "../lib/twt.js";
|
| 3 |
+
import { ttt } from "../lib/skrep.js";
|
| 4 |
+
import { soundcloud } from "../lib/soundcloud.js";
|
| 5 |
+
import ig from "../lib/ig.js";
|
| 6 |
+
import { spotifyTrack, spotifyPlaylist } from "../lib/spotify.js";
|
| 7 |
+
import yt from "../lib/ytdl.js";
|
| 8 |
+
import kwaii from "../lib/kuaishou.js";
|
| 9 |
+
import qq from "../lib/qqm.js";
|
| 10 |
+
import fesnuk from "../lib/fb.js";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
const IGr = /^(https?:\/\/)?(www\.)?instagram\.com\/.*$/i;
|
| 13 |
const SCr = /^(https?:\/\/)?(www\.|m\.)?(on\.|)soundcloud\.com\/[^\s]+$/i;
|
|
|
|
| 18 |
const Kr = /^https?:\/\/v\.kuaishou\.com\/[a-zA-Z0-9]+$/i;
|
| 19 |
const QQMr = /^https:\/\/c6\.y\.qq\.com\/base\/fcgi-bin\/u\?__=[a-zA-Z0-9]+$/;
|
| 20 |
const TwTr = /^https?:\/\/(www\.)?(twitter|x)\.com\/[^\/]+\/status\/\d+\/?$/i;
|
| 21 |
+
|
| 22 |
+
const allowX = ["x.com", "www.x.com", "twitter.com", "www.twitter.com"];
|
| 23 |
+
const allowedFacebookHosts = ["facebook.com", "www.facebook.com", "m.facebook.com", "fb.com"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
/**
|
| 26 |
* @param {string} response
|
|
|
|
| 31 |
url.searchParams.set("secret", "6Ldr6_cqAAAAAApmQtOImEUOVLq8cAIFUZuuRSrM");
|
| 32 |
url.searchParams.set("response", response);
|
| 33 |
|
| 34 |
+
const res = await fetch(url, { method: "POST" });
|
|
|
|
|
|
|
|
|
|
| 35 |
return await res.json();
|
| 36 |
}
|
| 37 |
|
| 38 |
/** @type {Map<string, any>} */
|
| 39 |
const yt_info = new Map();
|
| 40 |
+
|
| 41 |
+
export default async function(req, res) {
|
| 42 |
+
const { url } = req.body;
|
| 43 |
+
|
| 44 |
+
if (!url) {
|
| 45 |
+
return res.status(400).json({ error: "URL diperlukan." });
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
let parsedUrl;
|
|
|
|
| 52 |
return res.status(400).json({ error: "URL tidak valid." });
|
| 53 |
}
|
| 54 |
|
| 55 |
+
const authHeader = req.headers.authorization;
|
| 56 |
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
| 57 |
+
return res.status(401).json({ message: "Unauthorized: Token is missing or invalid" });
|
| 58 |
}
|
| 59 |
|
| 60 |
+
const token = authHeader.split(" ")[1];
|
| 61 |
+
const { success: isValid, "error-codes": errors } = await checkCaptcha(token);
|
| 62 |
|
| 63 |
+
if (!isValid) {
|
| 64 |
+
return res.status(400).send({ message: "Invalid captcha", errors });
|
| 65 |
}
|
| 66 |
|
| 67 |
console.log(parsedUrl);
|
| 68 |
let ress;
|
| 69 |
try {
|
| 70 |
+
if (IGr.test(url)) {
|
| 71 |
ress = await ig(url);
|
| 72 |
ress.type = "instagram";
|
| 73 |
+
} else if (SCr.test(url)) {
|
| 74 |
ress = await soundcloud(url);
|
| 75 |
ress.type = "soundcloud";
|
| 76 |
+
} else if (Ser.test(url)) {
|
| 77 |
ress = await spotifyPlaylist(url);
|
| 78 |
ress.type = "spotifyPlaylist";
|
| 79 |
+
} else if (TTr.test(url)) {
|
| 80 |
ress = await ttt(url);
|
| 81 |
ress.type = "tiktok";
|
| 82 |
+
} else if (Sr.test(url)) {
|
| 83 |
ress = await spotifyTrack(url);
|
| 84 |
ress.type = "spotify";
|
| 85 |
+
} else if (QQMr.test(url)) {
|
| 86 |
ress = await qq(url);
|
| 87 |
ress.type = "qq";
|
| 88 |
+
} else if (allowedFacebookHosts.includes(parsedUrl.hostname)) {
|
| 89 |
ress = await fesnuk(url);
|
| 90 |
+
ress.type = "facebook";
|
| 91 |
+
} else if (allowX.includes(parsedUrl.hostname)) {
|
| 92 |
ress = await twit(url);
|
| 93 |
+
ress.type = "twitter";
|
| 94 |
+
} else if (YTr.test(url)) {
|
| 95 |
+
const format = String(req.headers["x-selected-format"] || "").trim();
|
|
|
|
|
|
|
|
|
|
| 96 |
const [, id] = YTr.exec(url);
|
| 97 |
|
| 98 |
+
if (!format) {
|
| 99 |
+
ress = yt_info.has(id) ? yt_info.get(id) : await yt.getInfo(url);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
yt_info.set(id, ress);
|
| 101 |
ress.type = "yt_info";
|
| 102 |
} else {
|
| 103 |
+
const type = format === "audio" ? "Audio" : "Video";
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
ress = await yt[`get${type}`](url, format);
|
| 105 |
}
|
| 106 |
+
} else if (Kr.test(url)) {
|
| 107 |
ress = await kwaii(url);
|
| 108 |
ress.type = "kwaii";
|
| 109 |
} else {
|
| 110 |
+
ress = { status: 400, message: "failed request" };
|
|
|
|
|
|
|
|
|
|
| 111 |
}
|
| 112 |
} catch (e) {
|
| 113 |
console.log(e);
|
| 114 |
+
ress = { status: 404, message: e.message };
|
|
|
|
|
|
|
|
|
|
| 115 |
}
|
| 116 |
|
| 117 |
+
if (Buffer.isBuffer(ress)) {
|
| 118 |
const { mime } = await fileTypeFromBuffer(ress);
|
| 119 |
res.setHeader("Content-Type", mime);
|
| 120 |
res.setHeader("Content-Length", ress.length);
|
| 121 |
}
|
| 122 |
+
|
| 123 |
return res.status(ress.status || 200).send(ress.data || ress);
|
| 124 |
+
}
|