aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-17 15:45:42 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commit8a19bee1a1ee39f973bb37429e4f73c3f2873cdb (patch)
tree33c93ef19451d7e46d4be74ce0681359d2dcc70e /server/lib
parent965c4b22d0e4d2f853501e844e6ebbb861bd389d (diff)
downloadPeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.tar.gz
PeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.tar.zst
PeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.zip
Add ability to set a name to a channel
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/url.ts4
-rw-r--r--server/lib/user.ts11
-rw-r--r--server/lib/video-channel.ts5
3 files changed, 14 insertions, 6 deletions
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts
index ba3bf688d..262463310 100644
--- a/server/lib/activitypub/url.ts
+++ b/server/lib/activitypub/url.ts
@@ -13,8 +13,8 @@ function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCo
13 return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id 13 return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
14} 14}
15 15
16function getVideoChannelActivityPubUrl (videoChannelUUID: string) { 16function getVideoChannelActivityPubUrl (videoChannelName: string) {
17 return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelUUID 17 return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelName
18} 18}
19 19
20function getAccountActivityPubUrl (accountName: string) { 20function getAccountActivityPubUrl (accountName: string) {
diff --git a/server/lib/user.ts b/server/lib/user.ts
index e7a45f5aa..db29469eb 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -1,4 +1,5 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import * as uuidv4 from 'uuid/v4'
2import { ActivityPubActorType } from '../../shared/models/activitypub' 3import { ActivityPubActorType } from '../../shared/models/activitypub'
3import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../initializers' 4import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../initializers'
4import { AccountModel } from '../models/account/account' 5import { AccountModel } from '../models/account/account'
@@ -7,6 +8,7 @@ import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from
7import { createVideoChannel } from './video-channel' 8import { createVideoChannel } from './video-channel'
8import { VideoChannelModel } from '../models/video/video-channel' 9import { VideoChannelModel } from '../models/video/video-channel'
9import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' 10import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
11import { ActorModel } from '../models/activitypub/actor'
10 12
11async function createUserAccountAndChannel (userToCreate: UserModel, validateUser = true) { 13async function createUserAccountAndChannel (userToCreate: UserModel, validateUser = true) {
12 const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { 14 const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => {
@@ -19,8 +21,15 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse
19 const accountCreated = await createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t) 21 const accountCreated = await createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t)
20 userCreated.Account = accountCreated 22 userCreated.Account = accountCreated
21 23
22 const videoChannelDisplayName = `Default ${userCreated.username} channel` 24 let channelName = userCreated.username + '_channel'
25
26 // Conflict, generate uuid instead
27 const actor = await ActorModel.loadLocalByName(channelName)
28 if (actor) channelName = uuidv4()
29
30 const videoChannelDisplayName = `Main ${userCreated.username} channel`
23 const videoChannelInfo = { 31 const videoChannelInfo = {
32 name: channelName,
24 displayName: videoChannelDisplayName 33 displayName: videoChannelDisplayName
25 } 34 }
26 const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t) 35 const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t)
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts
index 600316cda..0fe95ca09 100644
--- a/server/lib/video-channel.ts
+++ b/server/lib/video-channel.ts
@@ -7,9 +7,8 @@ import { buildActorInstance, getVideoChannelActivityPubUrl } from './activitypub
7 7
8async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) { 8async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) {
9 const uuid = uuidv4() 9 const uuid = uuidv4()
10 const url = getVideoChannelActivityPubUrl(uuid) 10 const url = getVideoChannelActivityPubUrl(videoChannelInfo.name)
11 // We use the name as uuid 11 const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid)
12 const actorInstance = buildActorInstance('Group', url, uuid, uuid)
13 12
14 const actorInstanceCreated = await actorInstance.save({ transaction: t }) 13 const actorInstanceCreated = await actorInstance.save({ transaction: t })
15 14