diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts index db0e91b71..7cd8030e1 100644 --- a/server/lib/activitypub/send/utils.ts +++ b/server/lib/activitypub/send/utils.ts @@ -22,7 +22,9 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud // Send to origin 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 activity = activityBuilder(audience) diff --git a/server/models/actor/actor.ts b/server/models/actor/actor.ts index 0cd30f545..8df49951d 100644 --- a/server/models/actor/actor.ts +++ b/server/models/actor/actor.ts @@ -496,7 +496,7 @@ export class ActorModel extends Model>> { }, { where, transaction }) } - static loadAccountActorByVideoId (videoId: number): Promise { + static loadAccountActorByVideoId (videoId: number, transaction: Transaction): Promise { const query = { include: [ { @@ -520,7 +520,8 @@ export class ActorModel extends Model>> { } ] } - ] + ], + transaction } return ActorModel.unscoped().findOne(query) diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index f84b85290..183e7448c 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -291,8 +291,7 @@ export class VideoChannelModel extends Model AccountModel, { foreignKey: { allowNull: false - }, - hooks: true + } }) Account: AccountModel diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 7a9e96210..1e5648a36 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -572,7 +572,6 @@ export class VideoModel extends Model>> { foreignKey: { allowNull: true }, - hooks: true, onDelete: 'cascade' }) VideoChannel: VideoChannelModel diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index af9221c43..4fc3317df 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -8,6 +8,7 @@ import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, buildServerDirectory, + cleanupTests, flushAndRunServer, getMyUserInformation, prepareResumableUpload, @@ -184,4 +185,7 @@ describe('Test resumable upload', function () { }) }) + after(async function () { + await cleanupTests([ server ]) + }) }) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 7e7ad028c..865098777 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -15,6 +15,7 @@ import { getVideoChannel, getVideoChannelVideos, setDefaultVideoChannel, + testFileExistsOrNot, testImage, updateVideo, updateVideoChannelImage, @@ -53,6 +54,9 @@ describe('Test video channels', function () { let videoUUID: string let accountName: string + const avatarPaths: { [ port: number ]: string } = {} + const bannerPaths: { [ port: number ]: string } = {} + before(async function () { this.timeout(60000) @@ -287,9 +291,11 @@ describe('Test video channels', function () { for (const server of servers) { 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.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 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.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width) } @@ -336,6 +344,7 @@ describe('Test video channels', function () { for (const server of servers) { const videoChannel = await findChannel(server, secondVideoChannelId) + await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), false) expect(videoChannel.avatar).to.be.null } @@ -355,6 +364,7 @@ describe('Test video channels', function () { for (const server of servers) { const videoChannel = await findChannel(server, secondVideoChannelId) + await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), false) expect(videoChannel.banner).to.be.null } diff --git a/shared/extra-utils/miscs/miscs.ts b/shared/extra-utils/miscs/miscs.ts index 1cb1cf440..f20be8585 100644 --- a/shared/extra-utils/miscs/miscs.ts +++ b/shared/extra-utils/miscs/miscs.ts @@ -2,7 +2,7 @@ import * as chai from 'chai' 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 * as request from 'supertest' 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 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.below(maxLength, "the generated image is way larger 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') +} + +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 () { @@ -157,6 +163,7 @@ export { testImage, isGithubCI, buildAbsoluteFixturePath, + testFileExistsOrNot, root, generateHighBitrateVideo, generateVideoWithFramerate