Add activitypub migration script
[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     field: string,
54     start: number,
55     count: number,
56     sort: string
57   ) => Bluebird< ResultList<VideoInstance> >
58
59   export type Load = (id: number) => Bluebird<VideoInstance>
60   export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
61   export type LoadByUrlAndPopulateAccount = (url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
62   export type LoadAndPopulateAccountAndServerAndTags = (id: number) => Bluebird<VideoInstance>
63   export type LoadByUUIDAndPopulateAccountAndServerAndTags = (uuid: string) => Bluebird<VideoInstance>
64   export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird<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   list: VideoMethods.List
74   listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
75   listForApi: VideoMethods.ListForApi
76   listUserVideosForApi: VideoMethods.ListUserVideosForApi
77   load: VideoMethods.Load
78   loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags
79   loadByUUID: VideoMethods.LoadByUUID
80   loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount
81   loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
82   loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags
83   searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags
84 }
85
86 export interface VideoAttributes {
87   id?: number
88   uuid?: string
89   name: string
90   category: number
91   licence: number
92   language: number
93   nsfw: boolean
94   description: string
95   duration: number
96   privacy: number
97   views?: number
98   likes?: number
99   dislikes?: number
100   remote: boolean
101   url?: string
102
103   createdAt?: Date
104   updatedAt?: Date
105
106   parentId?: number
107   channelId?: number
108
109   VideoChannel?: VideoChannelInstance
110   Tags?: TagInstance[]
111   VideoFiles?: VideoFileInstance[]
112   VideoShares?: VideoShareInstance[]
113   AccountVideoRates?: AccountVideoRateInstance[]
114 }
115
116 export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
117   createPreview: VideoMethods.CreatePreview
118   createThumbnail: VideoMethods.CreateThumbnail
119   createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash
120   getOriginalFile: VideoMethods.GetOriginalFile
121   getPreviewName: VideoMethods.GetPreviewName
122   getPreviewPath: VideoMethods.GetPreviewPath
123   getThumbnailName: VideoMethods.GetThumbnailName
124   getThumbnailPath: VideoMethods.GetThumbnailPath
125   getTorrentFileName: VideoMethods.GetTorrentFileName
126   getVideoFilename: VideoMethods.GetVideoFilename
127   getVideoFilePath: VideoMethods.GetVideoFilePath
128   isOwned: VideoMethods.IsOwned
129   removeFile: VideoMethods.RemoveFile
130   removePreview: VideoMethods.RemovePreview
131   removeThumbnail: VideoMethods.RemoveThumbnail
132   removeTorrent: VideoMethods.RemoveTorrent
133   toActivityPubObject: VideoMethods.ToActivityPubObject
134   toFormattedJSON: VideoMethods.ToFormattedJSON
135   toFormattedDetailsJSON: VideoMethods.ToFormattedDetailsJSON
136   optimizeOriginalVideofile: VideoMethods.OptimizeOriginalVideofile
137   transcodeOriginalVideofile: VideoMethods.TranscodeOriginalVideofile
138   getOriginalFileHeight: VideoMethods.GetOriginalFileHeight
139   getEmbedPath: VideoMethods.GetEmbedPath
140   getDescriptionPath: VideoMethods.GetDescriptionPath
141   getTruncatedDescription: VideoMethods.GetTruncatedDescription
142   getCategoryLabel: VideoMethods.GetCategoryLabel
143   getLicenceLabel: VideoMethods.GetLicenceLabel
144   getLanguageLabel: VideoMethods.GetLanguageLabel
145
146   setTags: Sequelize.HasManySetAssociationsMixin<TagAttributes, string>
147   addVideoFile: Sequelize.HasManyAddAssociationMixin<VideoFileAttributes, string>
148   setVideoFiles: Sequelize.HasManySetAssociationsMixin<VideoFileAttributes, string>
149 }
150
151 export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {}