aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/index.ts3
-rw-r--r--server/lib/activitypub/process-create.ts104
-rw-r--r--server/lib/activitypub/process-flag.ts17
-rw-r--r--server/lib/activitypub/process-update.ts29
-rw-r--r--server/lib/activitypub/send-request.ts129
-rw-r--r--server/lib/index.ts1
-rw-r--r--server/lib/jobs/handlers/index.ts17
-rw-r--r--server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts25
-rw-r--r--server/lib/jobs/http-request-job-scheduler/http-request-job-scheduler.ts17
-rw-r--r--server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts25
-rw-r--r--server/lib/jobs/http-request-job-scheduler/index.ts1
-rw-r--r--server/lib/jobs/index.ts3
-rw-r--r--server/lib/jobs/job-scheduler.ts35
-rw-r--r--server/lib/jobs/transcoding-job-scheduler/index.ts1
-rw-r--r--server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts17
-rw-r--r--server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts (renamed from server/lib/jobs/handlers/video-file-optimizer.ts)0
-rw-r--r--server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts (renamed from server/lib/jobs/handlers/video-file-transcoder.ts)0
-rw-r--r--server/lib/user.ts18
-rw-r--r--server/lib/video-channel.ts10
19 files changed, 404 insertions, 48 deletions
diff --git a/server/lib/activitypub/index.ts b/server/lib/activitypub/index.ts
new file mode 100644
index 000000000..740800606
--- /dev/null
+++ b/server/lib/activitypub/index.ts
@@ -0,0 +1,3 @@
1export * from './process-create'
2export * from './process-flag'
3export * from './process-update'
diff --git a/server/lib/activitypub/process-create.ts b/server/lib/activitypub/process-create.ts
new file mode 100644
index 000000000..114ff1848
--- /dev/null
+++ b/server/lib/activitypub/process-create.ts
@@ -0,0 +1,104 @@
1import {
2 ActivityCreate,
3 VideoTorrentObject,
4 VideoChannelObject
5} from '../../../shared'
6import { database as db } from '../../initializers'
7import { logger, retryTransactionWrapper } from '../../helpers'
8
9function processCreateActivity (activity: ActivityCreate) {
10 const activityObject = activity.object
11 const activityType = activityObject.type
12
13 if (activityType === 'Video') {
14 return processCreateVideo(activityObject as VideoTorrentObject)
15 } else if (activityType === 'VideoChannel') {
16 return processCreateVideoChannel(activityObject as VideoChannelObject)
17 }
18
19 logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id })
20 return Promise.resolve()
21}
22
23// ---------------------------------------------------------------------------
24
25export {
26 processCreateActivity
27}
28
29// ---------------------------------------------------------------------------
30
31function processCreateVideo (video: VideoTorrentObject) {
32 const options = {
33 arguments: [ video ],
34 errorMessage: 'Cannot insert the remote video with many retries.'
35 }
36
37 return retryTransactionWrapper(addRemoteVideo, options)
38}
39
40async function addRemoteVideo (videoToCreateData: VideoTorrentObject) {
41 logger.debug('Adding remote video %s.', videoToCreateData.url)
42
43 await db.sequelize.transaction(async t => {
44 const sequelizeOptions = {
45 transaction: t
46 }
47
48 const videoFromDatabase = await db.Video.loadByUUID(videoToCreateData.uuid)
49 if (videoFromDatabase) throw new Error('UUID already exists.')
50
51 const videoChannel = await db.VideoChannel.loadByHostAndUUID(fromPod.host, videoToCreateData.channelUUID, t)
52 if (!videoChannel) throw new Error('Video channel ' + videoToCreateData.channelUUID + ' not found.')
53
54 const tags = videoToCreateData.tags
55 const tagInstances = await db.Tag.findOrCreateTags(tags, t)
56
57 const videoData = {
58 name: videoToCreateData.name,
59 uuid: videoToCreateData.uuid,
60 category: videoToCreateData.category,
61 licence: videoToCreateData.licence,
62 language: videoToCreateData.language,
63 nsfw: videoToCreateData.nsfw,
64 description: videoToCreateData.truncatedDescription,
65 channelId: videoChannel.id,
66 duration: videoToCreateData.duration,
67 createdAt: videoToCreateData.createdAt,
68 // FIXME: updatedAt does not seems to be considered by Sequelize
69 updatedAt: videoToCreateData.updatedAt,
70 views: videoToCreateData.views,
71 likes: videoToCreateData.likes,
72 dislikes: videoToCreateData.dislikes,
73 remote: true,
74 privacy: videoToCreateData.privacy
75 }
76
77 const video = db.Video.build(videoData)
78 await db.Video.generateThumbnailFromData(video, videoToCreateData.thumbnailData)
79 const videoCreated = await video.save(sequelizeOptions)
80
81 const tasks = []
82 for (const fileData of videoToCreateData.files) {
83 const videoFileInstance = db.VideoFile.build({
84 extname: fileData.extname,
85 infoHash: fileData.infoHash,
86 resolution: fileData.resolution,
87 size: fileData.size,
88 videoId: videoCreated.id
89 })
90
91 tasks.push(videoFileInstance.save(sequelizeOptions))
92 }
93
94 await Promise.all(tasks)
95
96 await videoCreated.setTags(tagInstances, sequelizeOptions)
97 })
98
99 logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid)
100}
101
102function processCreateVideoChannel (videoChannel: VideoChannelObject) {
103
104}
diff --git a/server/lib/activitypub/process-flag.ts b/server/lib/activitypub/process-flag.ts
new file mode 100644
index 000000000..6fa862ee9
--- /dev/null
+++ b/server/lib/activitypub/process-flag.ts
@@ -0,0 +1,17 @@
1import {
2 ActivityCreate,
3 VideoTorrentObject,
4 VideoChannelObject
5} from '../../../shared'
6
7function processFlagActivity (activity: ActivityCreate) {
8 // empty
9}
10
11// ---------------------------------------------------------------------------
12
13export {
14 processFlagActivity
15}
16
17// ---------------------------------------------------------------------------
diff --git a/server/lib/activitypub/process-update.ts b/server/lib/activitypub/process-update.ts
new file mode 100644
index 000000000..187c7be7c
--- /dev/null
+++ b/server/lib/activitypub/process-update.ts
@@ -0,0 +1,29 @@
1import {
2 ActivityCreate,
3 VideoTorrentObject,
4 VideoChannelObject
5} from '../../../shared'
6
7function processUpdateActivity (activity: ActivityCreate) {
8 if (activity.object.type === 'Video') {
9 return processUpdateVideo(activity.object)
10 } else if (activity.object.type === 'VideoChannel') {
11 return processUpdateVideoChannel(activity.object)
12 }
13}
14
15// ---------------------------------------------------------------------------
16
17export {
18 processUpdateActivity
19}
20
21// ---------------------------------------------------------------------------
22
23function processUpdateVideo (video: VideoTorrentObject) {
24
25}
26
27function processUpdateVideoChannel (videoChannel: VideoChannelObject) {
28
29}
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts
new file mode 100644
index 000000000..6a31c226d
--- /dev/null
+++ b/server/lib/activitypub/send-request.ts
@@ -0,0 +1,129 @@
1import * as Sequelize from 'sequelize'
2
3import {
4 AccountInstance,
5 VideoInstance,
6 VideoChannelInstance
7} from '../../models'
8import { httpRequestJobScheduler } from '../jobs'
9import { signObject, activityPubContextify } from '../../helpers'
10import { Activity } from '../../../shared'
11
12function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
13 const videoChannelObject = videoChannel.toActivityPubObject()
14 const data = createActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
15
16 return broadcastToFollowers(data, t)
17}
18
19function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
20 const videoChannelObject = videoChannel.toActivityPubObject()
21 const data = updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
22
23 return broadcastToFollowers(data, t)
24}
25
26function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
27 const videoChannelObject = videoChannel.toActivityPubObject()
28 const data = deleteActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
29
30 return broadcastToFollowers(data, t)
31}
32
33function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) {
34 const videoObject = video.toActivityPubObject()
35 const data = addActivityData(video.url, video.VideoChannel.Account, video.VideoChannel.url, videoObject)
36
37 return broadcastToFollowers(data, t)
38}
39
40function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction) {
41 const videoObject = video.toActivityPubObject()
42 const data = updateActivityData(video.url, video.VideoChannel.Account, videoObject)
43
44 return broadcastToFollowers(data, t)
45}
46
47function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) {
48 const videoObject = video.toActivityPubObject()
49 const data = deleteActivityData(video.url, video.VideoChannel.Account, videoObject)
50
51 return broadcastToFollowers(data, t)
52}
53
54// ---------------------------------------------------------------------------
55
56export {
57
58}
59
60// ---------------------------------------------------------------------------
61
62function broadcastToFollowers (data: any, t: Sequelize.Transaction) {
63 return httpRequestJobScheduler.createJob(t, 'http-request', 'httpRequestBroadcastHandler', data)
64}
65
66function buildSignedActivity (byAccount: AccountInstance, data: Object) {
67 const activity = activityPubContextify(data)
68
69 return signObject(byAccount, activity) as Promise<Activity>
70}
71
72async function getPublicActivityTo (account: AccountInstance) {
73 const inboxUrls = await account.getFollowerSharedInboxUrls()
74
75 return inboxUrls.concat('https://www.w3.org/ns/activitystreams#Public')
76}
77
78async function createActivityData (url: string, byAccount: AccountInstance, object: any) {
79 const to = await getPublicActivityTo(byAccount)
80 const base = {
81 type: 'Create',
82 id: url,
83 actor: byAccount.url,
84 to,
85 object
86 }
87
88 return buildSignedActivity(byAccount, base)
89}
90
91async function updateActivityData (url: string, byAccount: AccountInstance, object: any) {
92 const to = await getPublicActivityTo(byAccount)
93 const base = {
94 type: 'Update',
95 id: url,
96 actor: byAccount.url,
97 to,
98 object
99 }
100
101 return buildSignedActivity(byAccount, base)
102}
103
104async function deleteActivityData (url: string, byAccount: AccountInstance, object: any) {
105 const to = await getPublicActivityTo(byAccount)
106 const base = {
107 type: 'Update',
108 id: url,
109 actor: byAccount.url,
110 to,
111 object
112 }
113
114 return buildSignedActivity(byAccount, base)
115}
116
117async function addActivityData (url: string, byAccount: AccountInstance, target: string, object: any) {
118 const to = await getPublicActivityTo(byAccount)
119 const base = {
120 type: 'Add',
121 id: url,
122 actor: byAccount.url,
123 to,
124 object,
125 target
126 }
127
128 return buildSignedActivity(byAccount, base)
129}
diff --git a/server/lib/index.ts b/server/lib/index.ts
index d1534b085..bfb415ad2 100644
--- a/server/lib/index.ts
+++ b/server/lib/index.ts
@@ -1,3 +1,4 @@
1export * from './activitypub'
1export * from './cache' 2export * from './cache'
2export * from './jobs' 3export * from './jobs'
3export * from './request' 4export * from './request'
diff --git a/server/lib/jobs/handlers/index.ts b/server/lib/jobs/handlers/index.ts
deleted file mode 100644
index cef1f89a9..000000000
--- a/server/lib/jobs/handlers/index.ts
+++ /dev/null
@@ -1,17 +0,0 @@
1import * as videoFileOptimizer from './video-file-optimizer'
2import * as videoFileTranscoder from './video-file-transcoder'
3
4export interface JobHandler<T> {
5 process (data: object, jobId: number): T
6 onError (err: Error, jobId: number)
7 onSuccess (jobId: number, jobResult: T)
8}
9
10const jobHandlers: { [ handlerName: string ]: JobHandler<any> } = {
11 videoFileOptimizer,
12 videoFileTranscoder
13}
14
15export {
16 jobHandlers
17}
diff --git a/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts b/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts
new file mode 100644
index 000000000..6b6946d02
--- /dev/null
+++ b/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts
@@ -0,0 +1,25 @@
1import * as Bluebird from 'bluebird'
2
3import { database as db } from '../../../initializers/database'
4import { logger } from '../../../helpers'
5
6async function process (data: { videoUUID: string }, jobId: number) {
7
8}
9
10function onError (err: Error, jobId: number) {
11 logger.error('Error when optimized video file in job %d.', jobId, err)
12 return Promise.resolve()
13}
14
15async function onSuccess (jobId: number) {
16
17}
18
19// ---------------------------------------------------------------------------
20
21export {
22 process,
23 onError,
24 onSuccess
25}
diff --git a/server/lib/jobs/http-request-job-scheduler/http-request-job-scheduler.ts b/server/lib/jobs/http-request-job-scheduler/http-request-job-scheduler.ts
new file mode 100644
index 000000000..42cb9139c
--- /dev/null
+++ b/server/lib/jobs/http-request-job-scheduler/http-request-job-scheduler.ts
@@ -0,0 +1,17 @@
1import { JobScheduler, JobHandler } from '../job-scheduler'
2
3import * as httpRequestBroadcastHandler from './http-request-broadcast-handler'
4import * as httpRequestUnicastHandler from './http-request-unicast-handler'
5import { JobCategory } from '../../../../shared'
6
7const jobHandlers: { [ handlerName: string ]: JobHandler<any> } = {
8 httpRequestBroadcastHandler,
9 httpRequestUnicastHandler
10}
11const jobCategory: JobCategory = 'http-request'
12
13const httpRequestJobScheduler = new JobScheduler(jobCategory, jobHandlers)
14
15export {
16 httpRequestJobScheduler
17}
diff --git a/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts b/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts
new file mode 100644
index 000000000..6b6946d02
--- /dev/null
+++ b/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts
@@ -0,0 +1,25 @@
1import * as Bluebird from 'bluebird'
2
3import { database as db } from '../../../initializers/database'
4import { logger } from '../../../helpers'
5
6async function process (data: { videoUUID: string }, jobId: number) {
7
8}
9
10function onError (err: Error, jobId: number) {
11 logger.error('Error when optimized video file in job %d.', jobId, err)
12 return Promise.resolve()
13}
14
15async function onSuccess (jobId: number) {
16
17}
18
19// ---------------------------------------------------------------------------
20
21export {
22 process,
23 onError,
24 onSuccess
25}
diff --git a/server/lib/jobs/http-request-job-scheduler/index.ts b/server/lib/jobs/http-request-job-scheduler/index.ts
new file mode 100644
index 000000000..4d2573296
--- /dev/null
+++ b/server/lib/jobs/http-request-job-scheduler/index.ts
@@ -0,0 +1 @@
export * from './http-request-job-scheduler'
diff --git a/server/lib/jobs/index.ts b/server/lib/jobs/index.ts
index b18a3d845..a92743707 100644
--- a/server/lib/jobs/index.ts
+++ b/server/lib/jobs/index.ts
@@ -1 +1,2 @@
1export * from './job-scheduler' 1export * from './http-request-job-scheduler'
2export * from './transcoding-job-scheduler'
diff --git a/server/lib/jobs/job-scheduler.ts b/server/lib/jobs/job-scheduler.ts
index 61d483268..89a4bca88 100644
--- a/server/lib/jobs/job-scheduler.ts
+++ b/server/lib/jobs/job-scheduler.ts
@@ -1,39 +1,41 @@
1import { AsyncQueue, forever, queue } from 'async' 1import { AsyncQueue, forever, queue } from 'async'
2import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
3 3
4import { database as db } from '../../initializers/database'
5import { 4import {
5 database as db,
6 JOBS_FETCHING_INTERVAL, 6 JOBS_FETCHING_INTERVAL,
7 JOBS_FETCH_LIMIT_PER_CYCLE, 7 JOBS_FETCH_LIMIT_PER_CYCLE,
8 JOB_STATES 8 JOB_STATES
9} from '../../initializers' 9} from '../../initializers'
10import { logger } from '../../helpers' 10import { logger } from '../../helpers'
11import { JobInstance } from '../../models' 11import { JobInstance } from '../../models'
12import { JobHandler, jobHandlers } from './handlers' 12import { JobCategory } from '../../../shared'
13 13
14export interface JobHandler<T> {
15 process (data: object, jobId: number): T
16 onError (err: Error, jobId: number)
17 onSuccess (jobId: number, jobResult: T)
18}
14type JobQueueCallback = (err: Error) => void 19type JobQueueCallback = (err: Error) => void
15 20
16class JobScheduler { 21class JobScheduler<T> {
17
18 private static instance: JobScheduler
19 22
20 private constructor () { } 23 constructor (
21 24 private jobCategory: JobCategory,
22 static get Instance () { 25 private jobHandlers: { [ id: string ]: JobHandler<T> }
23 return this.instance || (this.instance = new this()) 26 ) {}
24 }
25 27
26 async activate () { 28 async activate () {
27 const limit = JOBS_FETCH_LIMIT_PER_CYCLE 29 const limit = JOBS_FETCH_LIMIT_PER_CYCLE[this.jobCategory]
28 30
29 logger.info('Jobs scheduler activated.') 31 logger.info('Jobs scheduler %s activated.', this.jobCategory)
30 32
31 const jobsQueue = queue<JobInstance, JobQueueCallback>(this.processJob.bind(this)) 33 const jobsQueue = queue<JobInstance, JobQueueCallback>(this.processJob.bind(this))
32 34
33 // Finish processing jobs from a previous start 35 // Finish processing jobs from a previous start
34 const state = JOB_STATES.PROCESSING 36 const state = JOB_STATES.PROCESSING
35 try { 37 try {
36 const jobs = await db.Job.listWithLimit(limit, state) 38 const jobs = await db.Job.listWithLimitByCategory(limit, state, this.jobCategory)
37 39
38 this.enqueueJobs(jobsQueue, jobs) 40 this.enqueueJobs(jobsQueue, jobs)
39 } catch (err) { 41 } catch (err) {
@@ -49,7 +51,7 @@ class JobScheduler {
49 51
50 const state = JOB_STATES.PENDING 52 const state = JOB_STATES.PENDING
51 try { 53 try {
52 const jobs = await db.Job.listWithLimit(limit, state) 54 const jobs = await db.Job.listWithLimitByCategory(limit, state, this.jobCategory)
53 55
54 this.enqueueJobs(jobsQueue, jobs) 56 this.enqueueJobs(jobsQueue, jobs)
55 } catch (err) { 57 } catch (err) {
@@ -64,9 +66,10 @@ class JobScheduler {
64 ) 66 )
65 } 67 }
66 68
67 createJob (transaction: Sequelize.Transaction, handlerName: string, handlerInputData: object) { 69 createJob (transaction: Sequelize.Transaction, category: JobCategory, handlerName: string, handlerInputData: object) {
68 const createQuery = { 70 const createQuery = {
69 state: JOB_STATES.PENDING, 71 state: JOB_STATES.PENDING,
72 category,
70 handlerName, 73 handlerName,
71 handlerInputData 74 handlerInputData
72 } 75 }
@@ -80,7 +83,7 @@ class JobScheduler {
80 } 83 }
81 84
82 private async processJob (job: JobInstance, callback: (err: Error) => void) { 85 private async processJob (job: JobInstance, callback: (err: Error) => void) {
83 const jobHandler = jobHandlers[job.handlerName] 86 const jobHandler = this.jobHandlers[job.handlerName]
84 if (jobHandler === undefined) { 87 if (jobHandler === undefined) {
85 logger.error('Unknown job handler for job %s.', job.handlerName) 88 logger.error('Unknown job handler for job %s.', job.handlerName)
86 return callback(null) 89 return callback(null)
diff --git a/server/lib/jobs/transcoding-job-scheduler/index.ts b/server/lib/jobs/transcoding-job-scheduler/index.ts
new file mode 100644
index 000000000..73152a1be
--- /dev/null
+++ b/server/lib/jobs/transcoding-job-scheduler/index.ts
@@ -0,0 +1 @@
export * from './transcoding-job-scheduler'
diff --git a/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts b/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts
new file mode 100644
index 000000000..d7c614fb8
--- /dev/null
+++ b/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts
@@ -0,0 +1,17 @@
1import { JobScheduler, JobHandler } from '../job-scheduler'
2
3import * as videoFileOptimizer from './video-file-optimizer-handler'
4import * as videoFileTranscoder from './video-file-transcoder-handler'
5import { JobCategory } from '../../../../shared'
6
7const jobHandlers: { [ handlerName: string ]: JobHandler<any> } = {
8 videoFileOptimizer,
9 videoFileTranscoder
10}
11const jobCategory: JobCategory = 'transcoding'
12
13const transcodingJobScheduler = new JobScheduler(jobCategory, jobHandlers)
14
15export {
16 transcodingJobScheduler
17}
diff --git a/server/lib/jobs/handlers/video-file-optimizer.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
index ccded4721..ccded4721 100644
--- a/server/lib/jobs/handlers/video-file-optimizer.ts
+++ b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
diff --git a/server/lib/jobs/handlers/video-file-transcoder.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts
index 853645510..853645510 100644
--- a/server/lib/jobs/handlers/video-file-transcoder.ts
+++ b/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts
diff --git a/server/lib/user.ts b/server/lib/user.ts
index a92f4777b..57c653e55 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -1,9 +1,9 @@
1import { database as db } from '../initializers' 1import { database as db } from '../initializers'
2import { UserInstance } from '../models' 2import { UserInstance } from '../models'
3import { addVideoAuthorToFriends } from './friends' 3import { addVideoAccountToFriends } from './friends'
4import { createVideoChannel } from './video-channel' 4import { createVideoChannel } from './video-channel'
5 5
6async function createUserAuthorAndChannel (user: UserInstance, validateUser = true) { 6async function createUserAccountAndChannel (user: UserInstance, validateUser = true) {
7 const res = await db.sequelize.transaction(async t => { 7 const res = await db.sequelize.transaction(async t => {
8 const userOptions = { 8 const userOptions = {
9 transaction: t, 9 transaction: t,
@@ -11,25 +11,25 @@ async function createUserAuthorAndChannel (user: UserInstance, validateUser = tr
11 } 11 }
12 12
13 const userCreated = await user.save(userOptions) 13 const userCreated = await user.save(userOptions)
14 const authorInstance = db.Author.build({ 14 const accountInstance = db.Account.build({
15 name: userCreated.username, 15 name: userCreated.username,
16 podId: null, // It is our pod 16 podId: null, // It is our pod
17 userId: userCreated.id 17 userId: userCreated.id
18 }) 18 })
19 19
20 const authorCreated = await authorInstance.save({ transaction: t }) 20 const accountCreated = await accountInstance.save({ transaction: t })
21 21
22 const remoteVideoAuthor = authorCreated.toAddRemoteJSON() 22 const remoteVideoAccount = accountCreated.toAddRemoteJSON()
23 23
24 // Now we'll add the video channel's meta data to our friends 24 // Now we'll add the video channel's meta data to our friends
25 const author = await addVideoAuthorToFriends(remoteVideoAuthor, t) 25 const account = await addVideoAccountToFriends(remoteVideoAccount, t)
26 26
27 const videoChannelInfo = { 27 const videoChannelInfo = {
28 name: `Default ${userCreated.username} channel` 28 name: `Default ${userCreated.username} channel`
29 } 29 }
30 const videoChannel = await createVideoChannel(videoChannelInfo, authorCreated, t) 30 const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t)
31 31
32 return { author, videoChannel } 32 return { account, videoChannel }
33 }) 33 })
34 34
35 return res 35 return res
@@ -38,5 +38,5 @@ async function createUserAuthorAndChannel (user: UserInstance, validateUser = tr
38// --------------------------------------------------------------------------- 38// ---------------------------------------------------------------------------
39 39
40export { 40export {
41 createUserAuthorAndChannel 41 createUserAccountAndChannel
42} 42}
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts
index 678ffe643..a6dd4d061 100644
--- a/server/lib/video-channel.ts
+++ b/server/lib/video-channel.ts
@@ -3,15 +3,15 @@ import * as Sequelize from 'sequelize'
3import { addVideoChannelToFriends } from './friends' 3import { addVideoChannelToFriends } from './friends'
4import { database as db } from '../initializers' 4import { database as db } from '../initializers'
5import { logger } from '../helpers' 5import { logger } from '../helpers'
6import { AuthorInstance } from '../models' 6import { AccountInstance } from '../models'
7import { VideoChannelCreate } from '../../shared/models' 7import { VideoChannelCreate } from '../../shared/models'
8 8
9async function createVideoChannel (videoChannelInfo: VideoChannelCreate, author: AuthorInstance, t: Sequelize.Transaction) { 9async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) {
10 const videoChannelData = { 10 const videoChannelData = {
11 name: videoChannelInfo.name, 11 name: videoChannelInfo.name,
12 description: videoChannelInfo.description, 12 description: videoChannelInfo.description,
13 remote: false, 13 remote: false,
14 authorId: author.id 14 authorId: account.id
15 } 15 }
16 16
17 const videoChannel = db.VideoChannel.build(videoChannelData) 17 const videoChannel = db.VideoChannel.build(videoChannelData)
@@ -19,8 +19,8 @@ async function createVideoChannel (videoChannelInfo: VideoChannelCreate, author:
19 19
20 const videoChannelCreated = await videoChannel.save(options) 20 const videoChannelCreated = await videoChannel.save(options)
21 21
22 // Do not forget to add Author information to the created video channel 22 // Do not forget to add Account information to the created video channel
23 videoChannelCreated.Author = author 23 videoChannelCreated.Account = account
24 24
25 const remoteVideoChannel = videoChannelCreated.toAddRemoteJSON() 25 const remoteVideoChannel = videoChannelCreated.toAddRemoteJSON()
26 26