Make some fields optional when uploading a video
[oweals/peertube.git] / server / models / video / video-interface.ts
1 import * as Bluebird from 'bluebird'
2 import * as Sequelize from 'sequelize'
3 import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'
4 import { ResultList } from '../../../shared/models/result-list.model'
5 import { Video as FormattedVideo, VideoDetails as FormattedDetailsVideo } from '../../../shared/models/videos/video.model'
6 import { AccountVideoRateInstance } from '../account/account-video-rate-interface'
7
8 import { TagAttributes, TagInstance } from './tag-interface'
9 import { VideoChannelInstance } from './video-channel-interface'
10 import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
11 import { VideoShareInstance } from './video-share-interface'
12
13 export namespace VideoMethods {
14   export type GetThumbnailName = (this: VideoInstance) => string
15   export type GetPreviewName = (this: VideoInstance) => string
16   export type IsOwned = (this: VideoInstance) => boolean
17   export type ToFormattedJSON = (this: VideoInstance) => FormattedVideo
18   export type ToFormattedDetailsJSON = (this: VideoInstance) => FormattedDetailsVideo
19
20   export type GetOriginalFile = (this: VideoInstance) => VideoFileInstance
21   export type GetTorrentFileName = (this: VideoInstance, videoFile: VideoFileInstance) => string
22   export type GetVideoFilename = (this: VideoInstance, videoFile: VideoFileInstance) => string
23   export type CreatePreview = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string>
24   export type CreateThumbnail = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string>
25   export type GetVideoFilePath = (this: VideoInstance, videoFile: VideoFileInstance) => string
26   export type CreateTorrentAndSetInfoHash = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
27
28   export type ToActivityPubObject = (this: VideoInstance) => VideoTorrentObject
29
30   export type OptimizeOriginalVideofile = (this: VideoInstance) => Promise<void>
31   export type TranscodeOriginalVideofile = (this: VideoInstance, resolution: number) => Promise<void>
32   export type GetOriginalFileHeight = (this: VideoInstance) => Promise<number>
33   export type GetEmbedPath = (this: VideoInstance) => string
34   export type GetThumbnailPath = (this: VideoInstance) => string
35   export type GetPreviewPath = (this: VideoInstance) => string
36   export type GetDescriptionPath = (this: VideoInstance) => string
37   export type GetTruncatedDescription = (this: VideoInstance) => string
38   export type GetCategoryLabel = (this: VideoInstance) => string
39   export type GetLicenceLabel = (this: VideoInstance) => string
40   export type GetLanguageLabel = (this: VideoInstance) => string
41
42   export type List = () => Bluebird<VideoInstance[]>
43
44   export type ListAllAndSharedByAccountForOutbox = (
45     accountId: number,
46     start: number,
47     count: number
48   ) => Bluebird< ResultList<VideoInstance> >
49   export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> >
50   export type ListUserVideosForApi = (userId: number, start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> >
51   export type SearchAndPopulateAccountAndServerAndTags = (
52     value: string,
53     start: number,
54     count: number,
55     sort: string
56   ) => Bluebird< ResultList<VideoInstance> >
57
58   export type Load = (id: number) => Bluebird<VideoInstance>
59   export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
60   export type LoadByUrlAndPopulateAccount = (url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
61   export type LoadAndPopulateAccountAndServerAndTags = (id: number) => Bluebird<VideoInstance>
62   export type LoadByUUIDAndPopulateAccountAndServerAndTags = (uuid: string) => Bluebird<VideoInstance>
63   export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
64
65   export type RemoveThumbnail = (this: VideoInstance) => Promise<void>
66   export type RemovePreview = (this: VideoInstance) => Promise<void>
67   export type RemoveFile = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
68   export type RemoveTorrent = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
69 }
70
71 export interface VideoClass {
72   list: VideoMethods.List
73   listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
74   listForApi: VideoMethods.ListForApi
75   listUserVideosForApi: VideoMethods.ListUserVideosForApi
76   load: VideoMethods.Load
77   loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags
78   loadByUUID: VideoMethods.LoadByUUID
79   loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount
80   loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
81   loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags
82   searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags
83 }
84
85 export interface VideoAttributes {
86   id?: number
87   uuid?: string
88   name: string
89   category: number
90   licence: number
91   language: number
92   nsfw: boolean
93   description: string
94   duration: number
95   privacy: number
96   views?: number
97   likes?: number
98   dislikes?: number
99   remote: boolean
100   url?: string
101
102   createdAt?: Date
103   updatedAt?: Date
104
105   parentId?: number
106   channelId?: number
107
108   VideoChannel?: VideoChannelInstance
109   Tags?: TagInstance[]
110   VideoFiles?: VideoFileInstance[]
111   VideoShares?: VideoShareInstance[]
112   AccountVideoRates?: AccountVideoRateInstance[]
113 }
114
115 export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
116   createPreview: VideoMethods.CreatePreview
117   createThumbnail: VideoMethods.CreateThumbnail
118   createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash
119   getOriginalFile: VideoMethods.GetOriginalFile
120   getPreviewName: VideoMethods.GetPreviewName
121   getPreviewPath: VideoMethods.GetPreviewPath
122   getThumbnailName: VideoMethods.GetThumbnailName
123   getThumbnailPath: VideoMethods.GetThumbnailPath
124   getTorrentFileName: VideoMethods.GetTorrentFileName
125   getVideoFilename: VideoMethods.GetVideoFilename
126   getVideoFilePath: VideoMethods.GetVideoFilePath
127   isOwned: VideoMethods.IsOwned
128   removeFile: VideoMethods.RemoveFile
129   removePreview: VideoMethods.RemovePreview
130   removeThumbnail: VideoMethods.RemoveThumbnail
131   removeTorrent: VideoMethods.RemoveTorrent
132   toActivityPubObject: VideoMethods.ToActivityPubObject
133   toFormattedJSON: VideoMethods.ToFormattedJSON
134   toFormattedDetailsJSON: VideoMethods.ToFormattedDetailsJSON
135   optimizeOriginalVideofile: VideoMethods.OptimizeOriginalVideofile
136   transcodeOriginalVideofile: VideoMethods.TranscodeOriginalVideofile
137   getOriginalFileHeight: VideoMethods.GetOriginalFileHeight
138   getEmbedPath: VideoMethods.GetEmbedPath
139   getDescriptionPath: VideoMethods.GetDescriptionPath
140   getTruncatedDescription: VideoMethods.GetTruncatedDescription
141   getCategoryLabel: VideoMethods.GetCategoryLabel
142   getLicenceLabel: VideoMethods.GetLicenceLabel
143   getLanguageLabel: VideoMethods.GetLanguageLabel
144
145   setTags: Sequelize.HasManySetAssociationsMixin<TagAttributes, string>
146   addVideoFile: Sequelize.HasManyAddAssociationMixin<VideoFileAttributes, string>
147   setVideoFiles: Sequelize.HasManySetAssociationsMixin<VideoFileAttributes, string>
148 }
149
150 export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {}