mirror of
https://github.com/zoriya/flood.git
synced 2026-06-07 04:15:06 +00:00
server: torrents: allow contents to be viewed inline
This commit is contained in:
Generated
+14
@@ -27,6 +27,7 @@
|
||||
"@types/classnames": "^2.2.11",
|
||||
"@types/clipboard": "^2.0.1",
|
||||
"@types/compression": "^1.7.0",
|
||||
"@types/content-disposition": "^0.5.3",
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
"@types/create-torrent": "^4.4.0",
|
||||
"@types/d3": "^6.1.0",
|
||||
@@ -69,6 +70,7 @@
|
||||
"classnames": "^2.2.6",
|
||||
"clipboard": "^2.0.6",
|
||||
"compression": "^1.7.4",
|
||||
"content-disposition": "^0.5.3",
|
||||
"cookie-parser": "^1.4.5",
|
||||
"create-torrent": "^4.4.2",
|
||||
"css-loader": "^5.0.1",
|
||||
@@ -2357,6 +2359,12 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/content-disposition": {
|
||||
"version": "0.5.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/content-disposition/-/content-disposition-0.5.3.tgz",
|
||||
"integrity": "sha512-P1bffQfhD3O4LW0ioENXUhZ9OIa0Zn+P7M+pWgkCKaT53wVLSq0mrKksCID/FGHpFhRSxRGhgrQmfhRuzwtKdg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/cookie-parser": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/cookie-parser/-/cookie-parser-1.4.2.tgz",
|
||||
@@ -28182,6 +28190,12 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/content-disposition": {
|
||||
"version": "0.5.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/content-disposition/-/content-disposition-0.5.3.tgz",
|
||||
"integrity": "sha512-P1bffQfhD3O4LW0ioENXUhZ9OIa0Zn+P7M+pWgkCKaT53wVLSq0mrKksCID/FGHpFhRSxRGhgrQmfhRuzwtKdg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/cookie-parser": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/cookie-parser/-/cookie-parser-1.4.2.tgz",
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
"@types/classnames": "^2.2.11",
|
||||
"@types/clipboard": "^2.0.1",
|
||||
"@types/compression": "^1.7.0",
|
||||
"@types/content-disposition": "^0.5.3",
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
"@types/create-torrent": "^4.4.0",
|
||||
"@types/d3": "^6.1.0",
|
||||
@@ -118,6 +119,7 @@
|
||||
"classnames": "^2.2.6",
|
||||
"clipboard": "^2.0.6",
|
||||
"compression": "^1.7.4",
|
||||
"content-disposition": "^0.5.3",
|
||||
"cookie-parser": "^1.4.5",
|
||||
"create-torrent": "^4.4.2",
|
||||
"css-loader": "^5.0.1",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import childProcess from 'child_process';
|
||||
import contentDisposition from 'content-disposition';
|
||||
import createTorrent from 'create-torrent';
|
||||
import express from 'express';
|
||||
import fs from 'fs';
|
||||
@@ -555,8 +556,17 @@ router.get('/:hash/contents/:indices/data', (req, res) => {
|
||||
const file = filePathsToDownload[0];
|
||||
if (!fs.existsSync(file)) return res.status(404).json({error: 'File not found.'});
|
||||
|
||||
res.attachment(path.basename(file));
|
||||
return res.download(file);
|
||||
const filename = path.basename(file);
|
||||
|
||||
// Browsers don't support MKV streaming. However, browsers do support WebM which is a
|
||||
// subset of MKV. Chromium supports MKV when encoded in selected codecs.
|
||||
res.type(filename.endsWith('.mkv') ? 'video/webm' : filename);
|
||||
|
||||
// Allow browsers to display the content inline when only a single content is requested.
|
||||
// This is useful for texts, videos and audios. Users can still download them if needed.
|
||||
res.setHeader('content-disposition', contentDisposition(filename, {type: 'inline'}));
|
||||
|
||||
return res.sendFile(file);
|
||||
}
|
||||
|
||||
const archiveRootFolder = sanitizePath(selectedTorrent.directory);
|
||||
|
||||
Reference in New Issue
Block a user