]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/users/login-command.ts
Refactor requests
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / users / login-command.ts
index b4e3bb602cb2f9151e453dcc69c8ca278fb07720..b39577260e6f7d5c55ff9ae5995baabc15e46781 100644 (file)
@@ -1,4 +1,4 @@
-import { HttpStatusCode } from '@shared/core-utils'
+import { HttpStatusCode } from '@shared/models'
 import { PeerTubeProblemDocument } from '@shared/models'
 import { unwrapBody } from '../requests'
 import { AbstractCommand, OverrideCommandOptions } from '../shared'
@@ -9,7 +9,7 @@ export class LoginCommand extends AbstractCommand {
     client?: { id?: string, secret?: string }
     user?: { username: string, password?: string }
   } = {}) {
-    const { client = this.server.client, user = this.server.user } = options
+    const { client = this.server.store.client, user = this.server.store.user } = options
     const path = '/api/v1/users/token'
 
     const body = {
@@ -26,7 +26,7 @@ export class LoginCommand extends AbstractCommand {
       ...options,
 
       path,
-      type: 'form',
+      requestType: 'form',
       fields: body,
       implicitToken: false,
       defaultExpectedStatus: HttpStatusCode.OK_200
@@ -38,7 +38,7 @@ export class LoginCommand extends AbstractCommand {
   async getAccessToken (arg1?: { username: string, password?: string } | string, password?: string) {
     let user: { username: string, password?: string }
 
-    if (!arg1) user = this.server.user
+    if (!arg1) user = this.server.store.user
     else if (typeof arg1 === 'object') user = arg1
     else user = { username: arg1, password }
 
@@ -59,8 +59,8 @@ export class LoginCommand extends AbstractCommand {
     const path = '/api/v1/users/token'
 
     const body = {
-      client_id: this.server.client.id,
-      client_secret: this.server.client.secret,
+      client_id: this.server.store.client.id,
+      client_secret: this.server.store.client.secret,
       username: username,
       response_type: 'code',
       grant_type: 'password',
@@ -72,7 +72,7 @@ export class LoginCommand extends AbstractCommand {
       ...options,
 
       path,
-      type: 'form',
+      requestType: 'form',
       fields: body,
       implicitToken: false,
       defaultExpectedStatus: HttpStatusCode.OK_200
@@ -88,7 +88,7 @@ export class LoginCommand extends AbstractCommand {
       ...options,
 
       path,
-      type: 'form',
+      requestType: 'form',
       implicitToken: false,
       defaultExpectedStatus: HttpStatusCode.OK_200
     }))
@@ -100,8 +100,8 @@ export class LoginCommand extends AbstractCommand {
     const path = '/api/v1/users/token'
 
     const body = {
-      client_id: this.server.client.id,
-      client_secret: this.server.client.secret,
+      client_id: this.server.store.client.id,
+      client_secret: this.server.store.client.secret,
       refresh_token: options.refreshToken,
       response_type: 'code',
       grant_type: 'refresh_token'
@@ -111,7 +111,7 @@ export class LoginCommand extends AbstractCommand {
       ...options,
 
       path,
-      type: 'form',
+      requestType: 'form',
       fields: body,
       implicitToken: false,
       defaultExpectedStatus: HttpStatusCode.OK_200