aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-29 18:30:11 +0200
committerChocobozzz <me@florianbigard.com>2018-05-29 18:30:11 +0200
commit02756fbd11190e75b8bed9fad5751027e2e0de49 (patch)
treef90d6182fbb6226cb319bd0cb759ec0ec3f05512 /server/models
parenta20776fcbbe488475238228716cad370056ad5bd (diff)
downloadPeerTube-02756fbd11190e75b8bed9fad5751027e2e0de49.tar.gz
PeerTube-02756fbd11190e75b8bed9fad5751027e2e0de49.tar.zst
PeerTube-02756fbd11190e75b8bed9fad5751027e2e0de49.zip
Improve torrent/video download
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 1640cd57f..5821ea397 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -29,7 +29,6 @@ import { VideoPrivacy, VideoResolution } from '../../../shared'
29import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 29import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
30import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' 30import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
31import { VideoFilter } from '../../../shared/models/videos/video-query.type' 31import { VideoFilter } from '../../../shared/models/videos/video-query.type'
32import { activityPubCollectionPagination } from '../../helpers/activitypub'
33import { 32import {
34 createTorrentPromise, 33 createTorrentPromise,
35 peertubeTruncate, 34 peertubeTruncate,
@@ -59,6 +58,7 @@ import {
59 CONSTRAINTS_FIELDS, 58 CONSTRAINTS_FIELDS,
60 PREVIEWS_SIZE, 59 PREVIEWS_SIZE,
61 REMOTE_SCHEME, 60 REMOTE_SCHEME,
61 STATIC_DOWNLOAD_PATHS,
62 STATIC_PATHS, 62 STATIC_PATHS,
63 THUMBNAILS_SIZE, 63 THUMBNAILS_SIZE,
64 VIDEO_CATEGORIES, 64 VIDEO_CATEGORIES,
@@ -979,6 +979,10 @@ export class VideoModel extends Model<VideoModel> {
979 ) 979 )
980 } 980 }
981 981
982 getTorrentFilePath (videoFile: VideoFileModel) {
983 return join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
984 }
985
982 getVideoFilePath (videoFile: VideoFileModel) { 986 getVideoFilePath (videoFile: VideoFileModel) {
983 return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) 987 return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
984 } 988 }
@@ -1112,7 +1116,9 @@ export class VideoModel extends Model<VideoModel> {
1112 magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs), 1116 magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs),
1113 size: videoFile.size, 1117 size: videoFile.size,
1114 torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp), 1118 torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp),
1115 fileUrl: this.getVideoFileUrl(videoFile, baseUrlHttp) 1119 torrentDownloadUrl: this.getTorrentDownloadUrl(videoFile, baseUrlHttp),
1120 fileUrl: this.getVideoFileUrl(videoFile, baseUrlHttp),
1121 fileDownloadUrl: this.getVideoFileDownloadUrl(videoFile, baseUrlHttp)
1116 } as VideoFile 1122 } as VideoFile
1117 }) 1123 })
1118 .sort((a, b) => { 1124 .sort((a, b) => {
@@ -1367,10 +1373,18 @@ export class VideoModel extends Model<VideoModel> {
1367 return baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile) 1373 return baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile)
1368 } 1374 }
1369 1375
1376 private getTorrentDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) {
1377 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + this.getTorrentFileName(videoFile)
1378 }
1379
1370 private getVideoFileUrl (videoFile: VideoFileModel, baseUrlHttp: string) { 1380 private getVideoFileUrl (videoFile: VideoFileModel, baseUrlHttp: string) {
1371 return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) 1381 return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)
1372 } 1382 }
1373 1383
1384 private getVideoFileDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) {
1385 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + this.getVideoFilename(videoFile)
1386 }
1387
1374 private generateMagnetUri (videoFile: VideoFileModel, baseUrlHttp: string, baseUrlWs: string) { 1388 private generateMagnetUri (videoFile: VideoFileModel, baseUrlHttp: string, baseUrlWs: string) {
1375 const xs = this.getTorrentUrl(videoFile, baseUrlHttp) 1389 const xs = this.getTorrentUrl(videoFile, baseUrlHttp)
1376 const announce = [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] 1390 const announce = [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ]