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:
parent
8113a93a0d
commit
72c7248b6f
56 changed files with 2011 additions and 280 deletions
46
server/lib/user.ts
Normal file
46
server/lib/user.ts
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue