]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/migrations/0100-activitypub.ts
Check live duration and size
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0100-activitypub.ts
index fb42e1d57fd3c0d9d93e04bf9f93bb32fded3653..05fd37406874a4c2eb0d85969631ee53d2810e95 100644 (file)
@@ -1,16 +1,15 @@
-import { values } from 'lodash'
 import * as Sequelize from 'sequelize'
 import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto'
-import { shareVideoByServer } from '../../lib/activitypub/share'
+import { shareVideoByServerAndChannel } from '../../lib/activitypub/share'
 import { getVideoActivityPubUrl, getVideoChannelActivityPubUrl } from '../../lib/activitypub/url'
 import { createLocalAccountWithoutKeys } from '../../lib/user'
 import { ApplicationModel } from '../../models/application/application'
-import { JOB_CATEGORIES, SERVER_ACCOUNT_NAME } from '../constants'
+import { SERVER_ACTOR_NAME } from '../constants'
 
 async function up (utils: {
-  transaction: Sequelize.Transaction,
-  queryInterface: Sequelize.QueryInterface,
-  sequelize: Sequelize.Sequelize,
+  transaction: Sequelize.Transaction
+  queryInterface: Sequelize.QueryInterface
+  sequelize: Sequelize.Sequelize
   db: any
 }): Promise<void> {
   const q = utils.queryInterface
@@ -22,7 +21,7 @@ async function up (utils: {
     const options = {
       type: Sequelize.QueryTypes.SELECT
     }
-    const res = await utils.sequelize.query(query, options)
+    const res = await utils.sequelize.query(query, options) as any
 
     if (!res[0] || res[0].total !== 0) {
       throw new Error('You need to quit friends.')
@@ -66,11 +65,16 @@ async function up (utils: {
   // Create application account
   {
     const applicationInstance = await ApplicationModel.findOne()
-    const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACCOUNT_NAME, null, applicationInstance.id, undefined)
+    const accountCreated = await createLocalAccountWithoutKeys({
+      name: SERVER_ACTOR_NAME,
+      userId: null,
+      applicationId: applicationInstance.id,
+      t: undefined
+    })
 
     const { publicKey, privateKey } = await createPrivateAndPublicKeys()
-    accountCreated.set('publicKey', publicKey)
-    accountCreated.set('privateKey', privateKey)
+    accountCreated.Actor.publicKey = publicKey
+    accountCreated.Actor.privateKey = privateKey
 
     await accountCreated.save()
   }
@@ -84,11 +88,11 @@ async function up (utils: {
   // Recreate accounts for each user
   const users = await db.User.findAll()
   for (const user of users) {
-    const account = await createLocalAccountWithoutKeys(user.username, user.id, null, undefined)
+    const account = await createLocalAccountWithoutKeys({ name: user.username, userId: user.id, applicationId: null, t: undefined })
 
     const { publicKey, privateKey } = await createPrivateAndPublicKeys()
-    account.set('publicKey', publicKey)
-    account.set('privateKey', privateKey)
+    account.Actor.publicKey = publicKey
+    account.Actor.privateKey = privateKey
     await account.save()
   }
 
@@ -161,7 +165,7 @@ async function up (utils: {
 
   {
     const data = {
-      type: Sequelize.ENUM(values(JOB_CATEGORIES)),
+      type: Sequelize.ENUM('transcoding', 'activitypub-http'),
       defaultValue: 'transcoding',
       allowNull: false
     }
@@ -197,7 +201,7 @@ async function up (utils: {
     })
 
     for (const video of videos) {
-      await shareVideoByServer(video, undefined)
+      await shareVideoByServerAndChannel(video, undefined)
     }
   }
 }