import { AccountModel } from '../account/account'
import { AccountVideoRateModel } from '../account/account-video-rate'
import { ActorModel } from '../activitypub/actor'
-import { ActorFollowModel } from '../activitypub/actor-follow'
import { ServerModel } from '../server/server'
import { getSort, throwIfNotValid } from '../utils'
import { TagModel } from './tag'
@Scopes({
[ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number) => ({
- subQuery: false,
where: {
id: {
[Sequelize.Op.notIn]: Sequelize.literal(
'(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")'
+ ),
+ [ Sequelize.Op.in ]: Sequelize.literal(
+ '(' +
+ 'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' +
+ 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
+ 'WHERE "actorFollow"."actorId" = ' + parseInt(actorId.toString(), 10) +
+ ' UNION ' +
+ 'SELECT "video"."id" AS "id" FROM "video" ' +
+ 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
+ 'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' +
+ 'INNER JOIN "actor" ON "account"."actorId" = "actor"."id" ' +
+ 'LEFT JOIN "actorFollow" ON "actorFollow"."targetActorId" = "actor"."id" ' +
+ 'WHERE "actor"."serverId" IS NULL OR "actorFollow"."actorId" = ' + parseInt(actorId.toString(), 10) +
+ ')'
)
},
- privacy: VideoPrivacy.PUBLIC,
- [Sequelize.Op.or]: [
- {
- '$VideoChannel.Account.Actor.serverId$': null
- },
- {
- '$VideoChannel.Account.Actor.followers.actorId$': actorId
- },
- {
- id: {
- [ Sequelize.Op.in ]: Sequelize.literal(
- '(' +
- 'SELECT "videoShare"."videoId" FROM "videoShare" ' +
- 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
- 'WHERE "actorFollow"."actorId" = ' + parseInt(actorId.toString(), 10) +
- ')'
- )
- }
- }
- ]
+ privacy: VideoPrivacy.PUBLIC
},
include: [
{
include: [
{
attributes: [ 'host' ],
- model: ServerModel.unscoped(),
- required: false
- },
- {
- attributes: [ ],
- model: ActorFollowModel.unscoped(),
- as: 'followers',
- required: false
+ model: ServerModel.unscoped()
}
]
}
attributes: {
exclude: [ 'privateKey', 'publicKey' ]
},
- model: () => ActorModel,
- required: true
+ model: () => ActorModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [ 'host' ],
+ model: () => ServerModel.unscoped(),
+ required: false
+ }
+ ]
},
{
- model: () => AccountModel,
+ model: () => AccountModel.unscoped(),
required: true,
include: [
{
- model: () => ActorModel,
+ model: () => ActorModel.unscoped(),
attributes: {
exclude: [ 'privateKey', 'publicKey' ]
},
required: true,
include: [
{
- model: () => ServerModel,
+ attributes: [ 'host' ],
+ model: () => ServerModel.unscoped(),
required: false
}
]
},
include: [
{
- model: VideoShareModel,
+ attributes: [ 'id' ],
+ model: VideoShareModel.unscoped(),
required: false,
where: {
[Sequelize.Op.and]: [
},
include: [
{
- model: ActorModel,
- required: true
+ attributes: [ 'id', 'url' ],
+ model: ActorModel.unscoped()
}
]
},
{
- model: VideoChannelModel,
+ model: VideoChannelModel.unscoped(),
required: true,
include: [
{
- model: AccountModel,
+ attributes: [ 'name' ],
+ model: AccountModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [ 'id', 'url' ],
+ model: ActorModel.unscoped(),
+ required: true
+ }
+ ]
+ },
+ {
+ attributes: [ 'id', 'url' ],
+ model: ActorModel.unscoped(),
required: true
}
]
},
{
+ attributes: [ 'type' ],
model: AccountVideoRateModel,
- include: [ AccountModel ]
+ required: false,
+ include: [
+ {
+ attributes: [ 'id' ],
+ model: AccountModel.unscoped(),
+ include: [
+ {
+ attributes: [ 'url' ],
+ model: ActorModel.unscoped(),
+ include: [
+ {
+ attributes: [ 'host' ],
+ model: ServerModel,
+ required: false
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ {
+ attributes: [ 'url' ],
+ model: VideoCommentModel,
+ required: false
},
VideoFileModel,
- TagModel,
- VideoCommentModel
+ TagModel
]
}
createTorrentAndSetInfoHash = async function (videoFile: VideoFileModel) {
const options = {
announceList: [
- [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ]
+ [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ],
+ [ CONFIG.WEBSERVER.URL + '/tracker/announce' ]
],
urlList: [
CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)