X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos.js;h=f29edac743f11ca8b62ef41b2fa5acf8609a666b;hb=4ff0d86208dafbdd07beb6286fd93c795db8a95f;hp=992f03db0c3b864d15b58346314368fec68c2b15;hpb=7920c273a204e2469416a30b752b12ccd3160102;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js index 992f03db0..f29edac74 100644 --- a/server/controllers/api/videos.js +++ b/server/controllers/api/videos.js @@ -1,6 +1,5 @@ 'use strict' -const each = require('async/each') const express = require('express') const fs = require('fs') const multer = require('multer') @@ -95,50 +94,22 @@ function addVideo (req, res, next) { }, function findOrCreateAuthor (t, callback) { - const username = res.locals.oauth.token.user.username - - const query = { - where: { - name: username, - podId: null - }, - defaults: { - name: username, - podId: null // null because it is OUR pod - }, - transaction: t - } + const user = res.locals.oauth.token.User + + const name = user.username + // null because it is OUR pod + const podId = null + const userId = user.id - db.Author.findOrCreate(query).asCallback(function (err, result) { - // [ instance, wasCreated ] - return callback(err, t, result[0]) + db.Author.findOrCreateAuthor(name, podId, userId, t, function (err, authorInstance) { + return callback(err, t, authorInstance) }) }, function findOrCreateTags (t, author, callback) { const tags = videoInfos.tags - const tagInstances = [] - - each(tags, function (tag, callbackEach) { - const query = { - where: { - name: tag - }, - defaults: { - name: tag - }, - transaction: t - } - - db.Tag.findOrCreate(query).asCallback(function (err, res) { - if (err) return callbackEach(err) - - // res = [ tag, isCreated ] - const tag = res[0] - tagInstances.push(tag) - return callbackEach() - }) - }, function (err) { + + db.Tag.findOrCreateTags(tags, t, function (err, tagInstances) { return callback(err, t, author, tagInstances) }) }, @@ -246,27 +217,15 @@ function removeVideo (req, res, next) { const videoId = req.params.id waterfall([ - function getVideo (callback) { - db.Video.load(videoId, callback) - }, - - function removeFromDB (video, callback) { - video.destroy().asCallback(function (err) { - if (err) return callback(err) - - return callback(null, video) + function loadVideo (callback) { + db.Video.load(videoId, function (err, video) { + return callback(err, video) }) }, - function sendInformationToFriends (video, callback) { - const params = { - name: video.name, - remoteId: video.id - } - - friends.removeVideoToFriends(params) - - return callback(null) + function deleteVideo (video, callback) { + // Informations to other pods will be sent by the afterDestroy video hook + video.destroy().asCallback(callback) } ], function andFinally (err) { if (err) {