X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=6856dcd9f057baa5f7d0f7c895afee3d7df8e43f;hb=282e61e6c11f79e919c543871783fe1a00298d18;hp=ab7b49f1e6c9b95d1fd22f3059a11b7822bbbb63;hpb=b5fecbf44192144d1ca27c23a0b53922de288c10;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index ab7b49f1e..6856dcd9f 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -135,6 +135,7 @@ import { MVideoFullLight, MVideoIdThumbnail, MVideoThumbnail, + MVideoThumbnailBlacklist, MVideoWithAllFiles, MVideoWithFile, MVideoWithRights @@ -467,13 +468,15 @@ export type AvailableForListIDsOptions = { // FIXME: issues with sequelize count when making a join on n:m relation, so we just make a IN() if (options.tagsAllOf || options.tagsOneOf) { if (options.tagsOneOf) { + const tagsOneOfLower = options.tagsOneOf.map(t => t.toLowerCase()) + whereAnd.push({ id: { [ Op.in ]: Sequelize.literal( '(' + 'SELECT "videoId" FROM "videoTag" ' + 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' + - 'WHERE "tag"."name" IN (' + createSafeIn(VideoModel, options.tagsOneOf) + ')' + + 'WHERE lower("tag"."name") IN (' + createSafeIn(VideoModel, tagsOneOfLower) + ')' + ')' ) } @@ -481,14 +484,16 @@ export type AvailableForListIDsOptions = { } if (options.tagsAllOf) { + const tagsAllOfLower = options.tagsAllOf.map(t => t.toLowerCase()) + whereAnd.push({ id: { [ Op.in ]: Sequelize.literal( '(' + 'SELECT "videoId" FROM "videoTag" ' + 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' + - 'WHERE "tag"."name" IN (' + createSafeIn(VideoModel, options.tagsAllOf) + ')' + - 'GROUP BY "videoTag"."videoId" HAVING COUNT(*) = ' + options.tagsAllOf.length + + 'WHERE lower("tag"."name") IN (' + createSafeIn(VideoModel, tagsAllOfLower) + ')' + + 'GROUP BY "videoTag"."videoId" HAVING COUNT(*) = ' + tagsAllOfLower.length + ')' ) } @@ -1409,6 +1414,19 @@ export class VideoModel extends Model { return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) } + static loadWithBlacklist (id: number | string, t?: Transaction): Bluebird { + const where = buildWhereIdOrUUID(id) + const options = { + where, + transaction: t + } + + return VideoModel.scope([ + ScopeNames.WITH_THUMBNAILS, + ScopeNames.WITH_BLACKLISTED + ]).findOne(options) + } + static loadWithRights (id: number | string, t?: Transaction): Bluebird { const where = buildWhereIdOrUUID(id) const options = {