Fix hooks definition
This commit is contained in:
parent
693c6586cb
commit
06c2759338
7 changed files with 35 additions and 13 deletions
|
@ -22,7 +22,9 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
|
||||||
|
|
||||||
// Send to origin
|
// Send to origin
|
||||||
if (video.isOwned() === false) {
|
if (video.isOwned() === false) {
|
||||||
const accountActor = (video as MVideoAccountLight).VideoChannel?.Account?.Actor || await ActorModel.loadAccountActorByVideoId(video.id)
|
let accountActor: MActorLight = (video as MVideoAccountLight).VideoChannel?.Account?.Actor
|
||||||
|
|
||||||
|
if (!accountActor) accountActor = await ActorModel.loadAccountActorByVideoId(video.id, transaction)
|
||||||
|
|
||||||
const audience = getRemoteVideoAudience(accountActor, actorsInvolvedInVideo)
|
const audience = getRemoteVideoAudience(accountActor, actorsInvolvedInVideo)
|
||||||
const activity = activityBuilder(audience)
|
const activity = activityBuilder(audience)
|
||||||
|
|
|
@ -496,7 +496,7 @@ export class ActorModel extends Model<Partial<AttributesOnly<ActorModel>>> {
|
||||||
}, { where, transaction })
|
}, { where, transaction })
|
||||||
}
|
}
|
||||||
|
|
||||||
static loadAccountActorByVideoId (videoId: number): Promise<MActor> {
|
static loadAccountActorByVideoId (videoId: number, transaction: Transaction): Promise<MActor> {
|
||||||
const query = {
|
const query = {
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
|
@ -520,7 +520,8 @@ export class ActorModel extends Model<Partial<AttributesOnly<ActorModel>>> {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
transaction
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActorModel.unscoped().findOne(query)
|
return ActorModel.unscoped().findOne(query)
|
||||||
|
|
|
@ -291,8 +291,7 @@ export class VideoChannelModel extends Model<Partial<AttributesOnly<VideoChannel
|
||||||
@BelongsTo(() => AccountModel, {
|
@BelongsTo(() => AccountModel, {
|
||||||
foreignKey: {
|
foreignKey: {
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
}
|
||||||
hooks: true
|
|
||||||
})
|
})
|
||||||
Account: AccountModel
|
Account: AccountModel
|
||||||
|
|
||||||
|
|
|
@ -572,7 +572,6 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
|
||||||
foreignKey: {
|
foreignKey: {
|
||||||
allowNull: true
|
allowNull: true
|
||||||
},
|
},
|
||||||
hooks: true,
|
|
||||||
onDelete: 'cascade'
|
onDelete: 'cascade'
|
||||||
})
|
})
|
||||||
VideoChannel: VideoChannelModel
|
VideoChannel: VideoChannelModel
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { HttpStatusCode } from '@shared/core-utils'
|
||||||
import {
|
import {
|
||||||
buildAbsoluteFixturePath,
|
buildAbsoluteFixturePath,
|
||||||
buildServerDirectory,
|
buildServerDirectory,
|
||||||
|
cleanupTests,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
getMyUserInformation,
|
getMyUserInformation,
|
||||||
prepareResumableUpload,
|
prepareResumableUpload,
|
||||||
|
@ -184,4 +185,7 @@ describe('Test resumable upload', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
await cleanupTests([ server ])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
getVideoChannel,
|
getVideoChannel,
|
||||||
getVideoChannelVideos,
|
getVideoChannelVideos,
|
||||||
setDefaultVideoChannel,
|
setDefaultVideoChannel,
|
||||||
|
testFileExistsOrNot,
|
||||||
testImage,
|
testImage,
|
||||||
updateVideo,
|
updateVideo,
|
||||||
updateVideoChannelImage,
|
updateVideoChannelImage,
|
||||||
|
@ -53,6 +54,9 @@ describe('Test video channels', function () {
|
||||||
let videoUUID: string
|
let videoUUID: string
|
||||||
let accountName: string
|
let accountName: string
|
||||||
|
|
||||||
|
const avatarPaths: { [ port: number ]: string } = {}
|
||||||
|
const bannerPaths: { [ port: number ]: string } = {}
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(60000)
|
this.timeout(60000)
|
||||||
|
|
||||||
|
@ -287,9 +291,11 @@ describe('Test video channels', function () {
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const videoChannel = await findChannel(server, secondVideoChannelId)
|
const videoChannel = await findChannel(server, secondVideoChannelId)
|
||||||
|
|
||||||
await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
|
avatarPaths[server.port] = videoChannel.avatar.path
|
||||||
|
await testImage(server.url, 'avatar-resized', avatarPaths[server.port], '.png')
|
||||||
|
await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true)
|
||||||
|
|
||||||
const row = await getActorImage(server.internalServerNumber, basename(videoChannel.avatar.path))
|
const row = await getActorImage(server.internalServerNumber, basename(avatarPaths[server.port]))
|
||||||
expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height)
|
expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height)
|
||||||
expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width)
|
expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width)
|
||||||
}
|
}
|
||||||
|
@ -314,9 +320,11 @@ describe('Test video channels', function () {
|
||||||
const res = await getVideoChannel(server.url, 'second_video_channel@' + servers[0].host)
|
const res = await getVideoChannel(server.url, 'second_video_channel@' + servers[0].host)
|
||||||
const videoChannel = res.body
|
const videoChannel = res.body
|
||||||
|
|
||||||
await testImage(server.url, 'banner-resized', videoChannel.banner.path)
|
bannerPaths[server.port] = videoChannel.banner.path
|
||||||
|
await testImage(server.url, 'banner-resized', bannerPaths[server.port])
|
||||||
|
await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true)
|
||||||
|
|
||||||
const row = await getActorImage(server.internalServerNumber, basename(videoChannel.banner.path))
|
const row = await getActorImage(server.internalServerNumber, basename(bannerPaths[server.port]))
|
||||||
expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height)
|
expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height)
|
||||||
expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width)
|
expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width)
|
||||||
}
|
}
|
||||||
|
@ -336,6 +344,7 @@ describe('Test video channels', function () {
|
||||||
|
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const videoChannel = await findChannel(server, secondVideoChannelId)
|
const videoChannel = await findChannel(server, secondVideoChannelId)
|
||||||
|
await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), false)
|
||||||
|
|
||||||
expect(videoChannel.avatar).to.be.null
|
expect(videoChannel.avatar).to.be.null
|
||||||
}
|
}
|
||||||
|
@ -355,6 +364,7 @@ describe('Test video channels', function () {
|
||||||
|
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const videoChannel = await findChannel(server, secondVideoChannelId)
|
const videoChannel = await findChannel(server, secondVideoChannelId)
|
||||||
|
await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), false)
|
||||||
|
|
||||||
expect(videoChannel.banner).to.be.null
|
expect(videoChannel.banner).to.be.null
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import * as ffmpeg from 'fluent-ffmpeg'
|
import * as ffmpeg from 'fluent-ffmpeg'
|
||||||
import { ensureDir, pathExists, readFile, stat } from 'fs-extra'
|
import { ensureDir, exists, pathExists, readFile, stat } from 'fs-extra'
|
||||||
import { basename, dirname, isAbsolute, join, resolve } from 'path'
|
import { basename, dirname, isAbsolute, join, resolve } from 'path'
|
||||||
import * as request from 'supertest'
|
import * as request from 'supertest'
|
||||||
import * as WebTorrent from 'webtorrent'
|
import * as WebTorrent from 'webtorrent'
|
||||||
|
@ -60,8 +60,14 @@ async function testImage (url: string, imageName: string, imagePath: string, ext
|
||||||
const minLength = body.length - ((30 * body.length) / 100)
|
const minLength = body.length - ((30 * body.length) / 100)
|
||||||
const maxLength = body.length + ((30 * body.length) / 100)
|
const maxLength = body.length + ((30 * body.length) / 100)
|
||||||
|
|
||||||
expect(data.length).to.be.above(minLength, "the generated image is way smaller than the recorded fixture")
|
expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture')
|
||||||
expect(data.length).to.be.below(maxLength, "the generated image is way larger than the recorded fixture")
|
expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testFileExistsOrNot (server: { internalServerNumber: number }, directory: string, filePath: string, exist: boolean) {
|
||||||
|
const base = buildServerDirectory(server, directory)
|
||||||
|
|
||||||
|
expect(await pathExists(join(base, filePath))).to.equal(exist)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isGithubCI () {
|
function isGithubCI () {
|
||||||
|
@ -157,6 +163,7 @@ export {
|
||||||
testImage,
|
testImage,
|
||||||
isGithubCI,
|
isGithubCI,
|
||||||
buildAbsoluteFixturePath,
|
buildAbsoluteFixturePath,
|
||||||
|
testFileExistsOrNot,
|
||||||
root,
|
root,
|
||||||
generateHighBitrateVideo,
|
generateHighBitrateVideo,
|
||||||
generateVideoWithFramerate
|
generateVideoWithFramerate
|
||||||
|
|
Loading…
Reference in a new issue