X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fcontrollers%2Fapi%2Foauth-clients.ts;h=3dcc023e6e20ba80ffc099e499cca56ac96feb7d;hb=b4d1af3dd8cdab2d58927e671d62194ca383cd75;hp=b9bc0534f24db865741f703dd917472e74e361d5;hpb=0a381679e04bc7adf097da9a6fb4e2c8f41bbda2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts index b9bc0534f..3dcc023e6 100644 --- a/server/controllers/api/oauth-clients.ts +++ b/server/controllers/api/oauth-clients.ts @@ -1,16 +1,18 @@ import * as express from 'express' - -import { CONFIG } from '../../initializers' -import { logger } from '../../helpers' -import { database as db } from '../../initializers/database' import { OAuthClientLocal } from '../../../shared' +import { logger } from '../../helpers/logger' +import { CONFIG } from '../../initializers' +import { asyncMiddleware } from '../../middlewares' +import { OAuthClientModel } from '../../models/oauth/oauth-client' const oauthClientsRouter = express.Router() -oauthClientsRouter.get('/local', getLocalClient) +oauthClientsRouter.get('/local', + asyncMiddleware(getLocalClient) +) // Get the client credentials for the PeerTube front end -function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { +async function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { const serverHostname = CONFIG.WEBSERVER.HOSTNAME const serverPort = CONFIG.WEBSERVER.PORT let headerHostShouldBe = serverHostname @@ -24,16 +26,14 @@ function getLocalClient (req: express.Request, res: express.Response, next: expr return res.type('json').status(403).end() } - db.OAuthClient.loadFirstClient(function (err, client) { - if (err) return next(err) - if (!client) return next(new Error('No client available.')) + const client = await OAuthClientModel.loadFirstClient() + if (!client) throw new Error('No client available.') - const json: OAuthClientLocal = { - client_id: client.clientId, - client_secret: client.clientSecret - } - res.json(json) - }) + const json: OAuthClientLocal = { + client_id: client.clientId, + client_secret: client.clientSecret + } + return res.json(json) } // ---------------------------------------------------------------------------