import * as Sequelize from 'sequelize'
import { database as db } from '../initializers/database'
+import { VideoTagInstance } from './video-tag-interface'
import {
logger,
isVideoNameValid,
let loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
let searchAndPopulateAuthorAndPodAndTags: VideoMethods.SearchAndPopulateAuthorAndPodAndTags
-export default function (sequelize, DataTypes) {
- Video = sequelize.define('Video',
+export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
+ Video = sequelize.define<VideoInstance, VideoAttributes>('Video',
{
id: {
type: DataTypes.UUID,
return Video
}
-function beforeValidate (video, options) {
+function beforeValidate (video: VideoInstance) {
// Put a fake infoHash if it does not exists yet
if (video.isOwned() && !video.infoHash) {
// 40 hexa length
}
}
-function beforeCreate (video, options) {
+function beforeCreate (video: VideoInstance, options: { transaction: Sequelize.Transaction }) {
return new Promise(function (resolve, reject) {
const tasks = []
})
}
-function afterDestroy (video, options) {
+function afterDestroy (video: VideoInstance) {
return new Promise(function (resolve, reject) {
const tasks = []
}
const xs = baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentName()
- const announce = baseUrlWs + '/tracker/socket'
+ const announce = [ baseUrlWs + '/tracker/socket' ]
const urlList = [ baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename() ]
const magnetHash = {
return this.remoteId === null
}
-toFormatedJSON = function () {
+toFormatedJSON = function (this: VideoInstance) {
let podHost
if (this.Author.Pod) {
views: this.views,
likes: this.likes,
dislikes: this.dislikes,
- tags: map(this.Tags, 'name'),
+ tags: map<VideoTagInstance, string>(this.Tags, 'name'),
thumbnailPath: join(STATIC_PATHS.THUMBNAILS, this.getThumbnailName()),
createdAt: this.createdAt,
updatedAt: this.updatedAt
return json
}
-toAddRemoteJSON = function (callback) {
+toAddRemoteJSON = function (callback: VideoMethods.ToAddRemoteJSONCallback) {
// Get thumbnail data to send to the other pod
const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())
fs.readFile(thumbnailPath, (err, thumbnailData) => {
author: this.Author.name,
duration: this.duration,
thumbnailData: thumbnailData.toString('binary'),
- tags: map(this.Tags, 'name'),
+ tags: map<VideoTagInstance, string>(this.Tags, 'name'),
createdAt: this.createdAt,
updatedAt: this.updatedAt,
extname: this.extname,
})
}
-toUpdateRemoteJSON = function (callback) {
+toUpdateRemoteJSON = function () {
const json = {
name: this.name,
category: this.category,
remoteId: this.id,
author: this.Author.name,
duration: this.duration,
- tags: map(this.Tags, 'name'),
+ tags: map<VideoTagInstance, string>(this.Tags, 'name'),
createdAt: this.createdAt,
updatedAt: this.updatedAt,
extname: this.extname,
return json
}
-transcodeVideofile = function (finalCallback) {
+transcodeVideofile = function (finalCallback: VideoMethods.TranscodeVideofileCallback) {
const video = this
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
video.save().asCallback(callback)
}
- ], function (err) {
+ ], function (err: Error) {
if (err) {
- // Autodescruction...
+ // Autodesctruction...
video.destroy().asCallback(function (err) {
if (err) logger.error('Cannot destruct video after transcoding failure.', { error: err })
})
// ------------------------------ STATICS ------------------------------
-generateThumbnailFromData = function (video, thumbnailData, callback) {
+generateThumbnailFromData = function (video: VideoInstance, thumbnailData: string, callback: VideoMethods.GenerateThumbnailFromDataCallback) {
// Creating the thumbnail for a remote video
const thumbnailName = video.getThumbnailName()
})
}
-getDurationFromFile = function (videoPath, callback) {
+getDurationFromFile = function (videoPath: string, callback: VideoMethods.GetDurationFromFileCallback) {
ffmpeg.ffprobe(videoPath, function (err, metadata) {
if (err) return callback(err)
})
}
-list = function (callback) {
+list = function (callback: VideoMethods.ListCallback) {
return Video.findAll().asCallback(callback)
}
-listForApi = function (start, count, sort, callback) {
+listForApi = function (start: number, count: number, sort: string, callback: VideoMethods.ListForApiCallback) {
// Exclude Blakclisted videos from the list
const query = {
distinct: true,
})
}
-loadByHostAndRemoteId = function (fromHost, remoteId, callback) {
+loadByHostAndRemoteId = function (fromHost: string, remoteId: string, callback: VideoMethods.LoadByHostAndRemoteIdCallback) {
const query = {
where: {
remoteId: remoteId
return Video.findOne(query).asCallback(callback)
}
-listOwnedAndPopulateAuthorAndTags = function (callback) {
+listOwnedAndPopulateAuthorAndTags = function (callback: VideoMethods.ListOwnedAndPopulateAuthorAndTagsCallback) {
// If remoteId is null this is *our* video
const query = {
where: {
return Video.findAll(query).asCallback(callback)
}
-listOwnedByAuthor = function (author, callback) {
+listOwnedByAuthor = function (author: string, callback: VideoMethods.ListOwnedByAuthorCallback) {
const query = {
where: {
remoteId: null
return Video.findAll(query).asCallback(callback)
}
-load = function (id, callback) {
+load = function (id: string, callback: VideoMethods.LoadCallback) {
return Video.findById(id).asCallback(callback)
}
-loadAndPopulateAuthor = function (id, callback) {
+loadAndPopulateAuthor = function (id: string, callback: VideoMethods.LoadAndPopulateAuthorCallback) {
const options = {
include: [ Video['sequelize'].models.Author ]
}
return Video.findById(id, options).asCallback(callback)
}
-loadAndPopulateAuthorAndPodAndTags = function (id, callback) {
+loadAndPopulateAuthorAndPodAndTags = function (id: string, callback: VideoMethods.LoadAndPopulateAuthorAndPodAndTagsCallback) {
const options = {
include: [
{
return Video.findById(id, options).asCallback(callback)
}
-searchAndPopulateAuthorAndPodAndTags = function (value, field, start, count, sort, callback) {
+searchAndPopulateAuthorAndPodAndTags = function (
+ value: string,
+ field: string,
+ start: number,
+ count: number,
+ sort: string,
+ callback: VideoMethods.SearchAndPopulateAuthorAndPodAndTagsCallback
+) {
const podInclude: any = {
model: Video['sequelize'].models.Pod,
required: false
}
}
-function removeThumbnail (video, callback) {
+function removeThumbnail (video: VideoInstance, callback: (err: Error) => void) {
const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName())
fs.unlink(thumbnailPath, callback)
}
-function removeFile (video, callback) {
+function removeFile (video: VideoInstance, callback: (err: Error) => void) {
const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename())
fs.unlink(filePath, callback)
}
-function removeTorrent (video, callback) {
+function removeTorrent (video: VideoInstance, callback: (err: Error) => void) {
const torrenPath = join(CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName())
fs.unlink(torrenPath, callback)
}
-function removePreview (video, callback) {
+function removePreview (video: VideoInstance, callback: (err: Error) => void) {
// Same name than video thumnail
fs.unlink(CONFIG.STORAGE.PREVIEWS_DIR + video.getPreviewName(), callback)
}
-function createTorrentFromVideo (video, videoPath, callback) {
+function createTorrentFromVideo (video: VideoInstance, videoPath: string, callback: (err: Error) => void) {
const options = {
announceList: [
[ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ]
})
}
-function createPreview (video, videoPath, callback) {
- generateImage(video, videoPath, CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName(), callback)
+function createPreview (video: VideoInstance, videoPath: string, callback: (err: Error) => void) {
+ generateImage(video, videoPath, CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName(), null, callback)
}
-function createThumbnail (video, videoPath, callback) {
+function createThumbnail (video: VideoInstance, videoPath: string, callback: (err: Error) => void) {
generateImage(video, videoPath, CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), THUMBNAILS_SIZE, callback)
}
-function generateImage (video, videoPath, folder, imageName, size, callback?) {
+type GenerateImageCallback = (err: Error, imageName: string) => void
+function generateImage (video: VideoInstance, videoPath: string, folder: string, imageName: string, size: string, callback?: GenerateImageCallback) {
const options: any = {
filename: imageName,
count: 1,
folder
}
- if (!callback) {
- callback = size
- } else {
+ if (size) {
options.size = size
}
.thumbnail(options)
}
-function removeFromBlacklist (video, callback) {
+function removeFromBlacklist (video: VideoInstance, callback: (err: Error) => void) {
// Find the blacklisted video
db.BlacklistedVideo.loadByVideoId(video.id, function (err, video) {
// If an error occured, stop here
video.destroy().asCallback(callback)
} else {
// If haven't found it, simply ignore it and do nothing
- return callback()
+ return callback(null)
}
})
}