diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-24 19:41:09 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 09:11:38 +0200 |
commit | 72c7248b6fdcdb2175e726ff51b42e7555f2bd84 (patch) | |
tree | 1bfdee99dbe2392cc997edba8e314e2a8a401c72 /server/lib/user.ts | |
parent | 8113a93a0d9f31aa9e23702bbc31b8a76275ae22 (diff) | |
download | PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.gz PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.zst PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.zip |
Add video channels
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r-- | server/lib/user.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts new file mode 100644 index 000000000..8609e72d8 --- /dev/null +++ b/server/lib/user.ts | |||
@@ -0,0 +1,46 @@ | |||
1 | import { database as db } from '../initializers' | ||
2 | import { UserInstance } from '../models' | ||
3 | import { addVideoAuthorToFriends } from './friends' | ||
4 | import { createVideoChannel } from './video-channel' | ||
5 | |||
6 | function createUserAuthorAndChannel (user: UserInstance, validateUser = true) { | ||
7 | return db.sequelize.transaction(t => { | ||
8 | const userOptions = { | ||
9 | transaction: t, | ||
10 | validate: validateUser | ||
11 | } | ||
12 | |||
13 | return user.save(userOptions) | ||
14 | .then(user => { | ||
15 | const author = db.Author.build({ | ||
16 | name: user.username, | ||
17 | podId: null, // It is our pod | ||
18 | userId: user.id | ||
19 | }) | ||
20 | |||
21 | return author.save({ transaction: t }) | ||
22 | .then(author => ({ author, user })) | ||
23 | }) | ||
24 | .then(({ author, user }) => { | ||
25 | const remoteVideoAuthor = author.toAddRemoteJSON() | ||
26 | |||
27 | // Now we'll add the video channel's meta data to our friends | ||
28 | return addVideoAuthorToFriends(remoteVideoAuthor, t) | ||
29 | .then(() => ({ author, user })) | ||
30 | }) | ||
31 | .then(({ author, user }) => { | ||
32 | const videoChannelInfo = { | ||
33 | name: `Default ${user.username} channel` | ||
34 | } | ||
35 | |||
36 | return createVideoChannel(videoChannelInfo, author, t) | ||
37 | .then(videoChannel => ({ author, user, videoChannel })) | ||
38 | }) | ||
39 | }) | ||
40 | } | ||
41 | |||
42 | // --------------------------------------------------------------------------- | ||
43 | |||
44 | export { | ||
45 | createUserAuthorAndChannel | ||
46 | } | ||