74 lines
2.2 KiB
JavaScript
74 lines
2.2 KiB
JavaScript
const axios = require("axios");
|
|
const lib = require("../lib");
|
|
|
|
module.exports = {
|
|
get: get,
|
|
hostnames: ["gofile.io"],
|
|
tests: []
|
|
}
|
|
|
|
async function get(url, options) {
|
|
let id = url.split("/d/")[1].split("/")[0].split("?")[0];
|
|
let headers = lib.defaultHeaders;
|
|
console.log(headers);
|
|
|
|
headers["Accept"] = "*/*";
|
|
headers["Origin"] = "https://gofile.io";
|
|
headers["Sec-Fetch-Dest"] = "empty";
|
|
headers["Sec-Fetch-Mode"] = "cors";
|
|
headers["Sec-Fetch-Site"] = "same-site";
|
|
headers["TE"] = "trailers";
|
|
|
|
let token = await getToken(headers, options);
|
|
lib.log(`gofile`, `Got token:`, [token]);
|
|
headers["Cookie"] = `accountToken=${token}`;
|
|
|
|
lib.log(`gofile`, `Sending API request...`, [])
|
|
let resp = await axios({
|
|
headers: headers,
|
|
url: `https://api.gofile.io/getContent?contentId=${id}&token=${token}&websiteToken=12345`
|
|
});
|
|
|
|
if (resp.data.status !== "ok") throw new Error("Error getting file data.");
|
|
let data = resp.data?.data;
|
|
|
|
if (data.contents.length > 1) throw new Error("Cannot parse folders with more than 1 file at the moment.");
|
|
|
|
headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
|
|
headers["Cache-Control"] = "no-cache";
|
|
headers["Sec-Fetch-Dest"] = "document";
|
|
headers["Sec-Fetch-Mode"] = "navigate";
|
|
headers["Sec-Fetch-Site"] = "none";
|
|
headers["Pragma"] = "no-cache";
|
|
delete headers["Origin"];
|
|
|
|
headers = JSON.parse(JSON.stringify(headers));
|
|
|
|
return {
|
|
axiosData: {
|
|
headers: headers,
|
|
url: data.contents[data.childs[0]].directLink
|
|
},
|
|
metadata: {
|
|
fileName: data.contents[data.childs[0]].directLink.split(`${data.contents[data.childs[0]].id}/`)[1]
|
|
}
|
|
}
|
|
}
|
|
|
|
async function getToken(headers, options) {
|
|
lib.log(`gofile`, `Creating token...`, [], true, options);
|
|
let resp = await axios({
|
|
headers: headers,
|
|
url: `https://api.gofile.io/createAccount`
|
|
});
|
|
|
|
if (resp.data?.status !== "ok") throw new Error("Could not get token.");
|
|
let token = resp.data.data.token;
|
|
|
|
resp = await axios({
|
|
headers: headers,
|
|
url: `https://api.gofile.io/getAccountDetails?token=${token}`
|
|
});
|
|
|
|
return token;
|
|
} |