X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Futils.ts;h=f89b80011ae5b5860b58233c531e92cb7be99df4;hb=0374b6b5cd685316f924874b2a3068bb345eb0dd;hp=ccdbcd1cf7d8a81eafebc5668152315f44003a2a;hpb=d7a25329f9e607894d29ab342b9cb66638b56dc0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/utils.ts b/server/models/utils.ts index ccdbcd1cf..f89b80011 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -1,5 +1,5 @@ import { Model, Sequelize } from 'sequelize-typescript' -import * as validator from 'validator' +import validator from 'validator' import { Col } from 'sequelize/types/lib/utils' import { literal, OrderItem } from 'sequelize' @@ -22,6 +22,19 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt return [ [ finalField, direction ], lastSort ] } +function getCommentSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { + const { direction, field } = buildDirectionAndField(value) + + if (field === 'totalReplies') { + return [ + [ Sequelize.literal('"totalReplies"'), direction ], + lastSort + ] + } + + return getSort(value, lastSort) +} + function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { const { direction, field } = buildDirectionAndField(value) @@ -58,6 +71,19 @@ function getBlacklistSort (model: any, value: string, lastSort: OrderItem = [ 'i return [ firstSort, lastSort ] } +function getFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { + const { direction, field } = buildDirectionAndField(value) + + if (field === 'redundancyAllowed') { + return [ + [ 'ActorFollowing', 'Server', 'redundancyAllowed', direction ], + lastSort + ] + } + + return getSort(value, lastSort) +} + function isOutdated (model: { createdAt: Date, updatedAt: Date }, refreshInterval: number) { const now = Date.now() const createdAtTime = model.createdAt.getTime() @@ -154,6 +180,7 @@ export { SortType, buildLocalAccountIdsIn, getSort, + getCommentSort, getVideoSort, getBlacklistSort, createSimilarityAttribute, @@ -163,6 +190,7 @@ export { buildWhereIdOrUUID, isOutdated, parseAggregateResult, + getFollowsSort, createSafeIn }