aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-06 17:19:53 +0200
committerChocobozzz <me@florianbigard.com>2019-08-06 17:26:51 +0200
commit6b9c966f6428c9e47bead3410a0401e8ebd744bf (patch)
tree282218ec56725b0e2e878b0471cd08a54fd91998 /server/models/utils.ts
parent466e3f20a537f1eff4b4fd03297df11ba371d049 (diff)
downloadPeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.tar.gz
PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.tar.zst
PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.zip
Automatically remove bad followings
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r--server/models/utils.ts20
1 files changed, 17 insertions, 3 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts
index 30de91e1d..24890f961 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -1,7 +1,7 @@
1import { Model, Sequelize } from 'sequelize-typescript' 1import { Model, Sequelize } from 'sequelize-typescript'
2import * as validator from 'validator' 2import * as validator from 'validator'
3import { Col } from 'sequelize/types/lib/utils' 3import { Col } from 'sequelize/types/lib/utils'
4import { OrderItem } from 'sequelize/types' 4import { OrderItem, literal } from 'sequelize'
5 5
6type SortType = { sortModel: any, sortValue: string } 6type SortType = { sortModel: any, sortValue: string }
7 7
@@ -129,16 +129,30 @@ function parseAggregateResult (result: any) {
129 return total 129 return total
130} 130}
131 131
132const createSafeIn = (model: typeof Model, stringArr: string[]) => { 132const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => {
133 return stringArr.map(t => model.sequelize.escape(t)) 133 return stringArr.map(t => model.sequelize.escape('' + t))
134 .join(', ') 134 .join(', ')
135} 135}
136 136
137function buildLocalAccountIdsIn () {
138 return literal(
139 '(SELECT "account"."id" FROM "account" INNER JOIN "actor" ON "actor"."id" = "account"."actorId" AND "actor"."serverId" IS NULL)'
140 )
141}
142
143function buildLocalActorIdsIn () {
144 return literal(
145 '(SELECT "actor"."id" FROM "actor" WHERE "actor"."serverId" IS NULL)'
146 )
147}
148
137// --------------------------------------------------------------------------- 149// ---------------------------------------------------------------------------
138 150
139export { 151export {
140 buildBlockedAccountSQL, 152 buildBlockedAccountSQL,
153 buildLocalActorIdsIn,
141 SortType, 154 SortType,
155 buildLocalAccountIdsIn,
142 getSort, 156 getSort,
143 getVideoSort, 157 getVideoSort,
144 getSortOnModel, 158 getSortOnModel,