diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-19 09:43:01 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-19 09:43:01 +0200 |
commit | 8a02bd0433b7101c5ea36e87a4edb63204d2adec (patch) | |
tree | d7ab4b6164aef752c216bd2f22f8b3b270a724b8 /server/models/pod/pod.ts | |
parent | 9fd540562c356cb54b98861d2d9e7d4fbfcd00e0 (diff) | |
download | PeerTube-8a02bd0433b7101c5ea36e87a4edb63204d2adec.tar.gz PeerTube-8a02bd0433b7101c5ea36e87a4edb63204d2adec.tar.zst PeerTube-8a02bd0433b7101c5ea36e87a4edb63204d2adec.zip |
Add pod list endpoint with pagination, sort...
Diffstat (limited to 'server/models/pod/pod.ts')
-rw-r--r-- | server/models/pod/pod.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/server/models/pod/pod.ts b/server/models/pod/pod.ts index 1440ac9b4..e4d7db48a 100644 --- a/server/models/pod/pod.ts +++ b/server/models/pod/pod.ts | |||
@@ -4,7 +4,7 @@ import * as Sequelize from 'sequelize' | |||
4 | import { FRIEND_SCORE, PODS_SCORE } from '../../initializers' | 4 | import { FRIEND_SCORE, PODS_SCORE } from '../../initializers' |
5 | import { logger, isHostValid } from '../../helpers' | 5 | import { logger, isHostValid } from '../../helpers' |
6 | 6 | ||
7 | import { addMethodsToModel } from '../utils' | 7 | import { addMethodsToModel, getSort } from '../utils' |
8 | import { | 8 | import { |
9 | PodInstance, | 9 | PodInstance, |
10 | PodAttributes, | 10 | PodAttributes, |
@@ -17,6 +17,7 @@ let toFormattedJSON: PodMethods.ToFormattedJSON | |||
17 | let countAll: PodMethods.CountAll | 17 | let countAll: PodMethods.CountAll |
18 | let incrementScores: PodMethods.IncrementScores | 18 | let incrementScores: PodMethods.IncrementScores |
19 | let list: PodMethods.List | 19 | let list: PodMethods.List |
20 | let listForApi: PodMethods.ListForApi | ||
20 | let listAllIds: PodMethods.ListAllIds | 21 | let listAllIds: PodMethods.ListAllIds |
21 | let listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest | 22 | let listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest |
22 | let listBadPods: PodMethods.ListBadPods | 23 | let listBadPods: PodMethods.ListBadPods |
@@ -78,6 +79,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
78 | countAll, | 79 | countAll, |
79 | incrementScores, | 80 | incrementScores, |
80 | list, | 81 | list, |
82 | listForApi, | ||
81 | listAllIds, | 83 | listAllIds, |
82 | listRandomPodIdsWithRequest, | 84 | listRandomPodIdsWithRequest, |
83 | listBadPods, | 85 | listBadPods, |
@@ -142,6 +144,21 @@ list = function () { | |||
142 | return Pod.findAll() | 144 | return Pod.findAll() |
143 | } | 145 | } |
144 | 146 | ||
147 | listForApi = function (start: number, count: number, sort: string) { | ||
148 | const query = { | ||
149 | offset: start, | ||
150 | limit: count, | ||
151 | order: [ getSort(sort) ] | ||
152 | } | ||
153 | |||
154 | return Pod.findAndCountAll(query).then(({ rows, count }) => { | ||
155 | return { | ||
156 | data: rows, | ||
157 | total: count | ||
158 | } | ||
159 | }) | ||
160 | } | ||
161 | |||
145 | listAllIds = function (transaction: Sequelize.Transaction) { | 162 | listAllIds = function (transaction: Sequelize.Transaction) { |
146 | const query = { | 163 | const query = { |
147 | attributes: [ 'id' ], | 164 | attributes: [ 'id' ], |