diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-17 15:45:42 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | 8a19bee1a1ee39f973bb37429e4f73c3f2873cdb (patch) | |
tree | 33c93ef19451d7e46d4be74ce0681359d2dcc70e /server/lib | |
parent | 965c4b22d0e4d2f853501e844e6ebbb861bd389d (diff) | |
download | PeerTube-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.ts | 4 | ||||
-rw-r--r-- | server/lib/user.ts | 11 | ||||
-rw-r--r-- | server/lib/video-channel.ts | 5 |
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 | ||
16 | function getVideoChannelActivityPubUrl (videoChannelUUID: string) { | 16 | function getVideoChannelActivityPubUrl (videoChannelName: string) { |
17 | return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelUUID | 17 | return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelName |
18 | } | 18 | } |
19 | 19 | ||
20 | function getAccountActivityPubUrl (accountName: string) { | 20 | function 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import * as uuidv4 from 'uuid/v4' | ||
2 | import { ActivityPubActorType } from '../../shared/models/activitypub' | 3 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
3 | import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../initializers' | 4 | import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../initializers' |
4 | import { AccountModel } from '../models/account/account' | 5 | import { AccountModel } from '../models/account/account' |
@@ -7,6 +8,7 @@ import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from | |||
7 | import { createVideoChannel } from './video-channel' | 8 | import { createVideoChannel } from './video-channel' |
8 | import { VideoChannelModel } from '../models/video/video-channel' | 9 | import { VideoChannelModel } from '../models/video/video-channel' |
9 | import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' | 10 | import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' |
11 | import { ActorModel } from '../models/activitypub/actor' | ||
10 | 12 | ||
11 | async function createUserAccountAndChannel (userToCreate: UserModel, validateUser = true) { | 13 | async 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 | ||
8 | async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) { | 8 | async 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 | ||