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