aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-26 10:55:40 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-03-18 11:17:59 +0100
commit418d092afa81e2c8fe8ac6838fc4b5eb0af6a782 (patch)
tree5e9bc5604fd5d66a006cfebb7acdbdd5486e5d1e /server/models/utils.ts
parentb427febb4d5cebf03b815bca2c59af6e82491569 (diff)
downloadPeerTube-418d092afa81e2c8fe8ac6838fc4b5eb0af6a782.tar.gz
PeerTube-418d092afa81e2c8fe8ac6838fc4b5eb0af6a782.tar.zst
PeerTube-418d092afa81e2c8fe8ac6838fc4b5eb0af6a782.zip
Playlist server API
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r--server/models/utils.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts
index 5b4093aec..4ebd07dab 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -1,4 +1,5 @@
1import { Sequelize } from 'sequelize-typescript' 1import { Sequelize } from 'sequelize-typescript'
2import * as validator from 'validator'
2 3
3type SortType = { sortModel: any, sortValue: string } 4type SortType = { sortModel: any, sortValue: string }
4 5
@@ -74,13 +75,25 @@ function buildBlockedAccountSQL (serverAccountId: number, userAccountId?: number
74 75
75 const blockerIdsString = blockerIds.join(', ') 76 const blockerIdsString = blockerIds.join(', ')
76 77
77 const query = 'SELECT "targetAccountId" AS "id" FROM "accountBlocklist" WHERE "accountId" IN (' + blockerIdsString + ')' + 78 return 'SELECT "targetAccountId" AS "id" FROM "accountBlocklist" WHERE "accountId" IN (' + blockerIdsString + ')' +
78 ' UNION ALL ' + 79 ' UNION ALL ' +
79 'SELECT "account"."id" AS "id" FROM account INNER JOIN "actor" ON account."actorId" = actor.id ' + 80 'SELECT "account"."id" AS "id" FROM account INNER JOIN "actor" ON account."actorId" = actor.id ' +
80 'INNER JOIN "serverBlocklist" ON "actor"."serverId" = "serverBlocklist"."targetServerId" ' + 81 'INNER JOIN "serverBlocklist" ON "actor"."serverId" = "serverBlocklist"."targetServerId" ' +
81 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')' 82 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')'
83}
84
85function buildServerIdsFollowedBy (actorId: any) {
86 const actorIdNumber = parseInt(actorId + '', 10)
87
88 return '(' +
89 'SELECT "actor"."serverId" FROM "actorFollow" ' +
90 'INNER JOIN "actor" ON actor.id = "actorFollow"."targetActorId" ' +
91 'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
92 ')'
93}
82 94
83 return query 95function buildWhereIdOrUUID (id: number | string) {
96 return validator.isInt('' + id) ? { id } : { uuid: id }
84} 97}
85 98
86// --------------------------------------------------------------------------- 99// ---------------------------------------------------------------------------
@@ -93,7 +106,9 @@ export {
93 getSortOnModel, 106 getSortOnModel,
94 createSimilarityAttribute, 107 createSimilarityAttribute,
95 throwIfNotValid, 108 throwIfNotValid,
96 buildTrigramSearchIndex 109 buildServerIdsFollowedBy,
110 buildTrigramSearchIndex,
111 buildWhereIdOrUUID
97} 112}
98 113
99// --------------------------------------------------------------------------- 114// ---------------------------------------------------------------------------