fix double require, improve tests

pull/4/head
aria 2 months ago
parent bd5c01d913
commit 0f40cd223e
Signed by: a
GPG Key ID: E851AE999FFCBC37
  1. 7
      extractor.js
  2. 7
      lib.js
  3. 37
      tests.js

@ -6,11 +6,12 @@ module.exports = {
if (h.startsWith("www.")) h = h.substring(4);
let d = await fs.readdir(`${__dirname}/extractors`);
for (let i = 0; i < d.length; i++) {
if (!(await require(`./extractors/${d[i]}`)).hostnames) {
console.log(`extraction/${d[i]} is broken.`)
let r = await require(`./extractors/${d[i]}`);
if (!r.hostnames) {
console.log(`extractors/${d[i]} is broken.`)
continue;
}
if ((await require(`./extractors/${d[i]}`)).hostnames.includes(h)) return d[i];
if (r.hostnames.includes(h)) return d[i];
}
return "generic";
},

@ -9,7 +9,7 @@ if (!fs.existsSync("./config.json")) {
const config = require("./config.json");
const two = require("2captcha");
const {MongoClient} = require("mongodb");
const client = new MongoClient(config["db"]["url"]);
let client, db, links;
(async function() {
if (config.db?.active !== false) {
@ -19,15 +19,16 @@ const client = new MongoClient(config["db"]["url"]);
console.log("[bifm] Please restart your BIFM instance.");
process.exit();
}
client = new MongoClient(config["db"]["url"]);
await client.connect();
db = client.db("bifm");
links = db.collection("links");
if (config.debug == true) console.log(`[db] Connected to MongoDB database.`);
} else {
if (config.debug == true) console.log(`[db] Not connecting to MongoDB database.`);
}
})();
const db = client.db("bifm");
const links = db.collection("links");
module.exports = {
get: async function(url, opt) {

@ -2,25 +2,25 @@ const lib = require("./lib");
// add a new extractor? add it to the test list.
const examples = [
{ extractor: "1bit.space", link: "https://1bit.space/FVJcWHr", expected: "https://mega.nz/#F!Xe4kVIII!z7WAxz65DzBhe6d1Cx_xHg" },
{ extractor: "1link.club", link: "http://1link.club/77679" },
{ extractor: "bc.vc", link: "https://bc.vc/vQesLIh", expected: "https://universal-bypass.org/" },
{ extractor: "boost.ink", link: "https://boost.ink/c5bba" },
{ extractor: "boostme.link", link: "https://boostme.link/iX9Krf" },
{ extractor: "cpmlink.net", link: "https://cpmlink.net/i7FyAQ" },
{ extractor: "cshort.org", link: "https://cshort.org/8i8dwPx0" },
{ extractor: "exe.io", link: "https://exe.io/ZaKsUgDc" },
{ extractor: "ity.im", link: "http://ity.im/1QZh2" },
{ extractor: "karung.in", link: "http://karung.in/Gyucc", expected: "https://drive.google.com/uc?id=0B263gKU-C09_WW5rbURLeXN5QXc&export=download"},
{ link: "https://1bit.space/FVJcWHr", expected: "https://mega.nz/#F!Xe4kVIII!z7WAxz65DzBhe6d1Cx_xHg" },
{ link: "http://1link.club/77679" },
{ link: "https://bc.vc/vQesLIh", expected: "https://universal-bypass.org/" },
{ link: "https://boost.ink/c5bba" },
{ link: "https://boostme.link/iX9Krf" },
{ link: "https://cpmlink.net/i7FyAQ" },
{ link: "https://cshort.org/8i8dwPx0" },
{ link: "https://exe.io/ZaKsUgDc" },
{ link: "http://ity.im/1QZh2" },
{ link: "http://karung.in/Gyucc", expected: "https://drive.google.com/uc?id=0B263gKU-C09_WW5rbURLeXN5QXc&export=download"},
{ extractor: "linkvertise.com (redirect)", link: "https://linkvertise.com/431184/roblox-scripts-website", expected: "https://tobirbxscripts.blogspot.com/" }, // (redirect) is there because there are two types of links on linkvertise, a paste and a redirect
{ extractor: "lnk.parts", link: "https://lnkload.com/2z8aF" },
{ extractor: "lnk2.cc", link: "https://lnk2.cc/wd1J1" },
{ extractor: "myl.li", link: "https://myl.li/NOEgI6aOp3bF" },
{ extractor: "oke.io", link: "https://oke.io/D3wL", expected: "https://mega.nz/#!TlkjwLrb!jj8GVmZJp1EmmSInnQ4FNsdmb4qq_Pp0b5IAJ5ik8u8" },
{ extractor: "ouo.io", link: "https://ouo.io/2dktqo" },
{ link: "https://lnkload.com/2z8aF" },
{ link: "https://lnk2.cc/wd1J1" },
{ link: "https://myl.li/NOEgI6aOp3bF" },
{ link: "https://oke.io/D3wL", expected: "https://mega.nz/#!TlkjwLrb!jj8GVmZJp1EmmSInnQ4FNsdmb4qq_Pp0b5IAJ5ik8u8" },
{ link: "https://ouo.io/2dktqo" },
{ extractor: "sh.st", link: "http://ceesty.com/es47QR" },
{ extractor: "show.co", link: "https://show.co/HQrPtta", expected: "https://universal-bypass.org" },
{ extractor: "social-unlock.com", link: "https://social-unlock.com/417pK" },
{ link: "https://show.co/HQrPtta", expected: "https://universal-bypass.org" },
{ link: "https://social-unlock.com/417pK" },
{ extractor: "adf.ly", link: "http://usheethe.com/T3F5" },
{ extractor: "WPSafelink", link: "https://demo-safelink.themeson.com/template1/?f7fbb8af", expected: "https://themeson.com/safelink/" }
];
@ -28,7 +28,7 @@ const examples = [
console.log("Beginning extractor tests...\n");
if (process.argv[2]) {
let intForm = parseInt(process.argv[2])
if (intForm!=process.argv[2]) intForm = examples.findIndex(e => e.extractor==process.argv[2])
if (intForm!=process.argv[2]) intForm = examples.findIndex(e => (e.extractor || new URL(e.link).hostname)==process.argv[2])
run(intForm);
} else {
run(0);
@ -41,6 +41,7 @@ async function run(i) {
process.exit();
}
let name = (examples[i].extractor || new URL(e.link).hostname);
console.log(`- Testing "${examples[i].extractor}" (${i}) extractor...\n`);
try {

Loading…
Cancel
Save