]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-interface.ts
Async signature and various fixes
[github/Chocobozzz/PeerTube.git] / server / models / video / video-interface.ts
index 71b9b0a69615d01bcec2567cb0e2fd944dc15dc8..c3e3365d595f280bbfdd893fafcf34e91ee0d97e 100644 (file)
@@ -1,10 +1,12 @@
 import * as Sequelize from 'sequelize'
+import * as Promise from 'bluebird'
 
 import { AuthorInstance } from './author-interface'
-import { VideoTagInstance } from './video-tag-interface'
+import { TagAttributes, TagInstance } from './tag-interface'
 
 // Don't use barrel, import just what we need
 import { Video as FormatedVideo } from '../../../shared/models/video.model'
+import { ResultList } from '../../../shared/models/result-list.model'
 
 export type FormatedAddRemoteVideo = {
   name: string
@@ -48,54 +50,40 @@ export type FormatedUpdateRemoteVideo = {
 }
 
 export namespace VideoMethods {
-  export type GenerateMagnetUri = () => string
-  export type GetVideoFilename = () => string
-  export type GetThumbnailName = () => string
-  export type GetPreviewName = () => string
-  export type GetTorrentName = () => string
-  export type IsOwned = () => boolean
-  export type ToFormatedJSON = () => FormatedVideo
-
-  export type ToAddRemoteJSONCallback = (err: Error, videoFormated?: FormatedAddRemoteVideo) => void
-  export type ToAddRemoteJSON = (callback: ToAddRemoteJSONCallback) => void
-
-  export type ToUpdateRemoteJSON = () => FormatedUpdateRemoteVideo
-
-  export type TranscodeVideofileCallback = (err: Error) => void
-  export type TranscodeVideofile = (callback: TranscodeVideofileCallback) => void
-
-  export type GenerateThumbnailFromDataCallback = (err: Error, thumbnailName?: string) => void
-  export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string, callback: GenerateThumbnailFromDataCallback) => void
-
-  export type GetDurationFromFileCallback = (err: Error, duration?: number) => void
-  export type GetDurationFromFile = (videoPath, callback) => void
-
-  export type ListCallback = (err: Error, videoInstances: VideoInstance[]) => void
-  export type List = (callback: ListCallback) => void
-
-  export type ListForApiCallback = (err: Error, videoInstances?: VideoInstance[], total?: number) => void
-  export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void
-
-  export type LoadByHostAndRemoteIdCallback = (err: Error, videoInstance: VideoInstance) => void
-  export type LoadByHostAndRemoteId = (fromHost: string, remoteId: string, callback: LoadByHostAndRemoteIdCallback) => void
-
-  export type ListOwnedAndPopulateAuthorAndTagsCallback = (err: Error, videoInstances: VideoInstance[]) => void
-  export type ListOwnedAndPopulateAuthorAndTags = (callback: ListOwnedAndPopulateAuthorAndTagsCallback) => void
-
-  export type ListOwnedByAuthorCallback = (err: Error, videoInstances: VideoInstance[]) => void
-  export type ListOwnedByAuthor = (author: string, callback: ListOwnedByAuthorCallback) => void
-
-  export type LoadCallback = (err: Error, videoInstance: VideoInstance) => void
-  export type Load = (id: string, callback: LoadCallback) => void
-
-  export type LoadAndPopulateAuthorCallback = (err: Error, videoInstance: VideoInstance) => void
-  export type LoadAndPopulateAuthor = (id: string, callback: LoadAndPopulateAuthorCallback) => void
-
-  export type LoadAndPopulateAuthorAndPodAndTagsCallback = (err: Error, videoInstance: VideoInstance) => void
-  export type LoadAndPopulateAuthorAndPodAndTags = (id: string, callback: LoadAndPopulateAuthorAndPodAndTagsCallback) => void
-
-  export type SearchAndPopulateAuthorAndPodAndTagsCallback = (err: Error, videoInstances?: VideoInstance[], total?: number) => void
-  export type SearchAndPopulateAuthorAndPodAndTags = (value: string, field: string, start: number, count: number, sort: string, callback: SearchAndPopulateAuthorAndPodAndTagsCallback) => void
+  export type GenerateMagnetUri = (this: VideoInstance) => string
+  export type GetVideoFilename = (this: VideoInstance) => string
+  export type GetThumbnailName = (this: VideoInstance) => string
+  export type GetPreviewName = (this: VideoInstance) => string
+  export type GetTorrentName = (this: VideoInstance) => string
+  export type IsOwned = (this: VideoInstance) => boolean
+  export type ToFormatedJSON = (this: VideoInstance) => FormatedVideo
+
+  export type ToAddRemoteJSON = (this: VideoInstance) => Promise<FormatedAddRemoteVideo>
+  export type ToUpdateRemoteJSON = (this: VideoInstance) => FormatedUpdateRemoteVideo
+
+  export type TranscodeVideofile = (this: VideoInstance) => Promise<void>
+
+  // Return thumbnail name
+  export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string) => Promise<string>
+  export type GetDurationFromFile = (videoPath: string) => Promise<number>
+
+  export type List = () => Promise<VideoInstance[]>
+  export type ListOwnedAndPopulateAuthorAndTags = () => Promise<VideoInstance[]>
+  export type ListOwnedByAuthor = (author: string) => Promise<VideoInstance[]>
+
+  export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoInstance> >
+  export type SearchAndPopulateAuthorAndPodAndTags = (
+    value: string,
+    field: string,
+    start: number,
+    count: number,
+    sort: string
+  ) => Promise< ResultList<VideoInstance> >
+
+  export type Load = (id: string) => Promise<VideoInstance>
+  export type LoadByHostAndRemoteId = (fromHost: string, remoteId: string) => Promise<VideoInstance>
+  export type LoadAndPopulateAuthor = (id: string) => Promise<VideoInstance>
+  export type LoadAndPopulateAuthorAndPodAndTags = (id: string) => Promise<VideoInstance>
 }
 
 export interface VideoClass {
@@ -139,13 +127,26 @@ export interface VideoAttributes {
   dislikes?: number
 
   Author?: AuthorInstance
-  Tags?: VideoTagInstance[]
+  Tags?: TagInstance[]
 }
 
 export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
   id: string
   createdAt: Date
   updatedAt: Date
+
+  generateMagnetUri: VideoMethods.GenerateMagnetUri
+  getVideoFilename: VideoMethods.GetVideoFilename
+  getThumbnailName: VideoMethods.GetThumbnailName
+  getPreviewName: VideoMethods.GetPreviewName
+  getTorrentName: VideoMethods.GetTorrentName
+  isOwned: VideoMethods.IsOwned
+  toFormatedJSON: VideoMethods.ToFormatedJSON
+  toAddRemoteJSON: VideoMethods.ToAddRemoteJSON
+  toUpdateRemoteJSON: VideoMethods.ToUpdateRemoteJSON
+  transcodeVideofile: VideoMethods.TranscodeVideofile
+
+  setTags: Sequelize.HasManySetAssociationsMixin<TagAttributes, string>
 }
 
 export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {}