diff options
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 139 |
1 files changed, 83 insertions, 56 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index b59df397d..6a95f6ef7 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,29 @@ 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 | MVideoThumbnailBlacklist, | ||
139 | MVideoWithAllFiles, | ||
140 | MVideoWithFile, | ||
141 | MVideoWithRights | ||
142 | } from '../../typings/models' | ||
143 | import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' | ||
144 | import { MThumbnail } from '../../typings/models/video/thumbnail' | ||
123 | 145 | ||
124 | // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation | 146 | // 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 })[] = [ | 147 | const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ |
@@ -232,8 +254,8 @@ export type AvailableForListIDsOptions = { | |||
232 | videoPlaylistId?: number | 254 | videoPlaylistId?: number |
233 | 255 | ||
234 | trendingDays?: number | 256 | trendingDays?: number |
235 | user?: UserModel, | 257 | user?: MUserAccountId |
236 | historyOfUser?: UserModel | 258 | historyOfUser?: MUserId |
237 | 259 | ||
238 | baseWhere?: WhereOptions[] | 260 | baseWhere?: WhereOptions[] |
239 | } | 261 | } |
@@ -634,7 +656,7 @@ export type AvailableForListIDsOptions = { | |||
634 | [ ScopeNames.WITH_BLACKLISTED ]: { | 656 | [ ScopeNames.WITH_BLACKLISTED ]: { |
635 | include: [ | 657 | include: [ |
636 | { | 658 | { |
637 | attributes: [ 'id', 'reason' ], | 659 | attributes: [ 'id', 'reason', 'unfederated' ], |
638 | model: VideoBlacklistModel, | 660 | model: VideoBlacklistModel, |
639 | required: false | 661 | required: false |
640 | } | 662 | } |
@@ -989,18 +1011,16 @@ export class VideoModel extends Model<VideoModel> { | |||
989 | VideoCaptions: VideoCaptionModel[] | 1011 | VideoCaptions: VideoCaptionModel[] |
990 | 1012 | ||
991 | @BeforeDestroy | 1013 | @BeforeDestroy |
992 | static async sendDelete (instance: VideoModel, options) { | 1014 | static async sendDelete (instance: MVideoAccountLight, options) { |
993 | if (instance.isOwned()) { | 1015 | if (instance.isOwned()) { |
994 | if (!instance.VideoChannel) { | 1016 | if (!instance.VideoChannel) { |
995 | instance.VideoChannel = await instance.$get('VideoChannel', { | 1017 | instance.VideoChannel = await instance.$get('VideoChannel', { |
996 | include: [ | 1018 | include: [ |
997 | { | 1019 | ActorModel, |
998 | model: AccountModel, | 1020 | AccountModel |
999 | include: [ ActorModel ] | ||
1000 | } | ||
1001 | ], | 1021 | ], |
1002 | transaction: options.transaction | 1022 | transaction: options.transaction |
1003 | }) as VideoChannelModel | 1023 | }) as MChannelAccountDefault |
1004 | } | 1024 | } |
1005 | 1025 | ||
1006 | return sendDeleteVideo(instance, options.transaction) | 1026 | return sendDeleteVideo(instance, options.transaction) |
@@ -1039,7 +1059,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1039 | return undefined | 1059 | return undefined |
1040 | } | 1060 | } |
1041 | 1061 | ||
1042 | static listLocal () { | 1062 | static listLocal (): Bluebird<MVideoWithAllFiles[]> { |
1043 | const query = { | 1063 | const query = { |
1044 | where: { | 1064 | where: { |
1045 | remote: false | 1065 | remote: false |
@@ -1159,7 +1179,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1159 | }) | 1179 | }) |
1160 | } | 1180 | } |
1161 | 1181 | ||
1162 | static listUserVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) { | 1182 | static listUserVideosForApi (accountId: number, start: number, count: number, sort: string) { |
1163 | function buildBaseQuery (): FindOptions { | 1183 | function buildBaseQuery (): FindOptions { |
1164 | return { | 1184 | return { |
1165 | offset: start, | 1185 | offset: start, |
@@ -1192,16 +1212,9 @@ export class VideoModel extends Model<VideoModel> { | |||
1192 | ScopeNames.WITH_THUMBNAILS | 1212 | ScopeNames.WITH_THUMBNAILS |
1193 | ] | 1213 | ] |
1194 | 1214 | ||
1195 | if (withFiles === true) { | ||
1196 | findQuery.include.push({ | ||
1197 | model: VideoFileModel.unscoped(), | ||
1198 | required: true | ||
1199 | }) | ||
1200 | } | ||
1201 | |||
1202 | return Promise.all([ | 1215 | return Promise.all([ |
1203 | VideoModel.count(countQuery), | 1216 | VideoModel.count(countQuery), |
1204 | VideoModel.scope(findScopes).findAll(findQuery) | 1217 | VideoModel.scope(findScopes).findAll<MVideoForUser>(findQuery) |
1205 | ]).then(([ count, rows ]) => { | 1218 | ]).then(([ count, rows ]) => { |
1206 | return { | 1219 | return { |
1207 | data: rows, | 1220 | data: rows, |
@@ -1228,8 +1241,8 @@ export class VideoModel extends Model<VideoModel> { | |||
1228 | followerActorId?: number | 1241 | followerActorId?: number |
1229 | videoPlaylistId?: number, | 1242 | videoPlaylistId?: number, |
1230 | trendingDays?: number, | 1243 | trendingDays?: number, |
1231 | user?: UserModel, | 1244 | user?: MUserAccountId, |
1232 | historyOfUser?: UserModel | 1245 | historyOfUser?: MUserId |
1233 | }, countVideos = true) { | 1246 | }, countVideos = true) { |
1234 | if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { | 1247 | 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') | 1248 | throw new Error('Try to filter all-local but no user has not the see all videos right') |
@@ -1294,7 +1307,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1294 | tagsAllOf?: string[] | 1307 | tagsAllOf?: string[] |
1295 | durationMin?: number // seconds | 1308 | durationMin?: number // seconds |
1296 | durationMax?: number // seconds | 1309 | durationMax?: number // seconds |
1297 | user?: UserModel, | 1310 | user?: MUserAccountId, |
1298 | filter?: VideoFilter | 1311 | filter?: VideoFilter |
1299 | }) { | 1312 | }) { |
1300 | const whereAnd = [] | 1313 | const whereAnd = [] |
@@ -1387,7 +1400,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1387 | return VideoModel.getAvailableForApi(query, queryOptions) | 1400 | return VideoModel.getAvailableForApi(query, queryOptions) |
1388 | } | 1401 | } |
1389 | 1402 | ||
1390 | static load (id: number | string, t?: Transaction) { | 1403 | static load (id: number | string, t?: Transaction): Bluebird<MVideoThumbnail> { |
1391 | const where = buildWhereIdOrUUID(id) | 1404 | const where = buildWhereIdOrUUID(id) |
1392 | const options = { | 1405 | const options = { |
1393 | where, | 1406 | where, |
@@ -1397,7 +1410,20 @@ export class VideoModel extends Model<VideoModel> { | |||
1397 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1410 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1398 | } | 1411 | } |
1399 | 1412 | ||
1400 | static loadWithRights (id: number | string, t?: Transaction) { | 1413 | static loadWithBlacklist (id: number | string, t?: Transaction): Bluebird<MVideoThumbnailBlacklist> { |
1414 | const where = buildWhereIdOrUUID(id) | ||
1415 | const options = { | ||
1416 | where, | ||
1417 | transaction: t | ||
1418 | } | ||
1419 | |||
1420 | return VideoModel.scope([ | ||
1421 | ScopeNames.WITH_THUMBNAILS, | ||
1422 | ScopeNames.WITH_BLACKLISTED | ||
1423 | ]).findOne(options) | ||
1424 | } | ||
1425 | |||
1426 | static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> { | ||
1401 | const where = buildWhereIdOrUUID(id) | 1427 | const where = buildWhereIdOrUUID(id) |
1402 | const options = { | 1428 | const options = { |
1403 | where, | 1429 | where, |
@@ -1411,7 +1437,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1411 | ]).findOne(options) | 1437 | ]).findOne(options) |
1412 | } | 1438 | } |
1413 | 1439 | ||
1414 | static loadOnlyId (id: number | string, t?: Transaction) { | 1440 | static loadOnlyId (id: number | string, t?: Transaction): Bluebird<MVideoIdThumbnail> { |
1415 | const where = buildWhereIdOrUUID(id) | 1441 | const where = buildWhereIdOrUUID(id) |
1416 | 1442 | ||
1417 | const options = { | 1443 | const options = { |
@@ -1423,7 +1449,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1423 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1449 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1424 | } | 1450 | } |
1425 | 1451 | ||
1426 | static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean) { | 1452 | static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Bluebird<MVideoWithAllFiles> { |
1427 | const where = buildWhereIdOrUUID(id) | 1453 | const where = buildWhereIdOrUUID(id) |
1428 | 1454 | ||
1429 | const query = { | 1455 | const query = { |
@@ -1439,7 +1465,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1439 | ]).findOne(query) | 1465 | ]).findOne(query) |
1440 | } | 1466 | } |
1441 | 1467 | ||
1442 | static loadByUUID (uuid: string) { | 1468 | static loadByUUID (uuid: string): Bluebird<MVideoThumbnail> { |
1443 | const options = { | 1469 | const options = { |
1444 | where: { | 1470 | where: { |
1445 | uuid | 1471 | uuid |
@@ -1449,7 +1475,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1449 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1475 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1450 | } | 1476 | } |
1451 | 1477 | ||
1452 | static loadByUrl (url: string, transaction?: Transaction) { | 1478 | static loadByUrl (url: string, transaction?: Transaction): Bluebird<MVideoThumbnail> { |
1453 | const query: FindOptions = { | 1479 | const query: FindOptions = { |
1454 | where: { | 1480 | where: { |
1455 | url | 1481 | url |
@@ -1460,7 +1486,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1460 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) | 1486 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) |
1461 | } | 1487 | } |
1462 | 1488 | ||
1463 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction) { | 1489 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> { |
1464 | const query: FindOptions = { | 1490 | const query: FindOptions = { |
1465 | where: { | 1491 | where: { |
1466 | url | 1492 | url |
@@ -1472,11 +1498,12 @@ export class VideoModel extends Model<VideoModel> { | |||
1472 | ScopeNames.WITH_ACCOUNT_DETAILS, | 1498 | ScopeNames.WITH_ACCOUNT_DETAILS, |
1473 | ScopeNames.WITH_FILES, | 1499 | ScopeNames.WITH_FILES, |
1474 | ScopeNames.WITH_STREAMING_PLAYLISTS, | 1500 | ScopeNames.WITH_STREAMING_PLAYLISTS, |
1475 | ScopeNames.WITH_THUMBNAILS | 1501 | ScopeNames.WITH_THUMBNAILS, |
1502 | ScopeNames.WITH_BLACKLISTED | ||
1476 | ]).findOne(query) | 1503 | ]).findOne(query) |
1477 | } | 1504 | } |
1478 | 1505 | ||
1479 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number) { | 1506 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Bluebird<MVideoFullLight> { |
1480 | const where = buildWhereIdOrUUID(id) | 1507 | const where = buildWhereIdOrUUID(id) |
1481 | 1508 | ||
1482 | const options = { | 1509 | const options = { |
@@ -1508,7 +1535,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1508 | id: number | string, | 1535 | id: number | string, |
1509 | t?: Transaction, | 1536 | t?: Transaction, |
1510 | userId?: number | 1537 | userId?: number |
1511 | }) { | 1538 | }): Bluebird<MVideoDetails> { |
1512 | const { id, t, userId } = parameters | 1539 | const { id, t, userId } = parameters |
1513 | const where = buildWhereIdOrUUID(id) | 1540 | const where = buildWhereIdOrUUID(id) |
1514 | 1541 | ||
@@ -1586,7 +1613,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1586 | .then(results => results.length === 1) | 1613 | .then(results => results.length === 1) |
1587 | } | 1614 | } |
1588 | 1615 | ||
1589 | static bulkUpdateSupportField (videoChannel: VideoChannelModel, t: Transaction) { | 1616 | static bulkUpdateSupportField (videoChannel: MChannel, t: Transaction) { |
1590 | const options = { | 1617 | const options = { |
1591 | where: { | 1618 | where: { |
1592 | channelId: videoChannel.id | 1619 | channelId: videoChannel.id |
@@ -1597,7 +1624,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1597 | return VideoModel.update({ support: videoChannel.support }, options) | 1624 | return VideoModel.update({ support: videoChannel.support }, options) |
1598 | } | 1625 | } |
1599 | 1626 | ||
1600 | static getAllIdsFromChannel (videoChannel: VideoChannelModel) { | 1627 | static getAllIdsFromChannel (videoChannel: MChannelId): Bluebird<number[]> { |
1601 | const query = { | 1628 | const query = { |
1602 | attributes: [ 'id' ], | 1629 | attributes: [ 'id' ], |
1603 | where: { | 1630 | where: { |
@@ -1756,20 +1783,20 @@ export class VideoModel extends Model<VideoModel> { | |||
1756 | this.VideoChannel.Account.isBlocked() | 1783 | this.VideoChannel.Account.isBlocked() |
1757 | } | 1784 | } |
1758 | 1785 | ||
1759 | getOriginalFile () { | 1786 | getOriginalFile <T extends MVideoWithFile> (this: T) { |
1760 | if (Array.isArray(this.VideoFiles) === false) return undefined | 1787 | if (Array.isArray(this.VideoFiles) === false) return undefined |
1761 | 1788 | ||
1762 | // The original file is the file that have the higher resolution | 1789 | // The original file is the file that have the higher resolution |
1763 | return maxBy(this.VideoFiles, file => file.resolution) | 1790 | return maxBy(this.VideoFiles, file => file.resolution) |
1764 | } | 1791 | } |
1765 | 1792 | ||
1766 | getFile (resolution: number) { | 1793 | getFile <T extends MVideoWithFile> (this: T, resolution: number) { |
1767 | if (Array.isArray(this.VideoFiles) === false) return undefined | 1794 | if (Array.isArray(this.VideoFiles) === false) return undefined |
1768 | 1795 | ||
1769 | return this.VideoFiles.find(f => f.resolution === resolution) | 1796 | return this.VideoFiles.find(f => f.resolution === resolution) |
1770 | } | 1797 | } |
1771 | 1798 | ||
1772 | async addAndSaveThumbnail (thumbnail: ThumbnailModel, transaction: Transaction) { | 1799 | async addAndSaveThumbnail (thumbnail: MThumbnail, transaction: Transaction) { |
1773 | thumbnail.videoId = this.id | 1800 | thumbnail.videoId = this.id |
1774 | 1801 | ||
1775 | const savedThumbnail = await thumbnail.save({ transaction }) | 1802 | const savedThumbnail = await thumbnail.save({ transaction }) |
@@ -1782,7 +1809,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1782 | this.Thumbnails.push(savedThumbnail) | 1809 | this.Thumbnails.push(savedThumbnail) |
1783 | } | 1810 | } |
1784 | 1811 | ||
1785 | getVideoFilename (videoFile: VideoFileModel) { | 1812 | getVideoFilename (videoFile: MVideoFile) { |
1786 | return this.uuid + '-' + videoFile.resolution + videoFile.extname | 1813 | return this.uuid + '-' + videoFile.resolution + videoFile.extname |
1787 | } | 1814 | } |
1788 | 1815 | ||
@@ -1806,7 +1833,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1806 | return this.Thumbnails.find(t => t.type === ThumbnailType.PREVIEW) | 1833 | return this.Thumbnails.find(t => t.type === ThumbnailType.PREVIEW) |
1807 | } | 1834 | } |
1808 | 1835 | ||
1809 | getTorrentFileName (videoFile: VideoFileModel) { | 1836 | getTorrentFileName (videoFile: MVideoFile) { |
1810 | const extension = '.torrent' | 1837 | const extension = '.torrent' |
1811 | return this.uuid + '-' + videoFile.resolution + extension | 1838 | return this.uuid + '-' + videoFile.resolution + extension |
1812 | } | 1839 | } |
@@ -1815,15 +1842,15 @@ export class VideoModel extends Model<VideoModel> { | |||
1815 | return this.remote === false | 1842 | return this.remote === false |
1816 | } | 1843 | } |
1817 | 1844 | ||
1818 | getTorrentFilePath (videoFile: VideoFileModel) { | 1845 | getTorrentFilePath (videoFile: MVideoFile) { |
1819 | return join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) | 1846 | return join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) |
1820 | } | 1847 | } |
1821 | 1848 | ||
1822 | getVideoFilePath (videoFile: VideoFileModel) { | 1849 | getVideoFilePath (videoFile: MVideoFile) { |
1823 | return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) | 1850 | return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) |
1824 | } | 1851 | } |
1825 | 1852 | ||
1826 | async createTorrentAndSetInfoHash (videoFile: VideoFileModel) { | 1853 | async createTorrentAndSetInfoHash (videoFile: MVideoFile) { |
1827 | const options = { | 1854 | const options = { |
1828 | // Keep the extname, it's used by the client to stream the file inside a web browser | 1855 | // 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}`, | 1856 | name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`, |
@@ -1869,11 +1896,11 @@ export class VideoModel extends Model<VideoModel> { | |||
1869 | return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename) | 1896 | return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename) |
1870 | } | 1897 | } |
1871 | 1898 | ||
1872 | toFormattedJSON (options?: VideoFormattingJSONOptions): Video { | 1899 | toFormattedJSON (this: MVideoFormattable, options?: VideoFormattingJSONOptions): Video { |
1873 | return videoModelToFormattedJSON(this, options) | 1900 | return videoModelToFormattedJSON(this, options) |
1874 | } | 1901 | } |
1875 | 1902 | ||
1876 | toFormattedDetailsJSON (): VideoDetails { | 1903 | toFormattedDetailsJSON (this: MVideoFormattableDetails): VideoDetails { |
1877 | return videoModelToFormattedDetailsJSON(this) | 1904 | return videoModelToFormattedDetailsJSON(this) |
1878 | } | 1905 | } |
1879 | 1906 | ||
@@ -1881,7 +1908,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1881 | return videoFilesModelToFormattedJSON(this, this.VideoFiles) | 1908 | return videoFilesModelToFormattedJSON(this, this.VideoFiles) |
1882 | } | 1909 | } |
1883 | 1910 | ||
1884 | toActivityPubObject (): VideoTorrentObject { | 1911 | toActivityPubObject (this: MVideoAP): VideoTorrentObject { |
1885 | return videoModelToActivityPubObject(this) | 1912 | return videoModelToActivityPubObject(this) |
1886 | } | 1913 | } |
1887 | 1914 | ||
@@ -1908,7 +1935,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1908 | return this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | 1935 | return this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) |
1909 | } | 1936 | } |
1910 | 1937 | ||
1911 | removeFile (videoFile: VideoFileModel, isRedundancy = false) { | 1938 | removeFile (videoFile: MVideoFile, isRedundancy = false) { |
1912 | const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR | 1939 | const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR |
1913 | 1940 | ||
1914 | const filePath = join(baseDir, this.getVideoFilename(videoFile)) | 1941 | const filePath = join(baseDir, this.getVideoFilename(videoFile)) |
@@ -1916,7 +1943,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1916 | .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) | 1943 | .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) |
1917 | } | 1944 | } |
1918 | 1945 | ||
1919 | removeTorrent (videoFile: VideoFileModel) { | 1946 | removeTorrent (videoFile: MVideoFile) { |
1920 | const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) | 1947 | const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) |
1921 | return remove(torrentPath) | 1948 | return remove(torrentPath) |
1922 | .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err })) | 1949 | .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err })) |
@@ -1957,7 +1984,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1957 | return { baseUrlHttp, baseUrlWs } | 1984 | return { baseUrlHttp, baseUrlWs } |
1958 | } | 1985 | } |
1959 | 1986 | ||
1960 | generateMagnetUri (videoFile: VideoFileModel, baseUrlHttp: string, baseUrlWs: string) { | 1987 | generateMagnetUri (videoFile: MVideoFileRedundanciesOpt, baseUrlHttp: string, baseUrlWs: string) { |
1961 | const xs = this.getTorrentUrl(videoFile, baseUrlHttp) | 1988 | const xs = this.getTorrentUrl(videoFile, baseUrlHttp) |
1962 | const announce = this.getTrackerUrls(baseUrlHttp, baseUrlWs) | 1989 | const announce = this.getTrackerUrls(baseUrlHttp, baseUrlWs) |
1963 | let urlList = [ this.getVideoFileUrl(videoFile, baseUrlHttp) ] | 1990 | let urlList = [ this.getVideoFileUrl(videoFile, baseUrlHttp) ] |
@@ -1980,27 +2007,27 @@ export class VideoModel extends Model<VideoModel> { | |||
1980 | return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] | 2007 | return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] |
1981 | } | 2008 | } |
1982 | 2009 | ||
1983 | getTorrentUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 2010 | getTorrentUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
1984 | return baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile) | 2011 | return baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile) |
1985 | } | 2012 | } |
1986 | 2013 | ||
1987 | getTorrentDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 2014 | getTorrentDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
1988 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + this.getTorrentFileName(videoFile) | 2015 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + this.getTorrentFileName(videoFile) |
1989 | } | 2016 | } |
1990 | 2017 | ||
1991 | getVideoFileUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 2018 | getVideoFileUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
1992 | return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) | 2019 | return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) |
1993 | } | 2020 | } |
1994 | 2021 | ||
1995 | getVideoRedundancyUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 2022 | getVideoRedundancyUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
1996 | return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getVideoFilename(videoFile) | 2023 | return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getVideoFilename(videoFile) |
1997 | } | 2024 | } |
1998 | 2025 | ||
1999 | getVideoFileDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) { | 2026 | getVideoFileDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) { |
2000 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + this.getVideoFilename(videoFile) | 2027 | return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + this.getVideoFilename(videoFile) |
2001 | } | 2028 | } |
2002 | 2029 | ||
2003 | getBandwidthBits (videoFile: VideoFileModel) { | 2030 | getBandwidthBits (videoFile: MVideoFile) { |
2004 | return Math.ceil((videoFile.size * 8) / this.duration) | 2031 | return Math.ceil((videoFile.size * 8) / this.duration) |
2005 | } | 2032 | } |
2006 | } | 2033 | } |