diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-12-29 10:33:36 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-12-29 10:56:07 +0100 |
commit | 4712081f2a5f48749cf125d729e78b926ab28d6d (patch) | |
tree | b0f2f380f6fe5403fb89fb5cfdbe9deafea1c889 /server/controllers/api/videos.js | |
parent | 319d072e8eb7266cd8d33e0bb2fb5ebe76c487d1 (diff) | |
download | PeerTube-4712081f2a5f48749cf125d729e78b926ab28d6d.tar.gz PeerTube-4712081f2a5f48749cf125d729e78b926ab28d6d.tar.zst PeerTube-4712081f2a5f48749cf125d729e78b926ab28d6d.zip |
Server: add association between author and user
Diffstat (limited to 'server/controllers/api/videos.js')
-rw-r--r-- | server/controllers/api/videos.js | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js index 992f03db0..170224634 100644 --- a/server/controllers/api/videos.js +++ b/server/controllers/api/videos.js | |||
@@ -95,23 +95,26 @@ function addVideo (req, res, next) { | |||
95 | }, | 95 | }, |
96 | 96 | ||
97 | function findOrCreateAuthor (t, callback) { | 97 | function findOrCreateAuthor (t, callback) { |
98 | const username = res.locals.oauth.token.user.username | 98 | const user = res.locals.oauth.token.User |
99 | 99 | ||
100 | const query = { | 100 | const query = { |
101 | where: { | 101 | where: { |
102 | name: username, | 102 | name: user.username, |
103 | podId: null | 103 | podId: null, |
104 | userId: user.id | ||
104 | }, | 105 | }, |
105 | defaults: { | 106 | defaults: { |
106 | name: username, | 107 | name: user.username, |
107 | podId: null // null because it is OUR pod | 108 | podId: null, // null because it is OUR pod |
109 | userId: user.id | ||
108 | }, | 110 | }, |
109 | transaction: t | 111 | transaction: t |
110 | } | 112 | } |
111 | 113 | ||
112 | db.Author.findOrCreate(query).asCallback(function (err, result) { | 114 | db.Author.findOrCreate(query).asCallback(function (err, result) { |
113 | // [ instance, wasCreated ] | 115 | const authorInstance = result[0] |
114 | return callback(err, t, result[0]) | 116 | |
117 | return callback(err, t, authorInstance) | ||
115 | }) | 118 | }) |
116 | }, | 119 | }, |
117 | 120 | ||