diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-06 17:19:53 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-06 17:26:51 +0200 |
commit | 6b9c966f6428c9e47bead3410a0401e8ebd744bf (patch) | |
tree | 282218ec56725b0e2e878b0471cd08a54fd91998 /server/models/utils.ts | |
parent | 466e3f20a537f1eff4b4fd03297df11ba371d049 (diff) | |
download | PeerTube-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.ts | 20 |
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 @@ | |||
1 | import { Model, Sequelize } from 'sequelize-typescript' | 1 | import { Model, Sequelize } from 'sequelize-typescript' |
2 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
3 | import { Col } from 'sequelize/types/lib/utils' | 3 | import { Col } from 'sequelize/types/lib/utils' |
4 | import { OrderItem } from 'sequelize/types' | 4 | import { OrderItem, literal } from 'sequelize' |
5 | 5 | ||
6 | type SortType = { sortModel: any, sortValue: string } | 6 | type 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 | ||
132 | const createSafeIn = (model: typeof Model, stringArr: string[]) => { | 132 | const 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 | ||
137 | function 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 | |||
143 | function buildLocalActorIdsIn () { | ||
144 | return literal( | ||
145 | '(SELECT "actor"."id" FROM "actor" WHERE "actor"."serverId" IS NULL)' | ||
146 | ) | ||
147 | } | ||
148 | |||
137 | // --------------------------------------------------------------------------- | 149 | // --------------------------------------------------------------------------- |
138 | 150 | ||
139 | export { | 151 | export { |
140 | buildBlockedAccountSQL, | 152 | buildBlockedAccountSQL, |
153 | buildLocalActorIdsIn, | ||
141 | SortType, | 154 | SortType, |
155 | buildLocalAccountIdsIn, | ||
142 | getSort, | 156 | getSort, |
143 | getVideoSort, | 157 | getVideoSort, |
144 | getSortOnModel, | 158 | getSortOnModel, |