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