X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-share.ts;h=fa9a70d509b42fccb99a59e8a10b9139a91f8b15;hb=d382f4e9175c1520835e41c3573471a84bcf1713;hp=48ba68a4aabfbdc6b77918221d8fa9a6768fd6dc;hpb=4ba3b8ea1be85d95a508ac479f26b96ceea15971;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 48ba68a4a..fa9a70d50 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -1,4 +1,5 @@ import * as Sequelize from 'sequelize' +import * as Bluebird from 'bluebird' import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONSTRAINTS_FIELDS } from '../../initializers' @@ -97,6 +98,15 @@ export class VideoShareModel extends Model { }) } + static loadByUrl (url: string, t: Sequelize.Transaction) { + return VideoShareModel.scope(ScopeNames.FULL).findOne({ + where: { + url + }, + transaction: t + }) + } + static loadActorsByShare (videoId: number, t: Sequelize.Transaction) { const query = { where: { @@ -115,7 +125,7 @@ export class VideoShareModel extends Model { .then(res => res.map(r => r.Actor)) } - static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction) { + static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction): Bluebird { const query = { attributes: [], include: [ @@ -152,4 +162,42 @@ export class VideoShareModel extends Model { return VideoShareModel.scope(ScopeNames.FULL).findAll(query) .then(res => res.map(r => r.Actor)) } + + static loadActorsByVideoChannel (videoChannelId: number, t: Sequelize.Transaction): Bluebird { + const query = { + attributes: [], + include: [ + { + model: ActorModel, + required: true + }, + { + attributes: [], + model: VideoModel, + required: true, + where: { + channelId: videoChannelId + } + } + ], + transaction: t + } + + return VideoShareModel.scope(ScopeNames.FULL) + .findAll(query) + .then(res => res.map(r => r.Actor)) + } + + static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Sequelize.Transaction) { + const query = { + offset: start, + limit: count, + where: { + videoId + }, + transaction: t + } + + return VideoShareModel.findAndCountAll(query) + } }