Spaces:
Sleeping
Sleeping
File size: 2,494 Bytes
a0b358c 62393c4 a0b358c d7e1d6b ea10dd1 d7e1d6b a0b358c d7e1d6b 5c4343f ea10dd1 d7e1d6b ea10dd1 5c4343f d7e1d6b ea10dd1 3603049 a0b358c d7e1d6b a0b358c 5c4343f d7e1d6b 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 |
const express = require('express');
const request = require('request');
require('dotenv').config();
const app = express();
const eachfilesize = {};
async function getFileSize(link) {
try {
const res = await request.head(link);
const contentLength = parseInt(res.headers['content-length'] || 0.1);
eachfilesize[link] = contentLength;
return contentLength;
} catch (err) {
console.error('Error retrieving file size:', err);
return 0;
}
}
app.get('/', async (req, res) => {
const shared = req.query.shared;
const filename = req.query.filename;
if (shared) {
const originalUrl = `https://huggingface.co/tranquan24/video/resolve/main/${shared}`;
const token = process.env.TOKEN;
const headers = {
'Authorization': `Bearer ${token}`,
'Range': req.headers['range'] || ''
};
try {
const originalResponse = await request.get({ url: originalUrl, headers });
const newResponse = new Response(originalResponse.body, { headers: originalResponse.headers });
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.writeHead(newResponse.status, newResponse.headers);
newResponse.body.pipe(res);
} catch (err) {
console.error('Error processing request:', err);
res.status(500).send(`Internal Server Error: ${err.message}`);
}
} else {
res.status(400).send('Missing shared parameter');
}
});
const port = 7860;
app.listen(port, '0.0.0.0', () => {
console.log(`Server is running on port ${port}`);
});
|