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