tranquan24 commited on
Commit
2619711
·
verified ·
1 Parent(s): 3603049

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +54 -52
index.js CHANGED
@@ -5,66 +5,68 @@ require('dotenv').config();
5
  const app = express();
6
  const eachfilesize = {};
7
 
8
- async function getFileSize(link) {
9
- try {
10
- const res = await request.head(link);
11
- const contentLength = parseInt(res.headers['content-length'] || 0.1);
12
- eachfilesize[link] = contentLength;
13
- return contentLength;
14
- } catch (err) {
15
- console.error('Error retrieving file size:', err);
16
- return 0;
17
- }
 
 
 
 
18
  }
19
 
20
- app.get('/', async (req, res) => {
21
- const shared = req.query.shared;
22
- const filename = req.query.filename;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- if (shared) {
25
- const originalUrl = `https://huggingface.co/tranquan24/video/resolve/main/${shared}`;
26
- const token = process.env.TOKEN;
27
- const headers = {
28
- 'Authorization': `Bearer ${token}`,
29
- 'Range': req.headers['range'] || ''
30
- };
31
-
32
- try {
33
- const originalResponse = await request.get({ url: originalUrl, headers });
34
 
35
- const newResponse = new Response(originalResponse.body, { headers: originalResponse.headers });
36
- newResponse.headers.delete('Date');
37
- newResponse.headers.delete('Etag');
38
- newResponse.headers.delete('Last-Modified');
39
- newResponse.headers.delete('Cf-Cache-Status');
40
- newResponse.headers.delete('Content-Disposition');
41
- newResponse.headers.delete('Nel');
42
- newResponse.headers.delete('Cf-Ray');
43
- newResponse.headers.delete('Report-To');
44
- newResponse.headers.delete('X-Amz-Cf-Id');
45
- newResponse.headers.delete('X-Amz-Cf-Pop');
46
- newResponse.headers.delete('X-Amz-Server-Side-Encryption');
47
- newResponse.headers.delete('X-Amz-Storage-Class');
48
- newResponse.headers.delete('X-Cache');
49
- newResponse.headers.set('Cache-Control', 'private, max-age=21188');
50
- newResponse.headers.set('Connection', 'close');
51
- newResponse.headers.set('Server', 'gvs 1.0');
52
- newResponse.headers.set('Vary', 'Origin');
53
- newResponse.headers.set('X-Content-Type-Options', 'nosniff');
54
- newResponse.headers.set('Access-Control-Allow-Origin', 'https://tpcloud.rf.gd');
55
 
56
- res.writeHead(newResponse.status, newResponse.headers);
57
- newResponse.body.pipe(res);
58
- } catch (err) {
59
- console.error('Error processing request:', err);
60
- res.status(500).send(`Internal Server Error: ${err.message}`);
 
 
 
 
61
  }
62
- } else {
63
- res.status(400).send('Missing shared parameter');
64
- }
65
  });
66
 
67
  const port = 7860;
68
  app.listen(port, '0.0.0.0', () => {
69
- console.log(`Server is running on port ${port}`);
70
  });
 
5
  const app = express();
6
  const eachfilesize = {};
7
 
8
+ function getFileSize(links) {
9
+ let fileSize = 0;
10
+ for (const link of links) {
11
+ request.head(link, (err, res) => {
12
+ if (err) {
13
+ console.error(err);
14
+ return;
15
+ }
16
+ const contentLength = parseInt(res.headers['content-length'] || 0.1);
17
+ fileSize += contentLength;
18
+ eachfilesize[link] = contentLength;
19
+ });
20
+ }
21
+ return fileSize;
22
  }
23
 
24
+ app.get('/', (req, res) => {
25
+ const shared = req.query.shared;
26
+ const filename = req.query.filename;
27
+
28
+ if (shared) {
29
+ const originalUrl = `https://huggingface.co/tranquan24/video/resolve/main/${shared}`;
30
+ const token = process.env.TOKEN;
31
+ const headers = {
32
+ 'Authorization': `Bearer ${token}`,
33
+ 'Range': req.headers['range'] || ''
34
+ };
35
+
36
+ request.get({
37
+ url: originalUrl,
38
+ headers: headers
39
+ }).on('response', (originalResponse) => {
40
+ const links = [originalUrl];
41
+ const fileSize = getFileSize(links);
42
+
43
+ let headers_dict = originalResponse.headers;
44
+ headers_dict['X-Speed'] = 'Fast';
45
+ headers_dict['X-Bandwidth'] = 'High';
46
+ headers_dict['Access-Control-Allow-Origin'] = 'https://embed.giize.com';
47
 
48
+ if (filename) {
49
+ headers_dict['Content-Disposition'] = `attachment; filename="${filename}"`;
50
+ } else {
51
+ const filenameFromUrl = shared.split('/').pop();
52
+ headers_dict['Content-Disposition'] = `attachment; filename="${filenameFromUrl}"`;
53
+ }
 
 
 
 
54
 
55
+ delete headers_dict['set-cookie'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
+ const { statusCode, headers } = originalResponse;
58
+ res.writeHead(statusCode, headers);
59
+ originalResponse.pipe(res);
60
+ }).on('error', (err) => {
61
+ console.error(err);
62
+ res.status(500).send('Internal Server Error');
63
+ });
64
+ } else {
65
+ res.status(400).send('Missing shared parameter');
66
  }
 
 
 
67
  });
68
 
69
  const port = 7860;
70
  app.listen(port, '0.0.0.0', () => {
71
+ console.log(`Server is running on port ${port}`);
72
  });