diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-11 09:21:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-07-11 09:21:13 +0200 |
commit | 784e2ad5c34bcfef36a3f69e9e9acd7cbb3d6428 (patch) | |
tree | 29c46cfd6344065eb805680ed080cb05592ee1d4 /server/middlewares | |
parent | c3030e944ad03c7fd7b5d668a2d88ff03e4cdf19 (diff) | |
download | PeerTube-784e2ad5c34bcfef36a3f69e9e9acd7cbb3d6428.tar.gz PeerTube-784e2ad5c34bcfef36a3f69e9e9acd7cbb3d6428.tar.zst PeerTube-784e2ad5c34bcfef36a3f69e9e9acd7cbb3d6428.zip |
Prefer web videos in favour of webtorrent
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/static.ts | 8 | ||||
-rw-r--r-- | server/middlewares/validators/videos/video-files.ts | 26 | ||||
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 6 |
3 files changed, 22 insertions, 18 deletions
diff --git a/server/middlewares/validators/static.ts b/server/middlewares/validators/static.ts index 36a94080c..86cc0a8d7 100644 --- a/server/middlewares/validators/static.ts +++ b/server/middlewares/validators/static.ts | |||
@@ -22,7 +22,7 @@ const staticFileTokenBypass = new LRUCache<string, LRUValue>({ | |||
22 | ttl: LRU_CACHE.STATIC_VIDEO_FILES_RIGHTS_CHECK.TTL | 22 | ttl: LRU_CACHE.STATIC_VIDEO_FILES_RIGHTS_CHECK.TTL |
23 | }) | 23 | }) |
24 | 24 | ||
25 | const ensureCanAccessVideoPrivateWebTorrentFiles = [ | 25 | const ensureCanAccessVideoPrivateWebVideoFiles = [ |
26 | query('videoFileToken').optional().custom(exists), | 26 | query('videoFileToken').optional().custom(exists), |
27 | 27 | ||
28 | isValidVideoPasswordHeader(), | 28 | isValidVideoPasswordHeader(), |
@@ -48,7 +48,7 @@ const ensureCanAccessVideoPrivateWebTorrentFiles = [ | |||
48 | return res.sendStatus(HttpStatusCode.FORBIDDEN_403) | 48 | return res.sendStatus(HttpStatusCode.FORBIDDEN_403) |
49 | } | 49 | } |
50 | 50 | ||
51 | const result = await isWebTorrentAllowed(req, res) | 51 | const result = await isWebVideoAllowed(req, res) |
52 | 52 | ||
53 | staticFileTokenBypass.set(cacheKey, result) | 53 | staticFileTokenBypass.set(cacheKey, result) |
54 | 54 | ||
@@ -122,13 +122,13 @@ const ensureCanAccessPrivateVideoHLSFiles = [ | |||
122 | ] | 122 | ] |
123 | 123 | ||
124 | export { | 124 | export { |
125 | ensureCanAccessVideoPrivateWebTorrentFiles, | 125 | ensureCanAccessVideoPrivateWebVideoFiles, |
126 | ensureCanAccessPrivateVideoHLSFiles | 126 | ensureCanAccessPrivateVideoHLSFiles |
127 | } | 127 | } |
128 | 128 | ||
129 | // --------------------------------------------------------------------------- | 129 | // --------------------------------------------------------------------------- |
130 | 130 | ||
131 | async function isWebTorrentAllowed (req: express.Request, res: express.Response) { | 131 | async function isWebVideoAllowed (req: express.Request, res: express.Response) { |
132 | const filename = basename(req.path) | 132 | const filename = basename(req.path) |
133 | 133 | ||
134 | const file = await VideoFileModel.loadWithVideoByFilename(filename) | 134 | const file = await VideoFileModel.loadWithVideoByFilename(filename) |
diff --git a/server/middlewares/validators/videos/video-files.ts b/server/middlewares/validators/videos/video-files.ts index 92c5b9483..6c0ecda42 100644 --- a/server/middlewares/validators/videos/video-files.ts +++ b/server/middlewares/validators/videos/video-files.ts | |||
@@ -5,7 +5,7 @@ import { MVideo } from '@server/types/models' | |||
5 | import { HttpStatusCode } from '@shared/models' | 5 | import { HttpStatusCode } from '@shared/models' |
6 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' | 6 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' |
7 | 7 | ||
8 | const videoFilesDeleteWebTorrentValidator = [ | 8 | const videoFilesDeleteWebVideoValidator = [ |
9 | isValidVideoIdParam('id'), | 9 | isValidVideoIdParam('id'), |
10 | 10 | ||
11 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 11 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -16,17 +16,17 @@ const videoFilesDeleteWebTorrentValidator = [ | |||
16 | 16 | ||
17 | if (!checkLocalVideo(video, res)) return | 17 | if (!checkLocalVideo(video, res)) return |
18 | 18 | ||
19 | if (!video.hasWebTorrentFiles()) { | 19 | if (!video.hasWebVideoFiles()) { |
20 | return res.fail({ | 20 | return res.fail({ |
21 | status: HttpStatusCode.BAD_REQUEST_400, | 21 | status: HttpStatusCode.BAD_REQUEST_400, |
22 | message: 'This video does not have WebTorrent files' | 22 | message: 'This video does not have Web Video files' |
23 | }) | 23 | }) |
24 | } | 24 | } |
25 | 25 | ||
26 | if (!video.getHLSPlaylist()) { | 26 | if (!video.getHLSPlaylist()) { |
27 | return res.fail({ | 27 | return res.fail({ |
28 | status: HttpStatusCode.BAD_REQUEST_400, | 28 | status: HttpStatusCode.BAD_REQUEST_400, |
29 | message: 'Cannot delete WebTorrent files since this video does not have HLS playlist' | 29 | message: 'Cannot delete Web Video files since this video does not have HLS playlist' |
30 | }) | 30 | }) |
31 | } | 31 | } |
32 | 32 | ||
@@ -34,7 +34,7 @@ const videoFilesDeleteWebTorrentValidator = [ | |||
34 | } | 34 | } |
35 | ] | 35 | ] |
36 | 36 | ||
37 | const videoFilesDeleteWebTorrentFileValidator = [ | 37 | const videoFilesDeleteWebVideoFileValidator = [ |
38 | isValidVideoIdParam('id'), | 38 | isValidVideoIdParam('id'), |
39 | 39 | ||
40 | param('videoFileId') | 40 | param('videoFileId') |
@@ -52,14 +52,14 @@ const videoFilesDeleteWebTorrentFileValidator = [ | |||
52 | if (!files.find(f => f.id === +req.params.videoFileId)) { | 52 | if (!files.find(f => f.id === +req.params.videoFileId)) { |
53 | return res.fail({ | 53 | return res.fail({ |
54 | status: HttpStatusCode.NOT_FOUND_404, | 54 | status: HttpStatusCode.NOT_FOUND_404, |
55 | message: 'This video does not have this WebTorrent file id' | 55 | message: 'This video does not have this Web Video file id' |
56 | }) | 56 | }) |
57 | } | 57 | } |
58 | 58 | ||
59 | if (files.length === 1 && !video.getHLSPlaylist()) { | 59 | if (files.length === 1 && !video.getHLSPlaylist()) { |
60 | return res.fail({ | 60 | return res.fail({ |
61 | status: HttpStatusCode.BAD_REQUEST_400, | 61 | status: HttpStatusCode.BAD_REQUEST_400, |
62 | message: 'Cannot delete WebTorrent files since this video does not have HLS playlist' | 62 | message: 'Cannot delete Web Video files since this video does not have HLS playlist' |
63 | }) | 63 | }) |
64 | } | 64 | } |
65 | 65 | ||
@@ -87,10 +87,10 @@ const videoFilesDeleteHLSValidator = [ | |||
87 | }) | 87 | }) |
88 | } | 88 | } |
89 | 89 | ||
90 | if (!video.hasWebTorrentFiles()) { | 90 | if (!video.hasWebVideoFiles()) { |
91 | return res.fail({ | 91 | return res.fail({ |
92 | status: HttpStatusCode.BAD_REQUEST_400, | 92 | status: HttpStatusCode.BAD_REQUEST_400, |
93 | message: 'Cannot delete HLS playlist since this video does not have WebTorrent files' | 93 | message: 'Cannot delete HLS playlist since this video does not have Web Video files' |
94 | }) | 94 | }) |
95 | } | 95 | } |
96 | 96 | ||
@@ -128,10 +128,10 @@ const videoFilesDeleteHLSFileValidator = [ | |||
128 | } | 128 | } |
129 | 129 | ||
130 | // Last file to delete | 130 | // Last file to delete |
131 | if (hlsFiles.length === 1 && !video.hasWebTorrentFiles()) { | 131 | if (hlsFiles.length === 1 && !video.hasWebVideoFiles()) { |
132 | return res.fail({ | 132 | return res.fail({ |
133 | status: HttpStatusCode.BAD_REQUEST_400, | 133 | status: HttpStatusCode.BAD_REQUEST_400, |
134 | message: 'Cannot delete last HLS playlist file since this video does not have WebTorrent files' | 134 | message: 'Cannot delete last HLS playlist file since this video does not have Web Video files' |
135 | }) | 135 | }) |
136 | } | 136 | } |
137 | 137 | ||
@@ -140,8 +140,8 @@ const videoFilesDeleteHLSFileValidator = [ | |||
140 | ] | 140 | ] |
141 | 141 | ||
142 | export { | 142 | export { |
143 | videoFilesDeleteWebTorrentValidator, | 143 | videoFilesDeleteWebVideoValidator, |
144 | videoFilesDeleteWebTorrentFileValidator, | 144 | videoFilesDeleteWebVideoFileValidator, |
145 | 145 | ||
146 | videoFilesDeleteHLSValidator, | 146 | videoFilesDeleteHLSValidator, |
147 | videoFilesDeleteHLSFileValidator | 147 | videoFilesDeleteHLSFileValidator |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index b829e4eb4..b39d13a23 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -506,10 +506,14 @@ const commonVideosFiltersValidator = [ | |||
506 | .optional() | 506 | .optional() |
507 | .customSanitizer(toBooleanOrNull) | 507 | .customSanitizer(toBooleanOrNull) |
508 | .custom(isBooleanValid).withMessage('Should have a valid hasHLSFiles boolean'), | 508 | .custom(isBooleanValid).withMessage('Should have a valid hasHLSFiles boolean'), |
509 | query('hasWebtorrentFiles') | 509 | query('hasWebtorrentFiles') // TODO: remove in v7 |
510 | .optional() | 510 | .optional() |
511 | .customSanitizer(toBooleanOrNull) | 511 | .customSanitizer(toBooleanOrNull) |
512 | .custom(isBooleanValid).withMessage('Should have a valid hasWebtorrentFiles boolean'), | 512 | .custom(isBooleanValid).withMessage('Should have a valid hasWebtorrentFiles boolean'), |
513 | query('hasWebVideoFiles') | ||
514 | .optional() | ||
515 | .customSanitizer(toBooleanOrNull) | ||
516 | .custom(isBooleanValid).withMessage('Should have a valid hasWebVideoFiles boolean'), | ||
513 | query('skipCount') | 517 | query('skipCount') |
514 | .optional() | 518 | .optional() |
515 | .customSanitizer(toBooleanOrNull) | 519 | .customSanitizer(toBooleanOrNull) |