tranquan24 commited on
Commit
a0b358c
·
verified ·
1 Parent(s): 8eac324

Create index.js

Browse files
Files changed (1) hide show
  1. index.js +81 -0
index.js ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const request = require('request');
3
+
4
+ const app = express();
5
+ const PORT = process.env.PORT || 7860;
6
+
7
+ const eachfilesize = {};
8
+
9
+ const REQUEST_URL = process.env.REQUEST_URL;
10
+ const TOKEN = process.env.TOKEN;
11
+
12
+ async function getFileSize(link) {
13
+ return new Promise((resolve, reject) => {
14
+ request.head(link, (err, res, body) => {
15
+ if (err) {
16
+ reject(err);
17
+ } else {
18
+ const contentLength = (parseInt(res.headers['content-length']) || 0.1).toString();
19
+ eachfilesize[link] = contentLength;
20
+ resolve(contentLength);
21
+ }
22
+ });
23
+ });
24
+ }
25
+
26
+ app.get('*', async (req, res) => {
27
+ if (req.method !== 'GET') {
28
+ return res.status(405).send('Method Not Allowed');
29
+ }
30
+
31
+ const referer = req.headers.referer;
32
+ if (!referer || !referer.includes('https://tpcloud.rf.gd')) {
33
+ return res.status(404).send();
34
+ }
35
+
36
+ const filename = req.params[0];
37
+
38
+ if (filename) {
39
+ const originalUrl = `${REQUEST_URL}${filename}`;
40
+ const headers = {
41
+ 'Authorization': `Bearer ${TOKEN}`,
42
+ 'Range': req.headers.range || ''
43
+ };
44
+
45
+ try {
46
+ const originalResponse = await fetch(originalUrl, { headers });
47
+
48
+ const newResponse = new Response(originalResponse.body, originalResponse);
49
+ newResponse.headers.delete('Date');
50
+ newResponse.headers.delete('Etag');
51
+ newResponse.headers.delete('Last-Modified');
52
+ newResponse.headers.delete('Cf-Cache-Status');
53
+ newResponse.headers.delete('Content-Disposition');
54
+ newResponse.headers.delete('Nel');
55
+ newResponse.headers.delete('Cf-Ray');
56
+ newResponse.headers.delete('Report-To');
57
+ newResponse.headers.delete('X-Amz-Cf-Id');
58
+ newResponse.headers.delete('X-Amz-Cf-Pop');
59
+ newResponse.headers.delete('X-Amz-Server-Side-Encryption');
60
+ newResponse.headers.delete('X-Amz-Storage-Class');
61
+ newResponse.headers.delete('X-Cache');
62
+ newResponse.headers.set('Cache-Control', 'private, max-age=21188');
63
+ newResponse.headers.set('Connection', 'close');
64
+ newResponse.headers.set('Server', 'gvs 1.0');
65
+ newResponse.headers.set('Vary', 'Origin');
66
+ newResponse.headers.set('X-Content-Type-Options', 'nosniff');
67
+ newResponse.headers.set('Access-Control-Allow-Origin', 'https://tpcloud.rf.gd');
68
+
69
+ res.send(newResponse);
70
+ } catch (err) {
71
+ console.error(err);
72
+ return res.status(500).send('500');
73
+ }
74
+ } else {
75
+ return res.status(400).send('400');
76
+ }
77
+ });
78
+
79
+ app.listen(PORT, '0.0.0.0', () => {
80
+ console.log(`Server is running on http://0.0.0.0:${PORT}`);
81
+ });