aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-12-29 18:02:03 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-12-29 18:02:03 +0100
commit4ff0d86208dafbdd07beb6286fd93c795db8a95f (patch)
treef24b12065afd2e9ec0c89f806961803dfcb678a8 /server/controllers/api/videos.js
parentd396a937b642d616beb72dde54c0c2d37c7e8c30 (diff)
downloadPeerTube-4ff0d86208dafbdd07beb6286fd93c795db8a95f.tar.gz
PeerTube-4ff0d86208dafbdd07beb6286fd93c795db8a95f.tar.zst
PeerTube-4ff0d86208dafbdd07beb6286fd93c795db8a95f.zip
Server: little refractoring
Diffstat (limited to 'server/controllers/api/videos.js')
-rw-r--r--server/controllers/api/videos.js46
1 files changed, 7 insertions, 39 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index ddf85d77d..f29edac74 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -1,6 +1,5 @@
1'use strict' 1'use strict'
2 2
3const each = require('async/each')
4const express = require('express') 3const express = require('express')
5const fs = require('fs') 4const fs = require('fs')
6const multer = require('multer') 5const multer = require('multer')
@@ -97,51 +96,20 @@ function addVideo (req, res, next) {
97 function findOrCreateAuthor (t, callback) { 96 function findOrCreateAuthor (t, callback) {
98 const user = res.locals.oauth.token.User 97 const user = res.locals.oauth.token.User
99 98
100 const query = { 99 const name = user.username
101 where: { 100 // null because it is OUR pod
102 name: user.username, 101 const podId = null
103 podId: null, 102 const userId = user.id
104 userId: user.id
105 },
106 defaults: {
107 name: user.username,
108 podId: null, // null because it is OUR pod
109 userId: user.id
110 },
111 transaction: t
112 }
113
114 db.Author.findOrCreate(query).asCallback(function (err, result) {
115 const authorInstance = result[0]
116 103
104 db.Author.findOrCreateAuthor(name, podId, userId, t, function (err, authorInstance) {
117 return callback(err, t, authorInstance) 105 return callback(err, t, authorInstance)
118 }) 106 })
119 }, 107 },
120 108
121 function findOrCreateTags (t, author, callback) { 109 function findOrCreateTags (t, author, callback) {
122 const tags = videoInfos.tags 110 const tags = videoInfos.tags
123 const tagInstances = [] 111
124 112 db.Tag.findOrCreateTags(tags, t, function (err, tagInstances) {
125 each(tags, function (tag, callbackEach) {
126 const query = {
127 where: {
128 name: tag
129 },
130 defaults: {
131 name: tag
132 },
133 transaction: t
134 }
135
136 db.Tag.findOrCreate(query).asCallback(function (err, res) {
137 if (err) return callbackEach(err)
138
139 // res = [ tag, isCreated ]
140 const tag = res[0]
141 tagInstances.push(tag)
142 return callbackEach()
143 })
144 }, function (err) {
145 return callback(err, t, author, tagInstances) 113 return callback(err, t, author, tagInstances)
146 }) 114 })
147 }, 115 },