From 6fcd19ba737f1f5614a56c6925adb882dea43b8d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Jul 2017 13:26:25 +0200 Subject: Move to promises Closes https://github.com/Chocobozzz/PeerTube/issues/74 --- server/models/video/video-interface.ts | 70 +++++++++++++++------------------- 1 file changed, 30 insertions(+), 40 deletions(-) (limited to 'server/models/video/video-interface.ts') diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts index 4b591b9e7..c3e3365d5 100644 --- a/server/models/video/video-interface.ts +++ b/server/models/video/video-interface.ts @@ -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 @@ -56,46 +58,32 @@ export namespace VideoMethods { export type IsOwned = (this: VideoInstance) => boolean export type ToFormatedJSON = (this: VideoInstance) => FormatedVideo - export type ToAddRemoteJSONCallback = (err: Error, videoFormated?: FormatedAddRemoteVideo) => void - export type ToAddRemoteJSON = (this: VideoInstance, callback: ToAddRemoteJSONCallback) => void - + export type ToAddRemoteJSON = (this: VideoInstance) => Promise export type ToUpdateRemoteJSON = (this: VideoInstance) => FormatedUpdateRemoteVideo - export type TranscodeVideofileCallback = (err: Error) => void - export type TranscodeVideofile = (this: VideoInstance, 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 TranscodeVideofile = (this: VideoInstance) => Promise + + // Return thumbnail name + export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string) => Promise + export type GetDurationFromFile = (videoPath: string) => Promise + + export type List = () => Promise + export type ListOwnedAndPopulateAuthorAndTags = () => Promise + export type ListOwnedByAuthor = (author: string) => Promise + + export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList > + export type SearchAndPopulateAuthorAndPodAndTags = ( + value: string, + field: string, + start: number, + count: number, + sort: string + ) => Promise< ResultList > + + export type Load = (id: string) => Promise + export type LoadByHostAndRemoteId = (fromHost: string, remoteId: string) => Promise + export type LoadAndPopulateAuthor = (id: string) => Promise + export type LoadAndPopulateAuthorAndPodAndTags = (id: string) => Promise } export interface VideoClass { @@ -139,7 +127,7 @@ export interface VideoAttributes { dislikes?: number Author?: AuthorInstance - Tags?: VideoTagInstance[] + Tags?: TagInstance[] } export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance { @@ -157,6 +145,8 @@ export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.In toAddRemoteJSON: VideoMethods.ToAddRemoteJSON toUpdateRemoteJSON: VideoMethods.ToUpdateRemoteJSON transcodeVideofile: VideoMethods.TranscodeVideofile + + setTags: Sequelize.HasManySetAssociationsMixin } export interface VideoModel extends VideoClass, Sequelize.Model {} -- cgit v1.2.3