diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-12 17:53:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-13 16:50:33 +0100 |
commit | 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch) | |
tree | e5ca358287fca6ecacce83defcf23af1e8e9f419 /server/initializers/installer.ts | |
parent | c893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff) | |
download | PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip |
Move models to typescript-sequelize
Diffstat (limited to 'server/initializers/installer.ts')
-rw-r--r-- | server/initializers/installer.ts | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 954516057..5452743b6 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts | |||
@@ -1,16 +1,17 @@ | |||
1 | import * as passwordGenerator from 'password-generator' | 1 | import * as passwordGenerator from 'password-generator' |
2 | import { UserRole } from '../../shared' | 2 | import { UserRole } from '../../shared' |
3 | import { logger, mkdirpPromise, rimrafPromise } from '../helpers' | 3 | import { createPrivateAndPublicKeys, logger, mkdirpPromise, rimrafPromise } from '../helpers' |
4 | import { createUserAccountAndChannel } from '../lib' | 4 | import { createLocalAccountWithoutKeys, createUserAccountAndChannel } from '../lib' |
5 | import { createLocalAccountWithoutKeys } from '../lib/user' | 5 | import { UserModel } from '../models/account/user' |
6 | import { ApplicationModel } from '../models/application/application' | ||
7 | import { OAuthClientModel } from '../models/oauth/oauth-client' | ||
6 | import { applicationExist, clientsExist, usersExist } from './checker' | 8 | import { applicationExist, clientsExist, usersExist } from './checker' |
7 | import { CACHE, CONFIG, LAST_MIGRATION_VERSION, SERVER_ACCOUNT_NAME } from './constants' | 9 | import { CACHE, CONFIG, LAST_MIGRATION_VERSION, SERVER_ACCOUNT_NAME } from './constants' |
8 | import { database as db } from './database' | 10 | import { sequelizeTypescript } from './database' |
9 | import { createPrivateAndPublicKeys } from '../helpers/peertube-crypto' | ||
10 | 11 | ||
11 | async function installApplication () { | 12 | async function installApplication () { |
12 | try { | 13 | try { |
13 | await db.sequelize.sync() | 14 | await sequelizeTypescript.sync() |
14 | await removeCacheDirectories() | 15 | await removeCacheDirectories() |
15 | await createDirectoriesIfNotExist() | 16 | await createDirectoriesIfNotExist() |
16 | await createApplicationIfNotExist() | 17 | await createApplicationIfNotExist() |
@@ -64,7 +65,7 @@ function createDirectoriesIfNotExist () { | |||
64 | } | 65 | } |
65 | 66 | ||
66 | async function createOAuthClientIfNotExist () { | 67 | async function createOAuthClientIfNotExist () { |
67 | const exist = await clientsExist(db.OAuthClient) | 68 | const exist = await clientsExist() |
68 | // Nothing to do, clients already exist | 69 | // Nothing to do, clients already exist |
69 | if (exist === true) return undefined | 70 | if (exist === true) return undefined |
70 | 71 | ||
@@ -72,7 +73,7 @@ async function createOAuthClientIfNotExist () { | |||
72 | 73 | ||
73 | const id = passwordGenerator(32, false, /[a-z0-9]/) | 74 | const id = passwordGenerator(32, false, /[a-z0-9]/) |
74 | const secret = passwordGenerator(32, false, /[a-zA-Z0-9]/) | 75 | const secret = passwordGenerator(32, false, /[a-zA-Z0-9]/) |
75 | const client = db.OAuthClient.build({ | 76 | const client = new OAuthClientModel({ |
76 | clientId: id, | 77 | clientId: id, |
77 | clientSecret: secret, | 78 | clientSecret: secret, |
78 | grants: [ 'password', 'refresh_token' ], | 79 | grants: [ 'password', 'refresh_token' ], |
@@ -87,7 +88,7 @@ async function createOAuthClientIfNotExist () { | |||
87 | } | 88 | } |
88 | 89 | ||
89 | async function createOAuthAdminIfNotExist () { | 90 | async function createOAuthAdminIfNotExist () { |
90 | const exist = await usersExist(db.User) | 91 | const exist = await usersExist() |
91 | // Nothing to do, users already exist | 92 | // Nothing to do, users already exist |
92 | if (exist === true) return undefined | 93 | if (exist === true) return undefined |
93 | 94 | ||
@@ -120,7 +121,7 @@ async function createOAuthAdminIfNotExist () { | |||
120 | role, | 121 | role, |
121 | videoQuota: -1 | 122 | videoQuota: -1 |
122 | } | 123 | } |
123 | const user = db.User.build(userData) | 124 | const user = new UserModel(userData) |
124 | 125 | ||
125 | await createUserAccountAndChannel(user, validatePassword) | 126 | await createUserAccountAndChannel(user, validatePassword) |
126 | logger.info('Username: ' + username) | 127 | logger.info('Username: ' + username) |
@@ -128,12 +129,12 @@ async function createOAuthAdminIfNotExist () { | |||
128 | } | 129 | } |
129 | 130 | ||
130 | async function createApplicationIfNotExist () { | 131 | async function createApplicationIfNotExist () { |
131 | const exist = await applicationExist(db.Application) | 132 | const exist = await applicationExist() |
132 | // Nothing to do, application already exist | 133 | // Nothing to do, application already exist |
133 | if (exist === true) return undefined | 134 | if (exist === true) return undefined |
134 | 135 | ||
135 | logger.info('Creating Application table.') | 136 | logger.info('Creating Application table.') |
136 | const applicationInstance = await db.Application.create({ migrationVersion: LAST_MIGRATION_VERSION }) | 137 | const applicationInstance = await ApplicationModel.create({ migrationVersion: LAST_MIGRATION_VERSION }) |
137 | 138 | ||
138 | logger.info('Creating application account.') | 139 | logger.info('Creating application account.') |
139 | 140 | ||