File size: 2,551 Bytes
a0b358c
 
 
 
29b5003
a0b358c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const express = require('express');
const request = require('request');

const app = express();
const PORT = 7860;

const eachfilesize = {};

const REQUEST_URL = process.env.REQUEST_URL;
const TOKEN = process.env.TOKEN;

async function getFileSize(link) {
  return new Promise((resolve, reject) => {
    request.head(link, (err, res, body) => {
      if (err) {
        reject(err);
      } else {
        const contentLength = (parseInt(res.headers['content-length']) || 0.1).toString();
        eachfilesize[link] = contentLength;
        resolve(contentLength);
      }
    });
  });
}

app.get('*', async (req, res) => {
  if (req.method !== 'GET') {
    return res.status(405).send('Method Not Allowed');
  }

  const referer = req.headers.referer;
  if (!referer || !referer.includes('https://tpcloud.rf.gd')) {
    return res.status(404).send();
  }

  const filename = req.params[0];

  if (filename) {
    const originalUrl = `${REQUEST_URL}${filename}`;
    const headers = {
      'Authorization': `Bearer ${TOKEN}`,
      'Range': req.headers.range || ''
    };

    try {
      const originalResponse = await fetch(originalUrl, { headers });

      const newResponse = new Response(originalResponse.body, originalResponse);
      newResponse.headers.delete('Date');
      newResponse.headers.delete('Etag');
      newResponse.headers.delete('Last-Modified');
      newResponse.headers.delete('Cf-Cache-Status');
      newResponse.headers.delete('Content-Disposition');
      newResponse.headers.delete('Nel');
      newResponse.headers.delete('Cf-Ray');
      newResponse.headers.delete('Report-To');
      newResponse.headers.delete('X-Amz-Cf-Id');
      newResponse.headers.delete('X-Amz-Cf-Pop');
      newResponse.headers.delete('X-Amz-Server-Side-Encryption');
      newResponse.headers.delete('X-Amz-Storage-Class');
      newResponse.headers.delete('X-Cache');
      newResponse.headers.set('Cache-Control', 'private, max-age=21188');
      newResponse.headers.set('Connection', 'close');
      newResponse.headers.set('Server', 'gvs 1.0');
      newResponse.headers.set('Vary', 'Origin');
      newResponse.headers.set('X-Content-Type-Options', 'nosniff');
      newResponse.headers.set('Access-Control-Allow-Origin', 'https://tpcloud.rf.gd');

      res.send(newResponse);
    } catch (err) {
      console.error(err);
      return res.status(500).send('500');
    }
  } else {
    return res.status(400).send('400');
  }
});

app.listen(PORT, '0.0.0.0', () => {
  console.log(`Server is running on http://0.0.0.0:${PORT}`);
});