Spaces:
Sleeping
Sleeping
Update index.js
Browse files
index.js
CHANGED
|
@@ -5,66 +5,68 @@ require('dotenv').config();
|
|
| 5 |
const app = express();
|
| 6 |
const eachfilesize = {};
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
const
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
-
app.get('/',
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
};
|
| 31 |
-
|
| 32 |
-
try {
|
| 33 |
-
const originalResponse = await request.get({ url: originalUrl, headers });
|
| 34 |
|
| 35 |
-
|
| 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 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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 |
});
|