Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fetch = require("node-fetch");
- const express = require('express')
- const app = express()
- String.prototype.replaceAll = function (search, replacement) {
- return this.replace(new RegExp(search, 'g'), replacement);
- };
- const parseFile = url =>
- url.split('=')[1].split('&')[0].replaceAll('%2F', '/').replaceAll('%3A', ':');
- const url = x => `https://gs.3g.cn/D/${x.toString(16)}/w`;
- const format = (url, url2) => {
- const style = `style="height:400px;"`;
- if (url.endsWith('.zip')) {
- return `<iframe src='${url2}' ${style}></iframe>`;
- }
- const format = url.endsWith('.mp3') ? 'audio' : (url.endsWith('.mp4') ? 'video' : 'img');
- return `<${format} src='${url}' ${style}></${format}>`;
- }
- app.get('/:start/:end', async (req, res) => {
- const start = parseInt(req.params.start),
- end = parseInt(req.params.end);
- console.log(start, end);
- const urls = Array(end).fill(start).map((i, j) => i + j).map(x => url(x));
- const results = await Promise.all(urls.map(async u =>
- fetch(u)
- .then(r => {
- return [parseFile(r.url), u];
- })
- .catch(() => console.log('error', u))
- ));
- // console.log(results);
- res.send(results.map(r => `<a href='${r[1]}' >${format(r[0], r[1])}</a>`).join('\n'));
- })
- app.listen(8000, () => console.log(`http://localhost:8000/14000000/10`));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement