diff options
author | Chocobozzz <me@florianbigard.com> | 2019-05-28 10:46:32 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-05-28 10:46:32 +0200 |
commit | e590b4a512617bbf63595b684386f68abea7d8b8 (patch) | |
tree | e5a173ffce942787ea8285239ee235a3f3607e65 /server/lib | |
parent | cce1b3dfd386c77a02f2b4f18f60bd916a60a2d3 (diff) | |
download | PeerTube-e590b4a512617bbf63595b684386f68abea7d8b8.tar.gz PeerTube-e590b4a512617bbf63595b684386f68abea7d8b8.tar.zst PeerTube-e590b4a512617bbf63595b684386f68abea7d8b8.zip |
Add ability to specify channel on registration
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/user.ts | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts index 7badb3e72..d9fd89e15 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts | |||
@@ -13,7 +13,8 @@ import { UserNotificationSetting, UserNotificationSettingValue } from '../../sha | |||
13 | import { createWatchLaterPlaylist } from './video-playlist' | 13 | import { createWatchLaterPlaylist } from './video-playlist' |
14 | import { sequelizeTypescript } from '../initializers/database' | 14 | import { sequelizeTypescript } from '../initializers/database' |
15 | 15 | ||
16 | async function createUserAccountAndChannelAndPlaylist (userToCreate: UserModel, validateUser = true) { | 16 | type ChannelNames = { name: string, displayName: string } |
17 | async function createUserAccountAndChannelAndPlaylist (userToCreate: UserModel, channelNames?: ChannelNames, validateUser = true) { | ||
17 | const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { | 18 | const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { |
18 | const userOptions = { | 19 | const userOptions = { |
19 | transaction: t, | 20 | transaction: t, |
@@ -26,18 +27,8 @@ async function createUserAccountAndChannelAndPlaylist (userToCreate: UserModel, | |||
26 | const accountCreated = await createLocalAccountWithoutKeys(userCreated.username, userCreated.id, null, t) | 27 | const accountCreated = await createLocalAccountWithoutKeys(userCreated.username, userCreated.id, null, t) |
27 | userCreated.Account = accountCreated | 28 | userCreated.Account = accountCreated |
28 | 29 | ||
29 | let channelName = userCreated.username + '_channel' | 30 | const channelAttributes = await buildChannelAttributes(userCreated, channelNames) |
30 | 31 | const videoChannel = await createVideoChannel(channelAttributes, accountCreated, t) | |
31 | // Conflict, generate uuid instead | ||
32 | const actor = await ActorModel.loadLocalByName(channelName) | ||
33 | if (actor) channelName = uuidv4() | ||
34 | |||
35 | const videoChannelDisplayName = `Main ${userCreated.username} channel` | ||
36 | const videoChannelInfo = { | ||
37 | name: channelName, | ||
38 | displayName: videoChannelDisplayName | ||
39 | } | ||
40 | const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t) | ||
41 | 32 | ||
42 | const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) | 33 | const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) |
43 | 34 | ||
@@ -116,3 +107,20 @@ function createDefaultUserNotificationSettings (user: UserModel, t: Sequelize.Tr | |||
116 | 107 | ||
117 | return UserNotificationSettingModel.create(values, { transaction: t }) | 108 | return UserNotificationSettingModel.create(values, { transaction: t }) |
118 | } | 109 | } |
110 | |||
111 | async function buildChannelAttributes (user: UserModel, channelNames?: ChannelNames) { | ||
112 | if (channelNames) return channelNames | ||
113 | |||
114 | let channelName = user.username + '_channel' | ||
115 | |||
116 | // Conflict, generate uuid instead | ||
117 | const actor = await ActorModel.loadLocalByName(channelName) | ||
118 | if (actor) channelName = uuidv4() | ||
119 | |||
120 | const videoChannelDisplayName = `Main ${user.username} channel` | ||
121 | |||
122 | return { | ||
123 | name: channelName, | ||
124 | displayName: videoChannelDisplayName | ||
125 | } | ||
126 | } | ||