diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-22 10:43:11 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-22 10:43:11 +0200 |
commit | 5c5e587307a27e173333789b5b5167d35f468b01 (patch) | |
tree | 94e3721caf2e11d38fd5f4112c0fc98da89ac535 /server/models/video/video.ts | |
parent | 1b42d73f44811eec1b7ddd72dd0d640a57c3376c (diff) | |
parent | b5fecbf44192144d1ca27c23a0b53922de288c10 (diff) | |
download | PeerTube-5c5e587307a27e173333789b5b5167d35f468b01.tar.gz PeerTube-5c5e587307a27e173333789b5b5167d35f468b01.tar.zst PeerTube-5c5e587307a27e173333789b5b5167d35f468b01.zip |
Merge branch 'feature/strong-model-types' into develop
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 125 |
1 files changed, 69 insertions, 56 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index b59df397d..ab7b49f1e 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -36,7 +36,7 @@ import { | |||
36 | Table, | 36 | Table, |
37 | UpdatedAt | 37 | UpdatedAt |
38 | } from 'sequelize-typescript' | 38 | } from 'sequelize-typescript' |
39 | import { UserRight, VideoPrivacy, VideoResolution, VideoState } from '../../../shared' | 39 | import { UserRight, VideoPrivacy, VideoState } from '../../../shared' |
40 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 40 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' |
41 | import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' | 41 | import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' |
42 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' | 42 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' |
@@ -111,7 +111,6 @@ import { | |||
111 | videoModelToFormattedJSON | 111 | videoModelToFormattedJSON |
112 | } from './video-format-utils' | 112 | } from './video-format-utils' |
113 | import { UserVideoHistoryModel } from '../account/user-video-history' | 113 | import { UserVideoHistoryModel } from '../account/user-video-history' |
114 | import { UserModel } from '../account/user' | ||
115 | import { VideoImportModel } from './video-import' | 114 | import { VideoImportModel } from './video-import' |
116 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' | 115 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' |
117 | import { VideoPlaylistElementModel } from './video-playlist-element' | 116 | import { VideoPlaylistElementModel } from './video-playlist-element' |
@@ -120,6 +119,28 @@ import { ThumbnailModel } from './thumbnail' | |||
120 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 119 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' |
121 | import { createTorrentPromise } from '../../helpers/webtorrent' | 120 | import { createTorrentPromise } from '../../helpers/webtorrent' |
122 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | 121 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' |
122 | import { | ||
123 | MChannel, | ||
124 | MChannelAccountDefault, | ||
125 | MChannelId, | ||
126 | MUserAccountId, | ||
127 | MUserId, | ||
128 | MVideoAccountLight, | ||
129 | MVideoAccountLightBlacklistAllFiles, | ||
130 | MVideoAP, | ||
131 | MVideoDetails, | ||
132 | MVideoFormattable, | ||
133 | MVideoFormattableDetails, | ||
134 | MVideoForUser, | ||
135 | MVideoFullLight, | ||
136 | MVideoIdThumbnail, | ||
137 | MVideoThumbnail, | ||
138 | MVideoWithAllFiles, | ||
139 | MVideoWithFile, | ||
140 | MVideoWithRights | ||
141 | } from '../../typings/models' | ||
142 | import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' | ||
143 | import { MThumbnail } from '../../typings/models/video/thumbnail' | ||
123 | 144 | ||
124 | // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation | 145 | // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation |
125 | const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ | 146 | const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ |
@@ -232,8 +253,8 @@ export type AvailableForListIDsOptions = { | |||
232 | videoPlaylistId?: number | 253 | videoPlaylistId?: number |
233 | 254 | ||
234 | trendingDays?: number | 255 | trendingDays?: number |
235 | user?: UserModel, | 256 | user?: MUserAccountId |
236 | historyOfUser?: UserModel | 257 | historyOfUser?: MUserId |
237 | 258 | ||
238 | baseWhere?: WhereOptions[] | 259 | baseWhere?: WhereOptions[] |
239 | } | 260 | } |
@@ -634,7 +655,7 @@ export type AvailableForListIDsOptions = { | |||
634 | [ ScopeNames.WITH_BLACKLISTED ]: { | 655 | [ ScopeNames.WITH_BLACKLISTED ]: { |
635 | include: [ | 656 | include: [ |
636 | { | 657 | { |
637 | attributes: [ 'id', 'reason' ], | 658 | attributes: [ 'id', 'reason', 'unfederated' ], |
638 | model: VideoBlacklistModel, | 659 | model: VideoBlacklistModel, |
639 | required: false | 660 | required: false |
640 | } | 661 | } |
@@ -989,18 +1010,16 @@ export class VideoModel extends Model<VideoModel> { | |||
989 | VideoCaptions: VideoCaptionModel[] | 1010 | VideoCaptions: VideoCaptionModel[] |
990 | 1011 | ||
991 | @BeforeDestroy | 1012 | @BeforeDestroy |
992 | static async sendDelete (instance: VideoModel, options) { | 1013 | static async sendDelete (instance: MVideoAccountLight, options) { |
993 | if (instance.isOwned()) { | 1014 | if (instance.isOwned()) { |
994 | if (!instance.VideoChannel) { | 1015 | if (!instance.VideoChannel) { |
995 | instance.VideoChannel = await instance.$get('VideoChannel', { | 1016 | instance.VideoChannel = await instance.$get('VideoChannel', { |
996 | include: [ | 1017 | include: [ |
997 | { | 1018 | ActorModel, |
998 | model: AccountModel, | 1019 | AccountModel |
999 | include: [ ActorModel ] | ||
1000 | } | ||
1001 | ], | 1020 | ], |
1002 | transaction: options.transaction | 1021 | transaction: options.transaction |
1003 | }) as VideoChannelModel | 1022 | }) as MChannelAccountDefault |
1004 | } | 1023 | } |
1005 | 1024 | ||
1006 | return sendDeleteVideo(instance, options.transaction) | 1025 | return sendDeleteVideo(instance, options.transaction) |
@@ -1039,7 +1058,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1039 | return undefined | 1058 | return undefined |
1040 | } | 1059 | } |
1041 | 1060 | ||
1042 | static listLocal () { | 1061 | static listLocal (): Bluebird<MVideoWithAllFiles[]> { |
1043 | const query = { | 1062 | const query = { |
1044 | where: { | 1063 | where: { |
1045 | remote: false | 1064 | remote: false |
@@ -1159,7 +1178,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1159 | }) | 1178 | }) |
1160 | } | 1179 | } |
1161 | 1180 | ||
1162 | static listUserVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) { | 1181 | static listUserVideosForApi (accountId: number, start: number, count: number, sort: string) { |
1163 | function buildBaseQuery (): FindOptions { | 1182 | function buildBaseQuery (): FindOptions { |
1164 | return { | 1183 | return { |
1165 | offset: start, | 1184 | offset: start, |
@@ -1192,16 +1211,9 @@ export class VideoModel extends Model<VideoModel> { | |||
1192 | ScopeNames.WITH_THUMBNAILS | 1211 | ScopeNames.WITH_THUMBNAILS |
1193 | ] | 1212 | ] |
1194 | 1213 | ||
1195 | if (withFiles === true) { | ||
1196 | findQuery.include.push({ | ||
1197 | model: VideoFileModel.unscoped(), | ||
1198 | required: true | ||
1199 | }) | ||
1200 | } | ||
1201 | |||
1202 | return Promise.all([ | 1214 | return Promise.all([ |
1203 | VideoModel.count(countQuery), | 1215 | VideoModel.count(countQuery), |
1204 | VideoModel.scope(findScopes).findAll(findQuery) | 1216 | VideoModel.scope(findScopes).findAll<MVideoForUser>(findQuery) |
1205 | ]).then(([ count, rows ]) => { | 1217 | ]).then(([ count, rows ]) => { |
1206 | return { | 1218 | return { |
1207 | data: rows, | 1219 | data: rows, |
@@ -1228,8 +1240,8 @@ export class VideoModel extends Model<VideoModel> { | |||
1228 | followerActorId?: number | 1240 | followerActorId?: number |
1229 | videoPlaylistId?: number, | 1241 | videoPlaylistId?: number, |
1230 | trendingDays?: number, | 1242 | trendingDays?: number, |
1231 | user?: UserModel, | 1243 | user?: MUserAccountId, |
1232 | historyOfUser?: UserModel | 1244 | historyOfUser?: MUserId |
1233 | }, countVideos = true) { | 1245 | }, countVideos = true) { |
1234 | if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { | 1246 | if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { |
1235 | throw new Error('Try to filter all-local but no user has not the see all videos right') | 1247 | throw new Error('Try to filter all-local but no user has not the see all videos right') |
@@ -1294,7 +1306,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1294 | tagsAllOf?: string[] | 1306 | tagsAllOf?: string[] |
1295 | durationMin?: number // seconds | 1307 | durationMin?: number // seconds |
1296 | durationMax?: number // seconds | 1308 | durationMax?: number // seconds |
1297 | user?: UserModel, | 1309 | user?: MUserAccountId, |
1298 | filter?: VideoFilter | 1310 | filter?: VideoFilter |
1299 | }) { | 1311 | }) { |
1300 | const whereAnd = [] | 1312 | const whereAnd = [] |
@@ -1387,7 +1399,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1387 | return VideoModel.getAvailableForApi(query, queryOptions) | 1399 | return VideoModel.getAvailableForApi(query, queryOptions) |
1388 | } | 1400 | } |
1389 | 1401 | ||
1390 | static load (id: number | string, t?: Transaction) { | 1402 | static load (id: number | string, t?: Transaction): Bluebird<MVideoThumbnail> { |
1391 | const where = buildWhereIdOrUUID(id) | 1403 | const where = buildWhereIdOrUUID(id) |
1392 | const options = { | 1404 | const options = { |
1393 | where, | 1405 | where, |
@@ -1397,7 +1409,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1397 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1409 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1398 | } | 1410 | } |
1399 | 1411 | ||
1400 | static loadWithRights (id: number | string, t?: Transaction) { | 1412 | static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> { |
1401 | const where = buildWhereIdOrUUID(id) | 1413 | const where = buildWhereIdOrUUID(id) |
1402 | const options = { | 1414 | const options = { |
1403 | where, | 1415 | where, |
@@ -1411,7 +1423,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1411 | ]).findOne(options) | 1423 | ]).findOne(options) |
1412 | } | 1424 | } |
1413 | 1425 | ||
1414 | static loadOnlyId (id: number | string, t?: Transaction) { | 1426 | static loadOnlyId (id: number | string, t?: Transaction): Bluebird<MVideoIdThumbnail> { |
1415 | const where = buildWhereIdOrUUID(id) | 1427 | const where = buildWhereIdOrUUID(id) |
1416 | 1428 | ||
1417 | const options = { | 1429 | const options = { |
@@ -1423,7 +1435,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1423 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1435 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1424 | } | 1436 | } |
1425 | 1437 | ||
1426 | static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean) { | 1438 | static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Bluebird<MVideoWithAllFiles> { |
1427 | const where = buildWhereIdOrUUID(id) | 1439 | const where = buildWhereIdOrUUID(id) |
1428 | 1440 | ||
1429 | const query = { | 1441 | const query = { |
@@ -1439,7 +1451,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1439 | ]).findOne(query) | 1451 | ]).findOne(query) |
1440 | } | 1452 | } |
1441 | 1453 | ||
1442 | static loadByUUID (uuid: string) { | 1454 | static loadByUUID (uuid: string): Bluebird<MVideoThumbnail> { |
1443 | const options = { | 1455 | const options = { |
1444 | where: { | 1456 | where: { |
1445 | uuid | 1457 | uuid |
@@ -1449,7 +1461,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1449 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1461 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1450 | } | 1462 | } |
1451 | 1463 | ||
1452 | static loadByUrl (url: string, transaction?: Transaction) { | 1464 | static loadByUrl (url: string, transaction?: Transaction): Bluebird<MVideoThumbnail> { |
1453 | const query: FindOptions = { | 1465 | const query: FindOptions = { |
1454 | where: { | 1466 | where: { |
1455 | url | 1467 | url |
@@ -1460,7 +1472,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1460 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) | 1472 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) |
1461 | } | 1473 | } |
1462 | 1474 | ||
1463 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction) { | 1475 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> { |
1464 | const query: FindOptions = { | 1476 | const query: FindOptions = { |
1465 | where: { | 1477 | where: { |
1466 | url | 1478 | url |
@@ -1472,11 +1484,12 @@ export class VideoModel extends Model<VideoModel> { | |||
1472 | ScopeNames.WITH_ACCOUNT_DETAILS, | 1484 | ScopeNames.WITH_ACCOUNT_DETAILS, |
1473 | ScopeNames.WITH_FILES, | 1485 | ScopeNames.WITH_FILES, |
1474 | ScopeNames.WITH_STREAMING_PLAYLISTS, | 1486 | ScopeNames.WITH_STREAMING_PLAYLISTS, |
1475 | ScopeNames.WITH_THUMBNAILS | 1487 | ScopeNames.WITH_THUMBNAILS, |
1488 | ScopeNames.WITH_BLACKLISTED | ||
1476 | ]).findOne(query) | 1489 | ]).findOne(query) |
1477 | } | 1490 | } |
1478 | 1491 | ||
1479 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number) { | 1492 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Bluebird<MVideoFullLight> { |
1480 | const where = buildWhereIdOrUUID(id) | 1493 | const where = buildWhereIdOrUUID(id) |
1481 | 1494 | ||
1482 | const options = { | 1495 | const options = { |
@@ -1508,7 +1521,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1508 | id: number | string, | 1521 | id: number | string, |
1509 | t?: Transaction, | 1522 | t?: Transaction, |
1510 | userId?: number | 1523 | userId?: number |
1511 | }) { | 1524 | }): Bluebird<MVideoDetails> { |
1512 | const { id, t, userId } = parameters | 1525 | const { id, t, userId } = parameters |
1513 | const where = buildWhereIdOrUUID(id) | 1526 | const where = buildWhereIdOrUUID(id) |
1514 | 1527 | ||
@@ -1586,7 +1599,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1586 | .then(results => results.length === 1) | 1599 | .then(results => results.length === 1) |
1587 | } | 1600 | } |
1588 | 1601 | ||
1589 | static bulkUpdateSupportField (videoChannel: VideoChannelModel, t: Transaction) { | 1602 | static bulkUpdateSupportField (videoChannel: MChannel, t: Transaction) { |
1590 | const options = { | 1603 | const options = { |
1591 | where: { | 1604 | where: { |
1592 | channelId: videoChannel.id | 1605 | channelId: videoChannel.id |
@@ -1597,7 +1610,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1597 | return VideoModel.update({ support: videoChannel.support }, options) | 1610 | return VideoModel.update({ support: videoChannel.support }, options) |
1598 | } | 1611 | } |
1599 | 1612 | ||
1600 | static getAllIdsFromChannel (videoChannel: VideoChannelModel) { | 1613 | static getAllIdsFromChannel (videoChannel: MChannelId): Bluebird<number[]> { |
1601 | const query = { | 1614 | const query = { |
1602 | attributes: [ 'id' ], | 1615 | attributes: [ 'id' ], |
1603 | where: { | 1616 | where: { |
@@ -1756,20 +1769,20 @@ export class VideoModel extends Model<VideoModel> { | |||
1756 | this.VideoChannel.Account.isBlocked() | 1769 | this.VideoChannel.Account.isBlocked() |
1757 | } | 1770 | } |
1758 | 1771 | ||
1759 | getOriginalFile () { | 1772 | getOriginalFile <T extends MVideoWithFile> (this: T) { |
1760 | if (Array.isArray(this.VideoFiles) === false) return undefined | 1773 | if (Array.isArray(this.VideoFiles) === false) return undefined |
1761 | 1774 | ||
1762 | // The original file is the file that have the higher resolution | 1775 | // The original file is the file that have the higher resolution |
1763 | return maxBy(this.VideoFiles, file => file.resolution) | 1776 | return maxBy(this.VideoFiles, file => file.resolution) |
1764 | } | 1777 | } |
1765 | 1778 | ||
1766 | getFile (resolution: number) { | 1779 | getFile <T extends MVideoWithFile> (this: T, resolution: number) { |
1767 | if (Array.isArray(this.VideoFiles) === false) return undefined | 1780 | if (Array.isArray(this.VideoFiles) === false) return undefined |
1768 | 1781 | ||
1769 | return this.VideoFiles.find(f => f.resolution === resolution) | 1782 | return this.VideoFiles.find(f => f.resolution === resolution) |
1770 | } | 1783 | } |
1771 | 1784 | ||
1772 | async addAndSaveThumbnail (thumbnail: ThumbnailModel, transaction: Transaction) { | 1785 | async addAndSaveThumbnail (thumbnail: MThumbnail, transaction: Transaction) { |
1773 | thumbnail.videoId = this.id | 1786 | thumbnail.videoId = this.id |
1774 | 1787 | ||
1775 | const savedThumbnail = await thumbnail.save({ transaction }) | 1788 | const savedThumbnail = await thumbnail.save({ transaction }) |
@@ -1782,7 +1795,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1782 | this.Thumbnails.push(savedThumbnail) | 1795 | this.Thumbnails.push(savedThumbnail) |
1783 | } | 1796 | } |
1784 | 1797 | ||
1785 | getVideoFilename (videoFile: VideoFileModel) { | 1798 | getVideoFilename (videoFile: MVideoFile) { |
1786 | return this.uuid + '-' + videoFile.resolution + videoFile.extname | 1799 | return this.uuid + '-' + videoFile.resolution + videoFile.extname |
1787 | } | 1800 | } |
1788 | 1801 | ||
@@ -1806,7 +1819,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1806 | return this.Thumbnails.find(t => t.type === ThumbnailType.PREVIEW) | 1819 | return this.Thumbnails.find(t => t.type === ThumbnailType.PREVIEW) |
1807 | } | 1820 | } |
1808 | 1821 | ||
1809 | getTorrentFileName (videoFile: VideoFileModel) { | 1822 | getTorrentFileName (videoFile: MVideoFile) { |
1810 | const extension = '.torrent' | 1823 | const extension = '.torrent' |
1811 | return this.uuid + '-' + videoFile.resolution + extension | 1824 | return this.uuid + '-' + videoFile.resolution + extension |
1812 | } | 1825 | } |
@@ -1815,15 +1828,15 @@ export class VideoModel extends Model<VideoModel> { | |||
1815 | return this.remote === false | 1828 | return this.remote === false |
1816 | } | 1829 | } |
1817 | 1830 | ||
1818 | getTorrentFilePath (videoFile: VideoFileModel) { | 1831 | getTorrentFilePath (videoFile: MVideoFile) { |
1819 | return join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) | 1832 | return join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) |
1820 | } | 1833 | } |
1821 | 1834 | ||
1822 | getVideoFilePath (videoFile: VideoFileModel) { | 1835 | getVideoFilePath (videoFile: MVideoFile) { |
1823 | return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) | 1836 | return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) |
1824 | } | 1837 | } |
1825 | 1838 | ||
1826 | async createTorrentAndSetInfoHash (videoFile: VideoFileModel) { | 1839 | async createTorrentAndSetInfoHash (videoFile: MVideoFile) { |
1827 | const options = { | 1840 | const options = { |
1828 | // Keep the extname, it's used by the client to stream the file inside a web browser | 1841 | // Keep the extname, it's used by the client to stream the file inside a web browser |
1829 | name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`, | 1842 | name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`, |
@@ -1869,11 +1882,11 @@ export class VideoModel extends Model<VideoModel> { | |||
1869 | return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename) | 1882 | return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename) |
1870 | } | 1883 | } |
1871 | 1884 | ||
1872 | toFormattedJSON (options?: VideoFormattingJSONOptions): Video { | 1885 | toFormattedJSON (this: MVideoFormattable, options?: VideoFormattingJSONOptions): Video { |
1873 | return videoModelToFormattedJSON(this, options) | 1886 | return videoModelToFormattedJSON(this, options) |
1874 | } | 1887 | } |
1875 | 1888 | ||
1876 | toFormattedDetailsJSON (): VideoDetails { | 1889 | toFormattedDetailsJSON (this: MVideoFormattableDetails): VideoDetails { |
1877 | return videoModelToFormattedDetailsJSON(this) | 1890 | return videoModelToFormattedDetailsJSON(this) |
1878 | } | 1891 | } |
1879 | 1892 | ||
@@ -1881,7 +1894,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1881 | return videoFilesModelToFormattedJSON(this, this.VideoFiles) | 1894 | return videoFilesModelToFormattedJSON(this, this.VideoFiles) |
1882 | } | 1895 | } |
1883 | 1896 | ||
1884 | toActivityPubObject (): VideoTorrentObject { | 1897 | toActivityPubObject (this: MVideoAP): VideoTorrentObject { |
1885 | return videoModelToActivityPubObject(this) | 1898 | return videoModelToActivityPubObject(this) |
1886 | } | 1899 | } |
1887 | 1900 | ||
@@ -1908,7 +1921,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1908 | return this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | 1921 | return this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) |
1909 | } | 1922 | } |
1910 | 1923 | ||
1911 | removeFile (videoFile: VideoFileModel, isRedundancy = false) { | 1924 | removeFile (videoFile: MVideoFile, isRedundancy = false) { |
1912 | const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR | 1925 | const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR |
1913 | 1926 | ||
1914 | const filePath = join(baseDir, this.getVideoFilename(videoFile)) | 1927 | const filePath = join(baseDir, this.getVideoFilename(videoFile)) |
@@ -1916,7 +1929,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1916 | .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) | 1929 | .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) |
1917 | } | 1930 | } |
1918 | 1931 | ||
1919 | removeTorrent (videoFile: VideoFileModel) { | 1932 | removeTorrent (videoFile: MVideoFile) { |
1920 | const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) | 1933 | const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) |
1921 | return remove(torrentPath) | 1934 | return remove(torrentPath) |
1922 | .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err })) | 1935 | .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err })) |
@@ -1957,7 +1970,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1957 | return { baseUrlHttp, baseUrlWs } | 1970 | return { baseUrlHttp, baseUrlWs } |
1958 | } | 1971 | } |
1959 | 1972 | ||
1960 | generateMagnetUri (videoFile: VideoFileModel, baseUrlHttp: string, baseUrlWs: string) { | 1973 | generateMagnetUri (videoFile: MVideoFileRedundanciesOpt, baseUrlHttp: string, baseUrlWs: string) { |
1961 | const xs = this.getTorrentUrl(videoFile, baseUrlHttp) | 1974 | const xs = this.getTorrentUrl(videoFile, baseUrlHttp) |
1962 | const announce = this.getTrackerUrls(baseUrlHttp, baseUrlWs) | 1975 | const announce = this.getTrackerUrls(baseUrlHttp, baseUrlWs) |
1963 | let urlList = [ this.getVideoFileUrl(videoFile, baseUrlHttp) ] | 1976 | let urlList = [ this.getVideoFileUrl(videoFile, baseUrlHttp) ] |
@@ -1980,27 +1993,27 @@ export class VideoModel extends Model<VideoModel> { | |||
1980 | return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] | 1993 | return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] |
1981 | } | 1994 | } |
1982 | 1995 | ||
1983 | getTorrentUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 1996 | getTorrentUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
1984 | return baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile) | 1997 | return baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile) |
1985 | } | 1998 | } |
1986 | 1999 | ||
1987 | getTorrentDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 2000 | getTorrentDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
1988 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + this.getTorrentFileName(videoFile) | 2001 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + this.getTorrentFileName(videoFile) |
1989 | } | 2002 | } |
1990 | 2003 | ||
1991 | getVideoFileUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 2004 | getVideoFileUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
1992 | return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) | 2005 | return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) |
1993 | } | 2006 | } |
1994 | 2007 | ||
1995 | getVideoRedundancyUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 2008 | getVideoRedundancyUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
1996 | return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getVideoFilename(videoFile) | 2009 | return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getVideoFilename(videoFile) |
1997 | } | 2010 | } |
1998 | 2011 | ||
1999 | getVideoFileDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 2012 | getVideoFileDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
2000 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + this.getVideoFilename(videoFile) | 2013 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + this.getVideoFilename(videoFile) |
2001 | } | 2014 | } |
2002 | 2015 | ||
2003 | getBandwidthBits (videoFile: VideoFileModel) { | 2016 | getBandwidthBits (videoFile: MVideoFile) { |
2004 | return Math.ceil((videoFile.size * 8) / this.duration) | 2017 | return Math.ceil((videoFile.size * 8) / this.duration) |
2005 | } | 2018 | } |
2006 | } | 2019 | } |