]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/video/video-interface.ts
4b5ae08c20f2a6bcb77f0caa5b7cc05ceff403a9
[github/Chocobozzz/PeerTube.git] / server / models / video / video-interface.ts
1 import * as Sequelize from 'sequelize'
2 import * as Promise from 'bluebird'
3
4 import { AuthorInstance } from './author-interface'
5 import { TagAttributes, TagInstance } from './tag-interface'
6 import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
7
8 // Don't use barrel, import just what we need
9 import {
10 Video as FormattedVideo,
11 VideoDetails as FormattedDetailsVideo
12 } from '../../../shared/models/videos/video.model'
13 import { RemoteVideoUpdateData } from '../../../shared/models/pods/remote-video/remote-video-update-request.model'
14 import { RemoteVideoCreateData } from '../../../shared/models/pods/remote-video/remote-video-create-request.model'
15 import { ResultList } from '../../../shared/models/result-list.model'
16 import { VideoChannelInstance } from './video-channel-interface'
17
18 export namespace VideoMethods {
19 export type GetThumbnailName = (this: VideoInstance) => string
20 export type GetPreviewName = (this: VideoInstance) => string
21 export type IsOwned = (this: VideoInstance) => boolean
22 export type ToFormattedJSON = (this: VideoInstance) => FormattedVideo
23 export type ToFormattedDetailsJSON = (this: VideoInstance) => FormattedDetailsVideo
24
25 export type GetOriginalFile = (this: VideoInstance) => VideoFileInstance
26 export type GetTorrentFileName = (this: VideoInstance, videoFile: VideoFileInstance) => string
27 export type GetVideoFilename = (this: VideoInstance, videoFile: VideoFileInstance) => string
28 export type CreatePreview = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string>
29 export type CreateThumbnail = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string>
30 export type GetVideoFilePath = (this: VideoInstance, videoFile: VideoFileInstance) => string
31 export type CreateTorrentAndSetInfoHash = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
32
33 export type ToAddRemoteJSON = (this: VideoInstance) => Promise<RemoteVideoCreateData>
34 export type ToUpdateRemoteJSON = (this: VideoInstance) => RemoteVideoUpdateData
35
36 export type OptimizeOriginalVideofile = (this: VideoInstance) => Promise<void>
37 export type TranscodeOriginalVideofile = (this: VideoInstance, resolution: number) => Promise<void>
38 export type GetOriginalFileHeight = (this: VideoInstance) => Promise<number>
39 export type GetEmbedPath = (this: VideoInstance) => string
40 export type GetThumbnailPath = (this: VideoInstance) => string
41 export type GetPreviewPath = (this: VideoInstance) => string
42
43 // Return thumbnail name
44 export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string) => Promise<string>
45
46 export type List = () => Promise<VideoInstance[]>
47 export type ListOwnedAndPopulateAuthorAndTags = () => Promise<VideoInstance[]>
48 export type ListOwnedByAuthor = (author: string) => Promise<VideoInstance[]>
49
50 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoInstance> >
51 export type SearchAndPopulateAuthorAndPodAndTags = (
52 value: string,
53 field: string,
54 start: number,
55 count: number,
56 sort: string
57 ) => Promise< ResultList<VideoInstance> >
58
59 export type Load = (id: number) => Promise<VideoInstance>
60 export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
61 export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
62 export type LoadAndPopulateAuthor = (id: number) => Promise<VideoInstance>
63 export type LoadAndPopulateAuthorAndPodAndTags = (id: number) => Promise<VideoInstance>
64 export type LoadByUUIDAndPopulateAuthorAndPodAndTags = (uuid: string) => Promise<VideoInstance>
65
66 export type RemoveThumbnail = (this: VideoInstance) => Promise<void>
67 export type RemovePreview = (this: VideoInstance) => Promise<void>
68 export type RemoveFile = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
69 export type RemoveTorrent = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
70 }
71
72 export interface VideoClass {
73 generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
74 list: VideoMethods.List
75 listForApi: VideoMethods.ListForApi
76 listOwnedAndPopulateAuthorAndTags: VideoMethods.ListOwnedAndPopulateAuthorAndTags
77 listOwnedByAuthor: VideoMethods.ListOwnedByAuthor
78 load: VideoMethods.Load
79 loadAndPopulateAuthor: VideoMethods.LoadAndPopulateAuthor
80 loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
81 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
82 loadByUUID: VideoMethods.LoadByUUID
83 loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
84 searchAndPopulateAuthorAndPodAndTags: VideoMethods.SearchAndPopulateAuthorAndPodAndTags
85 }
86
87 export interface VideoAttributes {
88 id?: number
89 uuid?: string
90 name: string
91 category: number
92 licence: number
93 language: number
94 nsfw: boolean
95 description: string
96 duration: number
97 views?: number
98 likes?: number
99 dislikes?: number
100 remote: boolean
101
102 channelId?: number
103
104 VideoChannel?: VideoChannelInstance
105 Tags?: TagInstance[]
106 VideoFiles?: VideoFileInstance[]
107 }
108
109 export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
110 createdAt: Date
111 updatedAt: Date
112
113 createPreview: VideoMethods.CreatePreview
114 createThumbnail: VideoMethods.CreateThumbnail
115 createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash
116 getOriginalFile: VideoMethods.GetOriginalFile
117 getPreviewName: VideoMethods.GetPreviewName
118 getPreviewPath: VideoMethods.GetPreviewPath
119 getThumbnailName: VideoMethods.GetThumbnailName
120 getThumbnailPath: VideoMethods.GetThumbnailPath
121 getTorrentFileName: VideoMethods.GetTorrentFileName
122 getVideoFilename: VideoMethods.GetVideoFilename
123 getVideoFilePath: VideoMethods.GetVideoFilePath
124 isOwned: VideoMethods.IsOwned
125 removeFile: VideoMethods.RemoveFile
126 removePreview: VideoMethods.RemovePreview
127 removeThumbnail: VideoMethods.RemoveThumbnail
128 removeTorrent: VideoMethods.RemoveTorrent
129 toAddRemoteJSON: VideoMethods.ToAddRemoteJSON
130 toFormattedJSON: VideoMethods.ToFormattedJSON
131 toFormattedDetailsJSON: VideoMethods.ToFormattedDetailsJSON
132 toUpdateRemoteJSON: VideoMethods.ToUpdateRemoteJSON
133 optimizeOriginalVideofile: VideoMethods.OptimizeOriginalVideofile
134 transcodeOriginalVideofile: VideoMethods.TranscodeOriginalVideofile
135 getOriginalFileHeight: VideoMethods.GetOriginalFileHeight
136 getEmbedPath: VideoMethods.GetEmbedPath
137
138 setTags: Sequelize.HasManySetAssociationsMixin<TagAttributes, string>
139 addVideoFile: Sequelize.HasManyAddAssociationMixin<VideoFileAttributes, string>
140 setVideoFiles: Sequelize.HasManySetAssociationsMixin<VideoFileAttributes, string>
141 }
142
143 export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {}