Skip to content

Commit

Permalink
Fix requests | Add file
Browse files Browse the repository at this point in the history
  • Loading branch information
inventionpro committed Sep 12, 2024
1 parent 72cd795 commit 7176e27
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
49 changes: 49 additions & 0 deletions apis/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
path: "/file",
info: "Get a file from a url",
type: "get",
params: [
{
name: 'url',
required: true,
default: 'fsh.plus'
}
],
category: "text",

async execute(req, res) {
let uri = req.query["url"];
if (!uri) {
res.error('You must provide an url')
return;
}
if (!uri.includes('://')) {
uri = 'https://'+uri
}
try {
let request = await fetch(uri, {
follow: 20,
redirect: "follow",
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Fsh (Api - user: " + req.clientIp + ")",
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",
"accept-language": "en;q=1.0",
"sec-ch-ua": '"Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "none",
"sec-fetch-user": "?1",
"sec-gpc": "1",
}
});
request = await request.arrayBuffer();

res.header("Content-Type", 'application/octet-stream');
res.send(Buffer.from(request));
} catch (err) {
res.error('Could not get', 500);
}
}
};
4 changes: 1 addition & 3 deletions apis/html.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const https = require("https");

function pretty(text) {
let u = String(text) || "";
if (!u.includes("\n")) {
Expand All @@ -15,7 +13,7 @@ function pretty(text) {

module.exports = {
path: "/html",
info: "Gets the html of a url (use www. for better results) (set linkback to true for relative paths to become full)",
info: "Gets the html of a url (use www. for better results) (linkback for relative to full paths)",
type: "get",
params: [
{
Expand Down
2 changes: 1 addition & 1 deletion html/requests.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ <h1 style="margin:0;text-align:center;">Fsh endpoints</h1>
return 'src="'+match.split('"')[1].split(', ').slice(-1)[0].split(',').slice(-1)[0].split(' ')[0]+'"';
})
.replaceAll(/(href|src)="(?!http:\/\/|https:\/\/).+?"/g, function(match) {
return match.split('"')[0] + '"' + (new URL(match.split('"')[1], uri)) + '"';
return match.split('"')[0] + '"' + (new URL(match.split('"')[1], url)) + '"';
})
.replace('data-color-mode="auto"','data-color-mode="dark"');

Expand Down

0 comments on commit 7176e27

Please sign in to comment.