]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/models/video/video-interface.ts
Be tolerant with remote requests
[github/Chocobozzz/PeerTube.git] / server / models / video / video-interface.ts
... / ...
CommitLineData
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3
4import { TagAttributes, TagInstance } from './tag-interface'
5import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
6
7// Don't use barrel, import just what we need
8import {
9 Video as FormattedVideo,
10 VideoDetails as FormattedDetailsVideo
11} from '../../../shared/models/videos/video.model'
12import { RemoteVideoUpdateData } from '../../../shared/models/pods/remote-video/remote-video-update-request.model'
13import { RemoteVideoCreateData } from '../../../shared/models/pods/remote-video/remote-video-create-request.model'
14import { ResultList } from '../../../shared/models/result-list.model'
15import { VideoChannelInstance } from './video-channel-interface'
16
17export 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 LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
61 export type LoadAndPopulateAuthor = (id: number) => Promise<VideoInstance>
62 export type LoadAndPopulateAuthorAndPodAndTags = (id: number) => Promise<VideoInstance>
63 export type LoadByUUIDAndPopulateAuthorAndPodAndTags = (uuid: string) => Promise<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
71export interface VideoClass {
72 generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
73 list: VideoMethods.List
74 listForApi: VideoMethods.ListForApi
75 listOwnedAndPopulateAuthorAndTags: VideoMethods.ListOwnedAndPopulateAuthorAndTags
76 listOwnedByAuthor: VideoMethods.ListOwnedByAuthor
77 load: VideoMethods.Load
78 loadAndPopulateAuthor: VideoMethods.LoadAndPopulateAuthor
79 loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
80 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
81 loadByUUID: VideoMethods.LoadByUUID
82 loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
83 searchAndPopulateAuthorAndPodAndTags: VideoMethods.SearchAndPopulateAuthorAndPodAndTags
84}
85
86export 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 views?: number
97 likes?: number
98 dislikes?: number
99 remote: boolean
100
101 channelId?: number
102
103 VideoChannel?: VideoChannelInstance
104 Tags?: TagInstance[]
105 VideoFiles?: VideoFileInstance[]
106}
107
108export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
109 createdAt: Date
110 updatedAt: Date
111
112 createPreview: VideoMethods.CreatePreview
113 createThumbnail: VideoMethods.CreateThumbnail
114 createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash
115 getOriginalFile: VideoMethods.GetOriginalFile
116 getPreviewName: VideoMethods.GetPreviewName
117 getPreviewPath: VideoMethods.GetPreviewPath
118 getThumbnailName: VideoMethods.GetThumbnailName
119 getThumbnailPath: VideoMethods.GetThumbnailPath
120 getTorrentFileName: VideoMethods.GetTorrentFileName
121 getVideoFilename: VideoMethods.GetVideoFilename
122 getVideoFilePath: VideoMethods.GetVideoFilePath
123 isOwned: VideoMethods.IsOwned
124 removeFile: VideoMethods.RemoveFile
125 removePreview: VideoMethods.RemovePreview
126 removeThumbnail: VideoMethods.RemoveThumbnail
127 removeTorrent: VideoMethods.RemoveTorrent
128 toAddRemoteJSON: VideoMethods.ToAddRemoteJSON
129 toFormattedJSON: VideoMethods.ToFormattedJSON
130 toFormattedDetailsJSON: VideoMethods.ToFormattedDetailsJSON
131 toUpdateRemoteJSON: VideoMethods.ToUpdateRemoteJSON
132 optimizeOriginalVideofile: VideoMethods.OptimizeOriginalVideofile
133 transcodeOriginalVideofile: VideoMethods.TranscodeOriginalVideofile
134 getOriginalFileHeight: VideoMethods.GetOriginalFileHeight
135 getEmbedPath: VideoMethods.GetEmbedPath
136
137 setTags: Sequelize.HasManySetAssociationsMixin<TagAttributes, string>
138 addVideoFile: Sequelize.HasManyAddAssociationMixin<VideoFileAttributes, string>
139 setVideoFiles: Sequelize.HasManySetAssociationsMixin<VideoFileAttributes, string>
140}
141
142export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {}