aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-10 14:34:45 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit0d0e8dd0904b380b70e19ebcb4763d65601c4632 (patch)
treeacb625d7c88fbe863fa14bf6783fafe4a8e35137 /server/models/video
parente4f97babf701481b55cc10fb3448feab5f97c867 (diff)
downloadPeerTube-0d0e8dd0904b380b70e19ebcb4763d65601c4632.tar.gz
PeerTube-0d0e8dd0904b380b70e19ebcb4763d65601c4632.tar.zst
PeerTube-0d0e8dd0904b380b70e19ebcb4763d65601c4632.zip
Continue activitypub
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-channel-interface.ts6
-rw-r--r--server/models/video/video-channel.ts35
-rw-r--r--server/models/video/video-interface.ts11
-rw-r--r--server/models/video/video.ts24
4 files changed, 66 insertions, 10 deletions
diff --git a/server/models/video/video-channel-interface.ts b/server/models/video/video-channel-interface.ts
index 477f97cd4..55e772063 100644
--- a/server/models/video/video-channel-interface.ts
+++ b/server/models/video/video-channel-interface.ts
@@ -24,6 +24,8 @@ export namespace VideoChannelMethods {
24 export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance> 24 export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance>
25 export type LoadByHostAndUUID = (uuid: string, podHost: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance> 25 export type LoadByHostAndUUID = (uuid: string, podHost: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance>
26 export type LoadAndPopulateAccountAndVideos = (id: number) => Promise<VideoChannelInstance> 26 export type LoadAndPopulateAccountAndVideos = (id: number) => Promise<VideoChannelInstance>
27 export type LoadByUrl = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance>
28 export type LoadByUUIDOrUrl = (uuid: string, url: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance>
27} 29}
28 30
29export interface VideoChannelClass { 31export interface VideoChannelClass {
@@ -37,6 +39,8 @@ export interface VideoChannelClass {
37 loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount 39 loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount
38 loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount 40 loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount
39 loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos 41 loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos
42 loadByUrl: VideoChannelMethods.LoadByUrl
43 loadByUUIDOrUrl: VideoChannelMethods.LoadByUUIDOrUrl
40} 44}
41 45
42export interface VideoChannelAttributes { 46export interface VideoChannelAttributes {
@@ -45,7 +49,7 @@ export interface VideoChannelAttributes {
45 name: string 49 name: string
46 description: string 50 description: string
47 remote: boolean 51 remote: boolean
48 url: string 52 url?: string
49 53
50 Account?: AccountInstance 54 Account?: AccountInstance
51 Videos?: VideoInstance[] 55 Videos?: VideoInstance[]
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index c17828f3e..93a611fa0 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -25,6 +25,8 @@ let loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount
25let loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount 25let loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount
26let loadByHostAndUUID: VideoChannelMethods.LoadByHostAndUUID 26let loadByHostAndUUID: VideoChannelMethods.LoadByHostAndUUID
27let loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos 27let loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos
28let loadByUrl: VideoChannelMethods.LoadByUrl
29let loadByUUIDOrUrl: VideoChannelMethods.LoadByUUIDOrUrl
28 30
29export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 31export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
30 VideoChannel = sequelize.define<VideoChannelInstance, VideoChannelAttributes>('VideoChannel', 32 VideoChannel = sequelize.define<VideoChannelInstance, VideoChannelAttributes>('VideoChannel',
@@ -94,12 +96,14 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
94 loadByUUID, 96 loadByUUID,
95 loadByHostAndUUID, 97 loadByHostAndUUID,
96 loadAndPopulateAccountAndVideos, 98 loadAndPopulateAccountAndVideos,
97 countByAccount 99 countByAccount,
100 loadByUrl,
101 loadByUUIDOrUrl
98 ] 102 ]
99 const instanceMethods = [ 103 const instanceMethods = [
100 isOwned, 104 isOwned,
101 toFormattedJSON, 105 toFormattedJSON,
102 toActivityPubObject, 106 toActivityPubObject
103 ] 107 ]
104 addMethodsToModel(VideoChannel, classMethods, instanceMethods) 108 addMethodsToModel(VideoChannel, classMethods, instanceMethods)
105 109
@@ -254,6 +258,33 @@ loadByUUID = function (uuid: string, t?: Sequelize.Transaction) {
254 return VideoChannel.findOne(query) 258 return VideoChannel.findOne(query)
255} 259}
256 260
261loadByUrl = function (url: string, t?: Sequelize.Transaction) {
262 const query: Sequelize.FindOptions<VideoChannelAttributes> = {
263 where: {
264 url
265 }
266 }
267
268 if (t !== undefined) query.transaction = t
269
270 return VideoChannel.findOne(query)
271}
272
273loadByUUIDOrUrl = function (uuid: string, url: string, t?: Sequelize.Transaction) {
274 const query: Sequelize.FindOptions<VideoChannelAttributes> = {
275 where: {
276 [Sequelize.Op.or]: [
277 { uuid },
278 { url }
279 ]
280 },
281 }
282
283 if (t !== undefined) query.transaction = t
284
285 return VideoChannel.findOne(query)
286}
287
257loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Transaction) { 288loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Transaction) {
258 const query: Sequelize.FindOptions<VideoChannelAttributes> = { 289 const query: Sequelize.FindOptions<VideoChannelAttributes> = {
259 where: { 290 where: {
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts
index e62e25a82..a0ac43e1e 100644
--- a/server/models/video/video-interface.ts
+++ b/server/models/video/video-interface.ts
@@ -69,6 +69,7 @@ export namespace VideoMethods {
69 export type LoadAndPopulateAccount = (id: number) => Bluebird<VideoInstance> 69 export type LoadAndPopulateAccount = (id: number) => Bluebird<VideoInstance>
70 export type LoadAndPopulateAccountAndPodAndTags = (id: number) => Bluebird<VideoInstance> 70 export type LoadAndPopulateAccountAndPodAndTags = (id: number) => Bluebird<VideoInstance>
71 export type LoadByUUIDAndPopulateAccountAndPodAndTags = (uuid: string) => Bluebird<VideoInstance> 71 export type LoadByUUIDAndPopulateAccountAndPodAndTags = (uuid: string) => Bluebird<VideoInstance>
72 export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
72 73
73 export type RemoveThumbnail = (this: VideoInstance) => Promise<void> 74 export type RemoveThumbnail = (this: VideoInstance) => Promise<void>
74 export type RemovePreview = (this: VideoInstance) => Promise<void> 75 export type RemovePreview = (this: VideoInstance) => Promise<void>
@@ -89,6 +90,7 @@ export interface VideoClass {
89 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID 90 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
90 loadByUUID: VideoMethods.LoadByUUID 91 loadByUUID: VideoMethods.LoadByUUID
91 loadByUrl: VideoMethods.LoadByUrl 92 loadByUrl: VideoMethods.LoadByUrl
93 loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
92 loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID 94 loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
93 loadByUUIDAndPopulateAccountAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndPodAndTags 95 loadByUUIDAndPopulateAccountAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndPodAndTags
94 searchAndPopulateAccountAndPodAndTags: VideoMethods.SearchAndPopulateAccountAndPodAndTags 96 searchAndPopulateAccountAndPodAndTags: VideoMethods.SearchAndPopulateAccountAndPodAndTags
@@ -109,7 +111,10 @@ export interface VideoAttributes {
109 likes?: number 111 likes?: number
110 dislikes?: number 112 dislikes?: number
111 remote: boolean 113 remote: boolean
112 url: string 114 url?: string
115
116 createdAt?: Date
117 updatedAt?: Date
113 118
114 parentId?: number 119 parentId?: number
115 channelId?: number 120 channelId?: number
@@ -120,9 +125,6 @@ export interface VideoAttributes {
120} 125}
121 126
122export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> { 127export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
123 createdAt: Date
124 updatedAt: Date
125
126 createPreview: VideoMethods.CreatePreview 128 createPreview: VideoMethods.CreatePreview
127 createThumbnail: VideoMethods.CreateThumbnail 129 createThumbnail: VideoMethods.CreateThumbnail
128 createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash 130 createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash
@@ -158,4 +160,3 @@ export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.In
158} 160}
159 161
160export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {} 162export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {}
161
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 94af1ece5..b5d333347 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -25,7 +25,8 @@ import {
25 statPromise, 25 statPromise,
26 generateImageFromVideoFile, 26 generateImageFromVideoFile,
27 transcode, 27 transcode,
28 getVideoFileHeight 28 getVideoFileHeight,
29 getActivityPubUrl
29} from '../../helpers' 30} from '../../helpers'
30import { 31import {
31 CONFIG, 32 CONFIG,
@@ -88,7 +89,7 @@ let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccount
88let listOwnedByAccount: VideoMethods.ListOwnedByAccount 89let listOwnedByAccount: VideoMethods.ListOwnedByAccount
89let load: VideoMethods.Load 90let load: VideoMethods.Load
90let loadByUUID: VideoMethods.LoadByUUID 91let loadByUUID: VideoMethods.LoadByUUID
91let loadByUrl: VideoMethods.LoadByUrl 92let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
92let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID 93let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
93let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount 94let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount
94let loadAndPopulateAccountAndPodAndTags: VideoMethods.LoadAndPopulateAccountAndPodAndTags 95let loadAndPopulateAccountAndPodAndTags: VideoMethods.LoadAndPopulateAccountAndPodAndTags
@@ -277,6 +278,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
277 loadAndPopulateAccount, 278 loadAndPopulateAccount,
278 loadAndPopulateAccountAndPodAndTags, 279 loadAndPopulateAccountAndPodAndTags,
279 loadByHostAndUUID, 280 loadByHostAndUUID,
281 loadByUUIDOrURL,
280 loadByUUID, 282 loadByUUID,
281 loadLocalVideoByUUID, 283 loadLocalVideoByUUID,
282 loadByUUIDAndPopulateAccountAndPodAndTags, 284 loadByUUIDAndPopulateAccountAndPodAndTags,
@@ -595,6 +597,7 @@ toActivityPubObject = function (this: VideoInstance) {
595 597
596 const videoObject: VideoTorrentObject = { 598 const videoObject: VideoTorrentObject = {
597 type: 'Video', 599 type: 'Video',
600 id: getActivityPubUrl('video', this.uuid),
598 name: this.name, 601 name: this.name,
599 // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration 602 // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
600 duration: 'PT' + this.duration + 'S', 603 duration: 'PT' + this.duration + 'S',
@@ -731,6 +734,7 @@ getCategoryLabel = function (this: VideoInstance) {
731 734
732getLicenceLabel = function (this: VideoInstance) { 735getLicenceLabel = function (this: VideoInstance) {
733 let licenceLabel = VIDEO_LICENCES[this.licence] 736 let licenceLabel = VIDEO_LICENCES[this.licence]
737
734 // Maybe our pod is not up to date and there are new licences since our version 738 // Maybe our pod is not up to date and there are new licences since our version
735 if (!licenceLabel) licenceLabel = 'Unknown' 739 if (!licenceLabel) licenceLabel = 'Unknown'
736 740
@@ -946,6 +950,22 @@ loadByUUID = function (uuid: string, t?: Sequelize.Transaction) {
946 return Video.findOne(query) 950 return Video.findOne(query)
947} 951}
948 952
953loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transaction) {
954 const query: Sequelize.FindOptions<VideoAttributes> = {
955 where: {
956 [Sequelize.Op.or]: [
957 { uuid },
958 { url }
959 ]
960 },
961 include: [ Video['sequelize'].models.VideoFile ]
962 }
963
964 if (t !== undefined) query.transaction = t
965
966 return Video.findOne(query)
967}
968
949loadLocalVideoByUUID = function (uuid: string, t?: Sequelize.Transaction) { 969loadLocalVideoByUUID = function (uuid: string, t?: Sequelize.Transaction) {
950 const query: Sequelize.FindOptions<VideoAttributes> = { 970 const query: Sequelize.FindOptions<VideoAttributes> = {
951 where: { 971 where: {