diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-17 11:28:11 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-17 11:28:11 +0200 |
commit | 154898b0b7bc1af41fc5a94974e338a3590c90f3 (patch) | |
tree | 5fb90f66da7587aed53c99ac1884c7acd0c1f7ca /server | |
parent | df98563e2104b82b119c00a3cd83cd0dc1242d25 (diff) | |
download | PeerTube-154898b0b7bc1af41fc5a94974e338a3590c90f3.tar.gz PeerTube-154898b0b7bc1af41fc5a94974e338a3590c90f3.tar.zst PeerTube-154898b0b7bc1af41fc5a94974e338a3590c90f3.zip |
Share models between server and client
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/clients.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/config.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/users.ts | 6 | ||||
-rw-r--r-- | server/helpers/utils.ts | 8 | ||||
-rw-r--r-- | server/models/user/user-interface.ts | 4 | ||||
-rw-r--r-- | server/models/user/user-video-rate.ts | 1 | ||||
-rw-r--r-- | server/models/video/video-abuse-interface.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-abuse.ts | 5 | ||||
-rw-r--r-- | server/models/video/video-blacklist-interface.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-interface.ts | 11 |
10 files changed, 41 insertions, 12 deletions
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' | |||
3 | import { CONFIG } from '../../initializers' | 3 | import { CONFIG } from '../../initializers' |
4 | import { logger } from '../../helpers' | 4 | import { logger } from '../../helpers' |
5 | import { database as db } from '../../initializers/database' | 5 | import { database as db } from '../../initializers/database' |
6 | import { ClientLocal } from '../../../shared' | ||
6 | 7 | ||
7 | const clientsRouter = express.Router() | 8 | const clientsRouter = express.Router() |
8 | 9 | ||
@@ -27,10 +28,11 @@ function getLocalClient (req: express.Request, res: express.Response, next: expr | |||
27 | if (err) return next(err) | 28 | if (err) return next(err) |
28 | if (!client) return next(new Error('No client available.')) | 29 | if (!client) return next(new Error('No client available.')) |
29 | 30 | ||
30 | res.json({ | 31 | const json: ClientLocal = { |
31 | client_id: client.clientId, | 32 | client_id: client.clientId, |
32 | client_secret: client.clientSecret | 33 | client_secret: client.clientSecret |
33 | }) | 34 | } |
35 | res.json(json) | ||
34 | }) | 36 | }) |
35 | } | 37 | } |
36 | 38 | ||
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | 2 | ||
3 | import { CONFIG } from '../../initializers' | 3 | import { CONFIG } from '../../initializers' |
4 | import { ServerConfig } from '../../../shared' | ||
4 | 5 | ||
5 | const configRouter = express.Router() | 6 | const configRouter = express.Router() |
6 | 7 | ||
@@ -8,11 +9,12 @@ configRouter.get('/', getConfig) | |||
8 | 9 | ||
9 | // Get the client credentials for the PeerTube front end | 10 | // Get the client credentials for the PeerTube front end |
10 | function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { | 11 | function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { |
11 | res.json({ | 12 | const json: ServerConfig = { |
12 | signup: { | 13 | signup: { |
13 | enabled: CONFIG.SIGNUP.ENABLED | 14 | enabled: CONFIG.SIGNUP.ENABLED |
14 | } | 15 | } |
15 | }) | 16 | } |
17 | res.json(json) | ||
16 | } | 18 | } |
17 | 19 | ||
18 | // --------------------------------------------------------------------------- | 20 | // --------------------------------------------------------------------------- |
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 { | |||
17 | setUsersSort, | 17 | setUsersSort, |
18 | token | 18 | token |
19 | } from '../../middlewares' | 19 | } from '../../middlewares' |
20 | import { UserVideoRate as FormatedUserVideoRate } from '../../../shared' | ||
20 | 21 | ||
21 | const usersRouter = express.Router() | 22 | const usersRouter = express.Router() |
22 | 23 | ||
@@ -119,10 +120,11 @@ function getUserVideoRating (req: express.Request, res: express.Response, next: | |||
119 | 120 | ||
120 | const rating = ratingObj ? ratingObj.type : 'none' | 121 | const rating = ratingObj ? ratingObj.type : 'none' |
121 | 122 | ||
122 | res.json({ | 123 | const json: FormatedUserVideoRate = { |
123 | videoId, | 124 | videoId, |
124 | rating | 125 | rating |
125 | }) | 126 | } |
127 | res.json(json) | ||
126 | }) | 128 | }) |
127 | } | 129 | } |
128 | 130 | ||
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 07c1b3f51..5b8d21f70 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -22,8 +22,12 @@ function createEmptyCallback () { | |||
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
25 | function getFormatedObjects (objects: any[], objectsTotal: number) { | 25 | interface FormatableToJSON { |
26 | const formatedObjects = [] | 26 | toFormatedJSON() |
27 | } | ||
28 | |||
29 | function getFormatedObjects<U, T extends FormatableToJSON> (objects: T[], objectsTotal: number) { | ||
30 | const formatedObjects: U[] = [] | ||
27 | 31 | ||
28 | objects.forEach(function (object) { | 32 | objects.forEach(function (object) { |
29 | formatedObjects.push(object.toFormatedJSON()) | 33 | formatedObjects.push(object.toFormatedJSON()) |
diff --git a/server/models/user/user-interface.ts b/server/models/user/user-interface.ts index fd98a042e..48c67678b 100644 --- a/server/models/user/user-interface.ts +++ b/server/models/user/user-interface.ts | |||
@@ -58,6 +58,10 @@ export interface UserInstance extends UserClass, UserAttributes, Sequelize.Insta | |||
58 | id: number | 58 | id: number |
59 | createdAt: Date | 59 | createdAt: Date |
60 | updatedAt: Date | 60 | updatedAt: Date |
61 | |||
62 | isPasswordMatch: UserMethods.IsPasswordMatch | ||
63 | toFormatedJSON: UserMethods.ToFormatedJSON | ||
64 | isAdmin: UserMethods.IsAdmin | ||
61 | } | 65 | } |
62 | 66 | ||
63 | export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {} | 67 | export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {} |
diff --git a/server/models/user/user-video-rate.ts b/server/models/user/user-video-rate.ts index 1094eb281..4bdd35bc9 100644 --- a/server/models/user/user-video-rate.ts +++ b/server/models/user/user-video-rate.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | User rates per video. | 2 | User rates per video. |
3 | |||
4 | */ | 3 | */ |
5 | import { values } from 'lodash' | 4 | import { values } from 'lodash' |
6 | import * as Sequelize from 'sequelize' | 5 | import * as Sequelize from 'sequelize' |
diff --git a/server/models/video/video-abuse-interface.ts b/server/models/video/video-abuse-interface.ts index f3e32f79c..c85d09091 100644 --- a/server/models/video/video-abuse-interface.ts +++ b/server/models/video/video-abuse-interface.ts | |||
@@ -6,7 +6,7 @@ import { PodInstance } from '../pod' | |||
6 | import { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/video-abuse.model' | 6 | import { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/video-abuse.model' |
7 | 7 | ||
8 | export namespace VideoAbuseMethods { | 8 | export namespace VideoAbuseMethods { |
9 | export type toFormatedJSON = () => FormatedVideoAbuse | 9 | export type ToFormatedJSON = (this: VideoAbuseInstance) => FormatedVideoAbuse |
10 | 10 | ||
11 | export type ListForApiCallback = (err: Error, videoAbuseInstances?: VideoAbuseInstance[], total?: number) => void | 11 | export type ListForApiCallback = (err: Error, videoAbuseInstances?: VideoAbuseInstance[], total?: number) => void |
12 | export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void | 12 | export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void |
@@ -28,6 +28,8 @@ export interface VideoAbuseInstance extends VideoAbuseClass, VideoAbuseAttribute | |||
28 | updatedAt: Date | 28 | updatedAt: Date |
29 | 29 | ||
30 | Pod: PodInstance | 30 | Pod: PodInstance |
31 | |||
32 | toFormatedJSON: VideoAbuseMethods.ToFormatedJSON | ||
31 | } | 33 | } |
32 | 34 | ||
33 | export interface VideoAbuseModel extends VideoAbuseClass, Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> {} | 35 | export interface VideoAbuseModel extends VideoAbuseClass, Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> {} |
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index f5b4debe6..bc5f01e21 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts | |||
@@ -13,6 +13,7 @@ import { | |||
13 | } from './video-abuse-interface' | 13 | } from './video-abuse-interface' |
14 | 14 | ||
15 | let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> | 15 | let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes> |
16 | let toFormatedJSON: VideoAbuseMethods.ToFormatedJSON | ||
16 | let listForApi: VideoAbuseMethods.ListForApi | 17 | let listForApi: VideoAbuseMethods.ListForApi |
17 | 18 | ||
18 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 19 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
@@ -66,7 +67,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
66 | 67 | ||
67 | // ------------------------------ METHODS ------------------------------ | 68 | // ------------------------------ METHODS ------------------------------ |
68 | 69 | ||
69 | function toFormatedJSON (this: VideoAbuseInstance) { | 70 | toFormatedJSON = function (this: VideoAbuseInstance) { |
70 | let reporterPodHost | 71 | let reporterPodHost |
71 | 72 | ||
72 | if (this.Pod) { | 73 | if (this.Pod) { |
@@ -108,7 +109,7 @@ function associate (models) { | |||
108 | }) | 109 | }) |
109 | } | 110 | } |
110 | 111 | ||
111 | listForApi = function (start, count, sort, callback) { | 112 | listForApi = function (start: number, count: number, sort: string, callback: VideoAbuseMethods.ListForApiCallback) { |
112 | const query = { | 113 | const query = { |
113 | offset: start, | 114 | offset: start, |
114 | limit: count, | 115 | limit: count, |
diff --git a/server/models/video/video-blacklist-interface.ts b/server/models/video/video-blacklist-interface.ts index c34e7fb09..d4d6528d1 100644 --- a/server/models/video/video-blacklist-interface.ts +++ b/server/models/video/video-blacklist-interface.ts | |||
@@ -39,6 +39,8 @@ export interface BlacklistedVideoInstance extends BlacklistedVideoClass, Blackli | |||
39 | id: number | 39 | id: number |
40 | createdAt: Date | 40 | createdAt: Date |
41 | updatedAt: Date | 41 | updatedAt: Date |
42 | |||
43 | toFormatedJSON: BlacklistedVideoMethods.ToFormatedJSON | ||
42 | } | 44 | } |
43 | 45 | ||
44 | export interface BlacklistedVideoModel extends BlacklistedVideoClass, Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes> {} | 46 | export interface BlacklistedVideoModel extends BlacklistedVideoClass, Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes> {} |
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts index 5fefc2bb1..4b591b9e7 100644 --- a/server/models/video/video-interface.ts +++ b/server/models/video/video-interface.ts | |||
@@ -146,6 +146,17 @@ export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.In | |||
146 | id: string | 146 | id: string |
147 | createdAt: Date | 147 | createdAt: Date |
148 | updatedAt: Date | 148 | updatedAt: Date |
149 | |||
150 | generateMagnetUri: VideoMethods.GenerateMagnetUri | ||
151 | getVideoFilename: VideoMethods.GetVideoFilename | ||
152 | getThumbnailName: VideoMethods.GetThumbnailName | ||
153 | getPreviewName: VideoMethods.GetPreviewName | ||
154 | getTorrentName: VideoMethods.GetTorrentName | ||
155 | isOwned: VideoMethods.IsOwned | ||
156 | toFormatedJSON: VideoMethods.ToFormatedJSON | ||
157 | toAddRemoteJSON: VideoMethods.ToAddRemoteJSON | ||
158 | toUpdateRemoteJSON: VideoMethods.ToUpdateRemoteJSON | ||
159 | transcodeVideofile: VideoMethods.TranscodeVideofile | ||
149 | } | 160 | } |
150 | 161 | ||
151 | export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {} | 162 | export interface VideoModel extends VideoClass, Sequelize.Model<VideoInstance, VideoAttributes> {} |