Spaces:
Sleeping
Sleeping
Update index.js
Browse files
index.js
CHANGED
|
@@ -21,46 +21,35 @@ function getFileSize(links) {
|
|
| 21 |
return fileSize;
|
| 22 |
}
|
| 23 |
|
| 24 |
-
app.get('/', (req, res) => {
|
| 25 |
-
const
|
| 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 |
-
const { statusCode, headers } = originalResponse;
|
| 55 |
-
res.writeHead(statusCode, headers);
|
| 56 |
-
originalResponse.pipe(res);
|
| 57 |
-
}).on('error', (err) => {
|
| 58 |
-
console.error(err);
|
| 59 |
-
res.status(500).send('Internal Server Error');
|
| 60 |
-
});
|
| 61 |
-
} else {
|
| 62 |
-
res.status(400).send('Missing shared parameter');
|
| 63 |
-
}
|
| 64 |
});
|
| 65 |
|
| 66 |
const port = 7860;
|
|
|
|
| 21 |
return fileSize;
|
| 22 |
}
|
| 23 |
|
| 24 |
+
app.get('/:filename', (req, res) => {
|
| 25 |
+
const filename = req.params.filename;
|
| 26 |
+
|
| 27 |
+
const originalUrl = `https://huggingface.co/tranquan24/video/resolve/main/${filename}`;
|
| 28 |
+
const token = process.env.TOKEN;
|
| 29 |
+
const headers = {
|
| 30 |
+
'Authorization': `Bearer ${token}`,
|
| 31 |
+
'Range': req.headers['range'] || ''
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
request.get({
|
| 35 |
+
url: originalUrl,
|
| 36 |
+
headers: headers
|
| 37 |
+
}).on('response', (originalResponse) => {
|
| 38 |
+
const links = [originalUrl];
|
| 39 |
+
const fileSize = getFileSize(links);
|
| 40 |
+
|
| 41 |
+
let headers_dict = originalResponse.headers;
|
| 42 |
+
headers_dict['Access-Control-Allow-Origin'] = '*';
|
| 43 |
+
|
| 44 |
+
headers_dict['Content-Disposition'] = `inline; filename="${filename}"`;
|
| 45 |
+
|
| 46 |
+
const { statusCode, headers } = originalResponse;
|
| 47 |
+
res.writeHead(statusCode, headers);
|
| 48 |
+
originalResponse.pipe(res);
|
| 49 |
+
}).on('error', (err) => {
|
| 50 |
+
console.error(err);
|
| 51 |
+
res.status(500).send('Internal Server Error');
|
| 52 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
});
|
| 54 |
|
| 55 |
const port = 7860;
|