From 154898b0b7bc1af41fc5a94974e338a3590c90f3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 17 Jun 2017 11:28:11 +0200 Subject: Share models between server and client --- server/controllers/api/clients.ts | 6 ++++-- server/controllers/api/config.ts | 6 ++++-- server/controllers/api/users.ts | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/clients.ts b/server/controllers/api/clients.ts index 8c460096b..96490d04a 100644 --- a/server/controllers/api/clients.ts +++ b/server/controllers/api/clients.ts @@ -3,6 +3,7 @@ import * as express from 'express' import { CONFIG } from '../../initializers' import { logger } from '../../helpers' import { database as db } from '../../initializers/database' +import { ClientLocal } from '../../../shared' const clientsRouter = express.Router() @@ -27,10 +28,11 @@ function getLocalClient (req: express.Request, res: express.Response, next: expr if (err) return next(err) if (!client) return next(new Error('No client available.')) - res.json({ + const json: ClientLocal = { client_id: client.clientId, client_secret: client.clientSecret - }) + } + res.json(json) }) } diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index c63981797..3e9aa77a5 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -1,6 +1,7 @@ import * as express from 'express' import { CONFIG } from '../../initializers' +import { ServerConfig } from '../../../shared' const configRouter = express.Router() @@ -8,11 +9,12 @@ configRouter.get('/', getConfig) // Get the client credentials for the PeerTube front end function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { - res.json({ + const json: ServerConfig = { signup: { enabled: CONFIG.SIGNUP.ENABLED } - }) + } + res.json(json) } // --------------------------------------------------------------------------- diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index ffe5881e5..1e9e65689 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -17,6 +17,7 @@ import { setUsersSort, token } from '../../middlewares' +import { UserVideoRate as FormatedUserVideoRate } from '../../../shared' const usersRouter = express.Router() @@ -119,10 +120,11 @@ function getUserVideoRating (req: express.Request, res: express.Response, next: const rating = ratingObj ? ratingObj.type : 'none' - res.json({ + const json: FormatedUserVideoRate = { videoId, rating - }) + } + res.json(json) }) } -- cgit v1.2.3