1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Add video channels

This commit is contained in:
Chocobozzz 2017-10-24 19:41:09 +02:00
parent 8113a93a0d
commit 72c7248b6f
No known key found for this signature in database
GPG key ID: 583A612D890159BE
56 changed files with 2011 additions and 280 deletions

46
server/lib/user.ts Normal file
View file

@ -0,0 +1,46 @@
import { database as db } from '../initializers'
import { UserInstance } from '../models'
import { addVideoAuthorToFriends } from './friends'
import { createVideoChannel } from './video-channel'
function createUserAuthorAndChannel (user: UserInstance, validateUser = true) {
return db.sequelize.transaction(t => {
const userOptions = {
transaction: t,
validate: validateUser
}
return user.save(userOptions)
.then(user => {
const author = db.Author.build({
name: user.username,
podId: null, // It is our pod
userId: user.id
})
return author.save({ transaction: t })
.then(author => ({ author, user }))
})
.then(({ author, user }) => {
const remoteVideoAuthor = author.toAddRemoteJSON()
// Now we'll add the video channel's meta data to our friends
return addVideoAuthorToFriends(remoteVideoAuthor, t)
.then(() => ({ author, user }))
})
.then(({ author, user }) => {
const videoChannelInfo = {
name: `Default ${user.username} channel`
}
return createVideoChannel(videoChannelInfo, author, t)
.then(videoChannel => ({ author, user, videoChannel }))
})
})
}
// ---------------------------------------------------------------------------
export {
createUserAuthorAndChannel
}