aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts137
1 files changed, 3 insertions, 134 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 592fc2d59..e5fd92549 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1,8 +1,8 @@
1import * as Bluebird from 'bluebird'
1import { map, maxBy, truncate } from 'lodash' 2import { map, maxBy, truncate } from 'lodash'
2import * as magnetUtil from 'magnet-uri' 3import * as magnetUtil from 'magnet-uri'
3import * as parseTorrent from 'parse-torrent' 4import * as parseTorrent from 'parse-torrent'
4import { join } from 'path' 5import { join } from 'path'
5import * as safeBuffer from 'safe-buffer'
6import * as Sequelize from 'sequelize' 6import * as Sequelize from 'sequelize'
7import { VideoPrivacy, VideoResolution } from '../../../shared' 7import { VideoPrivacy, VideoResolution } from '../../../shared'
8import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' 8import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'
@@ -25,6 +25,7 @@ import {
25 unlinkPromise, 25 unlinkPromise,
26 writeFilePromise 26 writeFilePromise
27} from '../../helpers' 27} from '../../helpers'
28import { activityPubCollection } from '../../helpers/activitypub'
28import { isVideoUrlValid } from '../../helpers/custom-validators/videos' 29import { isVideoUrlValid } from '../../helpers/custom-validators/videos'
29import { 30import {
30 API_VERSION, 31 API_VERSION,
@@ -39,17 +40,13 @@ import {
39 VIDEO_LICENCES, 40 VIDEO_LICENCES,
40 VIDEO_PRIVACIES 41 VIDEO_PRIVACIES
41} from '../../initializers' 42} from '../../initializers'
43import { sendDeleteVideo } from '../../lib/index'
42 44
43import { addMethodsToModel, getSort } from '../utils' 45import { addMethodsToModel, getSort } from '../utils'
44 46
45import { TagInstance } from './tag-interface' 47import { TagInstance } from './tag-interface'
46import { VideoFileInstance, VideoFileModel } from './video-file-interface' 48import { VideoFileInstance, VideoFileModel } from './video-file-interface'
47import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' 49import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface'
48import { sendDeleteVideo } from '../../lib/index'
49import * as Bluebird from 'bluebird'
50import { activityPubCollection } from '../../helpers/activitypub'
51
52const Buffer = safeBuffer.Buffer
53 50
54let Video: Sequelize.Model<VideoInstance, VideoAttributes> 51let Video: Sequelize.Model<VideoInstance, VideoAttributes>
55let getOriginalFile: VideoMethods.GetOriginalFile 52let getOriginalFile: VideoMethods.GetOriginalFile
@@ -77,20 +74,14 @@ let getCategoryLabel: VideoMethods.GetCategoryLabel
77let getLicenceLabel: VideoMethods.GetLicenceLabel 74let getLicenceLabel: VideoMethods.GetLicenceLabel
78let getLanguageLabel: VideoMethods.GetLanguageLabel 75let getLanguageLabel: VideoMethods.GetLanguageLabel
79 76
80let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
81let list: VideoMethods.List 77let list: VideoMethods.List
82let listForApi: VideoMethods.ListForApi 78let listForApi: VideoMethods.ListForApi
83let listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox 79let listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
84let listUserVideosForApi: VideoMethods.ListUserVideosForApi 80let listUserVideosForApi: VideoMethods.ListUserVideosForApi
85let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
86let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
87let listOwnedByAccount: VideoMethods.ListOwnedByAccount
88let load: VideoMethods.Load 81let load: VideoMethods.Load
89let loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount 82let loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount
90let loadByUUID: VideoMethods.LoadByUUID 83let loadByUUID: VideoMethods.LoadByUUID
91let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL 84let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
92let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
93let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount
94let loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags 85let loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags
95let loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags 86let loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags
96let searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags 87let searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags
@@ -267,21 +258,15 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
267 const classMethods = [ 258 const classMethods = [
268 associate, 259 associate,
269 260
270 generateThumbnailFromData,
271 list, 261 list,
272 listAllAndSharedByAccountForOutbox, 262 listAllAndSharedByAccountForOutbox,
273 listForApi, 263 listForApi,
274 listUserVideosForApi, 264 listUserVideosForApi,
275 listOwnedAndPopulateAccountAndTags,
276 listOwnedByAccount,
277 load, 265 load,
278 loadByUrlAndPopulateAccount, 266 loadByUrlAndPopulateAccount,
279 loadAndPopulateAccount,
280 loadAndPopulateAccountAndServerAndTags, 267 loadAndPopulateAccountAndServerAndTags,
281 loadByHostAndUUID,
282 loadByUUIDOrURL, 268 loadByUUIDOrURL,
283 loadByUUID, 269 loadByUUID,
284 loadLocalVideoByUUID,
285 loadByUUIDAndPopulateAccountAndServerAndTags, 270 loadByUUIDAndPopulateAccountAndServerAndTags,
286 searchAndPopulateAccountAndServerAndTags 271 searchAndPopulateAccountAndServerAndTags
287 ] 272 ]
@@ -803,16 +788,6 @@ removeTorrent = function (this: VideoInstance, videoFile: VideoFileInstance) {
803 788
804// ------------------------------ STATICS ------------------------------ 789// ------------------------------ STATICS ------------------------------
805 790
806generateThumbnailFromData = function (video: VideoInstance, thumbnailData: string) {
807 // Creating the thumbnail for a remote video
808
809 const thumbnailName = video.getThumbnailName()
810 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName)
811 return writeFilePromise(thumbnailPath, Buffer.from(thumbnailData, 'binary')).then(() => {
812 return thumbnailName
813 })
814}
815
816list = function () { 791list = function () {
817 const query = { 792 const query = {
818 include: [ Video['sequelize'].models.VideoFile ] 793 include: [ Video['sequelize'].models.VideoFile ]
@@ -970,84 +945,6 @@ listForApi = function (start: number, count: number, sort: string) {
970 }) 945 })
971} 946}
972 947
973loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Transaction) {
974 const query: Sequelize.FindOptions<VideoAttributes> = {
975 where: {
976 uuid
977 },
978 include: [
979 {
980 model: Video['sequelize'].models.VideoFile
981 },
982 {
983 model: Video['sequelize'].models.VideoChannel,
984 include: [
985 {
986 model: Video['sequelize'].models.Account,
987 include: [
988 {
989 model: Video['sequelize'].models.Server,
990 required: true,
991 where: {
992 host: fromHost
993 }
994 }
995 ]
996 }
997 ]
998 }
999 ]
1000 }
1001
1002 if (t !== undefined) query.transaction = t
1003
1004 return Video.findOne(query)
1005}
1006
1007listOwnedAndPopulateAccountAndTags = function () {
1008 const query = {
1009 where: {
1010 remote: false
1011 },
1012 include: [
1013 Video['sequelize'].models.VideoFile,
1014 {
1015 model: Video['sequelize'].models.VideoChannel,
1016 include: [ Video['sequelize'].models.Account ]
1017 },
1018 Video['sequelize'].models.Tag
1019 ]
1020 }
1021
1022 return Video.findAll(query)
1023}
1024
1025listOwnedByAccount = function (account: string) {
1026 const query = {
1027 where: {
1028 remote: false
1029 },
1030 include: [
1031 {
1032 model: Video['sequelize'].models.VideoFile
1033 },
1034 {
1035 model: Video['sequelize'].models.VideoChannel,
1036 include: [
1037 {
1038 model: Video['sequelize'].models.Account,
1039 where: {
1040 name: account
1041 }
1042 }
1043 ]
1044 }
1045 ]
1046 }
1047
1048 return Video.findAll(query)
1049}
1050
1051load = function (id: number) { 948load = function (id: number) {
1052 return Video.findById(id) 949 return Video.findById(id)
1053} 950}
@@ -1100,34 +997,6 @@ loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transaction
1100 return Video.findOne(query) 997 return Video.findOne(query)
1101} 998}
1102 999
1103loadLocalVideoByUUID = function (uuid: string, t?: Sequelize.Transaction) {
1104 const query: Sequelize.FindOptions<VideoAttributes> = {
1105 where: {
1106 uuid,
1107 remote: false
1108 },
1109 include: [ Video['sequelize'].models.VideoFile ]
1110 }
1111
1112 if (t !== undefined) query.transaction = t
1113
1114 return Video.findOne(query)
1115}
1116
1117loadAndPopulateAccount = function (id: number) {
1118 const options = {
1119 include: [
1120 Video['sequelize'].models.VideoFile,
1121 {
1122 model: Video['sequelize'].models.VideoChannel,
1123 include: [ Video['sequelize'].models.Account ]
1124 }
1125 ]
1126 }
1127
1128 return Video.findById(id, options)
1129}
1130
1131loadAndPopulateAccountAndServerAndTags = function (id: number) { 1000loadAndPopulateAccountAndServerAndTags = function (id: number) {
1132 const options = { 1001 const options = {
1133 include: [ 1002 include: [