aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/pod/pod.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-19 09:43:01 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-19 09:43:01 +0200
commit8a02bd0433b7101c5ea36e87a4edb63204d2adec (patch)
treed7ab4b6164aef752c216bd2f22f8b3b270a724b8 /server/models/pod/pod.ts
parent9fd540562c356cb54b98861d2d9e7d4fbfcd00e0 (diff)
downloadPeerTube-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.ts19
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'
4import { FRIEND_SCORE, PODS_SCORE } from '../../initializers' 4import { FRIEND_SCORE, PODS_SCORE } from '../../initializers'
5import { logger, isHostValid } from '../../helpers' 5import { logger, isHostValid } from '../../helpers'
6 6
7import { addMethodsToModel } from '../utils' 7import { addMethodsToModel, getSort } from '../utils'
8import { 8import {
9 PodInstance, 9 PodInstance,
10 PodAttributes, 10 PodAttributes,
@@ -17,6 +17,7 @@ let toFormattedJSON: PodMethods.ToFormattedJSON
17let countAll: PodMethods.CountAll 17let countAll: PodMethods.CountAll
18let incrementScores: PodMethods.IncrementScores 18let incrementScores: PodMethods.IncrementScores
19let list: PodMethods.List 19let list: PodMethods.List
20let listForApi: PodMethods.ListForApi
20let listAllIds: PodMethods.ListAllIds 21let listAllIds: PodMethods.ListAllIds
21let listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest 22let listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest
22let listBadPods: PodMethods.ListBadPods 23let 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
147listForApi = 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
145listAllIds = function (transaction: Sequelize.Transaction) { 162listAllIds = function (transaction: Sequelize.Transaction) {
146 const query = { 163 const query = {
147 attributes: [ 'id' ], 164 attributes: [ 'id' ],