Begin activitypub
[oweals/peertube.git] / server / models / video / video-interface.ts
1 import * as Sequelize from 'sequelize'
2 import * as Bluebird 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 import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'
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 ToActivityPubObject = (this: VideoInstance) => VideoTorrentObject
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   export type GetDescriptionPath = (this: VideoInstance) => string
42   export type GetTruncatedDescription = (this: VideoInstance) => string
43   export type GetCategoryLabel = (this: VideoInstance) => string
44   export type GetLicenceLabel = (this: VideoInstance) => string
45   export type GetLanguageLabel = (this: VideoInstance) => string
46
47   // Return thumbnail name
48   export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string) => Promise<string>
49
50   export type List = () => Bluebird<VideoInstance[]>
51   export type ListOwnedAndPopulateAccountAndTags = () => Bluebird<VideoInstance[]>
52   export type ListOwnedByAccount = (account: string) => Bluebird<VideoInstance[]>
53
54   export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> >
55   export type ListUserVideosForApi = (userId: number, start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> >
56   export type SearchAndPopulateAccountAndPodAndTags = (
57     value: string,
58     field: string,
59     start: number,
60     count: number,
61     sort: string
62   ) => Bluebird< ResultList<VideoInstance> >
63
64   export type Load = (id: number) => Bluebird<VideoInstance>
65   export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
66   export type LoadByUrl = (url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
67   export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
68   export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
69   export type LoadAndPopulateAccount = (id: number) => Bluebird<VideoInstance>
70   export type LoadAndPopulateAccountAndPodAndTags = (id: number) => Bluebird<VideoInstance>
71   export type LoadByUUIDAndPopulateAccountAndPodAndTags = (uuid: string) => Bluebird<VideoInstance>
72
73   export type RemoveThumbnail = (this: VideoInstance) => Promise<void>
74   export type RemovePreview = (this: VideoInstance) => Promise<void>
75   export type RemoveFile = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
76   export type RemoveTorrent = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<void>
77 }
78
79 export interface VideoClass {
80   generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
81   list: VideoMethods.List
82   listForApi: VideoMethods.ListForApi
83   listUserVideosForApi: VideoMethods.ListUserVideosForApi
84   listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
85   listOwnedByAccount: VideoMethods.ListOwnedByAccount
86   load: VideoMethods.Load
87   loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount
88   loadAndPopulateAccountAndPodAndTags: VideoMethods.LoadAndPopulateAccountAndPodAndTags
89   loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
90   loadByUUID: VideoMethods.LoadByUUID
91   loadByUrl: VideoMethods.LoadByUrl
92   loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
93   loadByUUIDAndPopulateAccountAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndPodAndTags
94   searchAndPopulateAccountAndPodAndTags: VideoMethods.SearchAndPopulateAccountAndPodAndTags
95 }
96
97 export interface VideoAttributes {
98   id?: number
99   uuid?: string
100   name: string
101   category: number
102   licence: number
103   language: number
104   nsfw: boolean
105   description: string
106   duration: number
107   privacy: number
108   views?: number
109   likes?: number
110   dislikes?: number
111   remote: boolean
112   url: string
113
114   parentId?: number
115   channelId?: number
116
117   VideoChannel?: VideoChannelInstance
118   Tags?: TagInstance[]
119   VideoFiles?: VideoFileInstance[]
120 }
121
122 export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
123   createdAt: Date
124   updatedAt: Date
125
126   createPreview: VideoMethods.CreatePreview
127   createThumbnail: VideoMethods.CreateThumbnail
128   createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash
129   getOriginalFile: VideoMethods.GetOriginalFile
130   getPreviewName: VideoMethods.GetPreviewName
131   getPreviewPath: VideoMethods.GetPreviewPath
132   getThumbnailName: VideoMethods.GetThumbnailName
133   getThumbnailPath: VideoMethods.GetThumbnailPath
134   getTorrentFileName: VideoMethods.GetTorrentFileName
135   getVideoFilename: VideoMethods.GetVideoFilename
136   getVideoFilePath: VideoMethods.GetVideoFilePath
137   isOwned: VideoMethods.IsOwned
138   removeFile: VideoMethods.RemoveFile
139   removePreview: VideoMethods.RemovePreview
140   removeThumbnail: VideoMethods.RemoveThumbnail
141   removeTorrent: VideoMethods.RemoveTorrent
142   toActivityPubObject: VideoMethods.ToActivityPubObject
143   toFormattedJSON: VideoMethods.ToFormattedJSON
144   toFormattedDetailsJSON: VideoMethods.ToFormattedDetailsJSON
145   optimizeOriginalVideofile: VideoMethods.OptimizeOriginalVideofile
146   transcodeOriginalVideofile: VideoMethods.TranscodeOriginalVideofile
147   getOriginalFileHeight: VideoMethods.GetOriginalFileHeight
148   getEmbedPath: VideoMethods.GetEmbedPath
149   getDescriptionPath: VideoMethods.GetDescriptionPath
150   getTruncatedDescription: VideoMethods.GetTruncatedDescription
151   getCategoryLabel: VideoMethods.GetCategoryLabel
152   getLicenceLabel: VideoMethods.GetLicenceLabel
153   getLanguageLabel: VideoMethods.GetLanguageLabel
154
155   setTags: Sequelize.HasManySetAssociationsMixin<TagAttributes, string>
156   addVideoFile: Sequelize.HasManyAddAssociationMixin<VideoFileAttributes, string>
157   setVideoFiles: Sequelize.HasManySetAssociationsMixin<VideoFileAttributes, string>
158 }
159
160 export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {}
161