Waad / api /index.js
Epikcoder
yum
825f700
import { config } from 'dotenv'
config()
import express from 'express'
import cors from 'cors'
import axios from 'axios'
import { rateLimit } from 'express-rate-limit'
const app = express()
const port = process.env.SERVER_PORT || process.env.SERVER_PORT || 7860
// import {exec} from 'child_process'
const link_twt = "https://raw.githubusercontent.com/Epikcoder/aru/main/twt.json"
let twt_data = await axios.get(link_twt).then(r => r.data)
const link_ig = "https://raw.githubusercontent.com/Epikcoder/aru/main/ig.json"
let ig_data = await axios.get(link_ig).then(r => r.data)
app.use(cors())
app.get("/video", async (req, res) => {
let c = "" //get random data
let url = "";
function check() {
c = twt_data[Math.floor(Math.random() * twt_data.length)].split("|")
url = c[2]
if (!url.includes("?tag=")) {
check()
}
}
check()
const response = await axios({
method: 'GET',
url: url,
responseType: 'stream'
});
res.setHeader('Content-Disposition', 'inline');
res.setHeader('Content-Type', response.headers['content-type']);
response.data.pipe(res);
})
app.get('/image', async (req, res) => {
let c = "" //get random data
let url = "";
function check() {
c = twt_data[Math.floor(Math.random() * twt_data.length)].split("|")
url = c[2]
if (url.includes("?tag=")) {
check()
}
}
check()
// Set custom headers
res.set("X-fetchedurl", c[2]); // fetch url
res.set("X-fetchedurlid", c[1]); // give vid id
res.set("X-fetchedurlname", c[0]); // give vid author name
// Image or non-range video request
const response = await axios({
method: 'GET',
url: url,
responseType: 'stream'
});
res.setHeader('Content-Disposition', 'inline');
res.setHeader('Content-Type', response.headers['content-type']);
response.data.pipe(res);
})
app.get("/api", (req, res) => {
const a = twt_data[Math.floor(Math.random() * twt_data.length)].split("|")
res.json({ "urllink": a[2], "id": a[1], "name": a[0] })
})
app.get("/igvideo", async (req, res) => {
let c = "" //get random data
let url = "";
function check() {
c = ig_data[Math.floor(Math.random() * ig_data.length)]
url = c
if (!url.includes(".mp4")) {
check()
}
}
check()
const response = await axios({
method: 'GET',
url: url,
responseType: 'stream'
});
res.setHeader('Content-Disposition', 'inline');
res.setHeader('Content-Type', response.headers['content-type']);
response.data.pipe(res);
})
app.get('/igimage', async (req, res) => {
let c = "" //get random data
let url = "";
function check() {
c = ig_data[Math.floor(Math.random() * ig_data.length)]
url = c
if (url.includes(".mp4")) {
check()
}
}
check()
const response = await axios({
method: 'GET',
url: url,
responseType: 'stream'
});
res.setHeader('Content-Disposition', 'inline');
res.setHeader('Content-Type', response.headers['content-type']);
response.data.pipe(res);
})
app.get("/igapi", (req, res) => {
const a = ig_data[Math.floor(Math.random() * ig_data.length)]
res.json({ "urllink": a })
})
app.get("/", async (req, res) => {
const murl = req.headers["x-vercel-deployment-url"] || req.headers.referrer || req.headers.host
res.json({
madeBy: "@EpikCoder", mainurl: murl, routes: [
murl + "/image",
murl + "/api",
murl + "/video",
murl + "/igimage",
murl + "/igapi",
murl + "/igvideo"
]
})
})
app.get("/updb", async (req, res) => {
const { data } = await axios.get(link_twt)
const { data: igs_data } = await axios.get(link_twt)
if(data.length != twt_data.length || igs_data != ig_data.length) {
if (data.length != twt_data.length) {
twt_data = data;
res.write("updb twt")
}
if(igs_data != ig_data.length) {
ig_data = igs_data
res.write("updb ig")
}
}else{
res.send("no update")
}
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
export default app