From 50d6de9c286abcb34ff4234d56d9cbb803db7665 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Dec 2017 17:38:41 +0100 Subject: Begin moving video channel to actor --- server/initializers/constants.ts | 14 +++++++++++--- server/initializers/database.ts | 8 ++++---- server/initializers/installer.ts | 17 +++++++---------- server/initializers/migrations/0100-activitypub.ts | 4 ++-- 4 files changed, 24 insertions(+), 19 deletions(-) (limited to 'server/initializers') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index f209bef90..04b610b7a 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -1,7 +1,8 @@ import * as config from 'config' import { join } from 'path' import { JobCategory, JobState, VideoRateType } from '../../shared/models' -import { FollowState } from '../../shared/models/accounts' +import { FollowState } from '../../shared/models/actors' +import { ActivityPubActorType } from '../../shared/models/activitypub' import { VideoPrivacy } from '../../shared/models/videos' // Do not use barrels, remain constants as independent as possible import { isTestInstance, root } from '../helpers/core-utils' @@ -210,7 +211,7 @@ const VIDEO_MIMETYPE_EXT = { // --------------------------------------------------------------------------- -const SERVER_ACCOUNT_NAME = 'peertube' +const SERVER_ACTOR_NAME = 'peertube' const ACTIVITY_PUB = { POTENTIAL_ACCEPT_HEADERS: [ @@ -229,6 +230,12 @@ const ACTIVITY_PUB = { } } +const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = { + GROUP: 'Group', + PERSON: 'Person', + APPLICATION: 'Application' +} + // --------------------------------------------------------------------------- // Number of points we add/remove from a friend after a successful/bad request @@ -350,12 +357,13 @@ export { REMOTE_SCHEME, FOLLOW_STATES, AVATARS_DIR, - SERVER_ACCOUNT_NAME, + SERVER_ACTOR_NAME, PRIVATE_RSA_KEY_SIZE, SORTABLE_COLUMNS, STATIC_MAX_AGE, STATIC_PATHS, ACTIVITY_PUB, + ACTIVITY_PUB_ACTOR_TYPES, THUMBNAILS_SIZE, VIDEO_CATEGORIES, VIDEO_LANGUAGES, diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 85d205cdc..0b3f695f7 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts @@ -3,9 +3,10 @@ import { isTestInstance } from '../helpers/core-utils' import { logger } from '../helpers/logger' import { AccountModel } from '../models/account/account' -import { AccountFollowModel } from '../models/account/account-follow' import { AccountVideoRateModel } from '../models/account/account-video-rate' import { UserModel } from '../models/account/user' +import { ActorModel } from '../models/activitypub/actor' +import { ActorFollowModel } from '../models/activitypub/actor-follow' import { ApplicationModel } from '../models/application/application' import { AvatarModel } from '../models/avatar/avatar' import { JobModel } from '../models/job/job' @@ -17,7 +18,6 @@ import { VideoModel } from '../models/video/video' import { VideoAbuseModel } from '../models/video/video-abuse' import { VideoBlacklistModel } from '../models/video/video-blacklist' import { VideoChannelModel } from '../models/video/video-channel' -import { VideoChannelShareModel } from '../models/video/video-channel-share' import { VideoFileModel } from '../models/video/video-file' import { VideoShareModel } from '../models/video/video-share' import { VideoTagModel } from '../models/video/video-tag' @@ -56,6 +56,8 @@ const sequelizeTypescript = new SequelizeTypescript({ async function initDatabaseModels (silent: boolean) { sequelizeTypescript.addModels([ ApplicationModel, + ActorModel, + ActorFollowModel, AvatarModel, AccountModel, JobModel, @@ -64,11 +66,9 @@ async function initDatabaseModels (silent: boolean) { ServerModel, TagModel, AccountVideoRateModel, - AccountFollowModel, UserModel, VideoAbuseModel, VideoChannelModel, - VideoChannelShareModel, VideoShareModel, VideoFileModel, VideoBlacklistModel, diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 5452743b6..ee3c9dfd9 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts @@ -1,12 +1,12 @@ import * as passwordGenerator from 'password-generator' import { UserRole } from '../../shared' -import { createPrivateAndPublicKeys, logger, mkdirpPromise, rimrafPromise } from '../helpers' -import { createLocalAccountWithoutKeys, createUserAccountAndChannel } from '../lib' +import { logger, mkdirpPromise, rimrafPromise } from '../helpers' +import { createApplicationActor, createUserAccountAndChannel } from '../lib/user' import { UserModel } from '../models/account/user' import { ApplicationModel } from '../models/application/application' import { OAuthClientModel } from '../models/oauth/oauth-client' import { applicationExist, clientsExist, usersExist } from './checker' -import { CACHE, CONFIG, LAST_MIGRATION_VERSION, SERVER_ACCOUNT_NAME } from './constants' +import { CACHE, CONFIG, LAST_MIGRATION_VERSION } from './constants' import { sequelizeTypescript } from './database' async function installApplication () { @@ -134,15 +134,12 @@ async function createApplicationIfNotExist () { if (exist === true) return undefined logger.info('Creating Application table.') - const applicationInstance = await ApplicationModel.create({ migrationVersion: LAST_MIGRATION_VERSION }) logger.info('Creating application account.') - const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACCOUNT_NAME, null, applicationInstance.id, undefined) - - const { publicKey, privateKey } = await createPrivateAndPublicKeys() - accountCreated.set('publicKey', publicKey) - accountCreated.set('privateKey', privateKey) + const application = await ApplicationModel.create({ + migrationVersion: LAST_MIGRATION_VERSION + }) - return accountCreated.save() + return createApplicationActor(application.id) } diff --git a/server/initializers/migrations/0100-activitypub.ts b/server/initializers/migrations/0100-activitypub.ts index fb42e1d57..d896b3205 100644 --- a/server/initializers/migrations/0100-activitypub.ts +++ b/server/initializers/migrations/0100-activitypub.ts @@ -5,7 +5,7 @@ import { shareVideoByServer } 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 { JOB_CATEGORIES, SERVER_ACTOR_NAME } from '../constants' async function up (utils: { transaction: Sequelize.Transaction, @@ -66,7 +66,7 @@ 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(SERVER_ACTOR_NAME, null, applicationInstance.id, undefined) const { publicKey, privateKey } = await createPrivateAndPublicKeys() accountCreated.set('publicKey', publicKey) -- cgit v1.2.3