From 1870626af5a0d1c61364308c30ef7e35df197653 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Aug 2024 09:05:53 +0200 Subject: [PATCH] Fix video file storage attribute --- .../tests/src/shared/streaming-playlists.ts | 20 +++++++++++-------- packages/tests/src/shared/videos.ts | 10 +++++++--- .../video/formatter/video-api-format.ts | 6 ++++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/tests/src/shared/streaming-playlists.ts b/packages/tests/src/shared/streaming-playlists.ts index edc869727..35229db86 100644 --- a/packages/tests/src/shared/streaming-playlists.ts +++ b/packages/tests/src/shared/streaming-playlists.ts @@ -190,6 +190,8 @@ export async function completeCheckHlsPlaylist (options: { for (const server of options.servers) { const videoDetails = await server.videos.getWithToken({ id: videoUUID }) + const isOrigin = videoDetails.account.host === server.host + const requiresAuth = videoDetails.privacy.id === VideoPrivacy.PRIVATE || videoDetails.privacy.id === VideoPrivacy.INTERNAL const privatePath = requiresAuth @@ -221,25 +223,27 @@ export async function completeCheckHlsPlaylist (options: { expect(file.resolution.label).to.equal('Audio only') expect(file.hasAudio).to.be.true expect(file.hasVideo).to.be.false + + expect(file.height).to.equal(0) + expect(file.width).to.equal(0) } else { expect(file.resolution.label).to.equal(resolution + 'p') expect(file.hasVideo).to.be.true expect(file.hasAudio).to.equal(hasAudio && !splittedAudio) - } - if (resolution === 0) { - expect(file.height).to.equal(0) - expect(file.width).to.equal(0) - } else { expect(Math.min(file.height, file.width)).to.equal(resolution) expect(Math.max(file.height, file.width)).to.be.greaterThan(resolution) } - if (objectStorageBaseUrl) { - expect(file.storage).to.equal(FileStorage.OBJECT_STORAGE) + if (isOrigin) { + if (objectStorageBaseUrl) { + expect(file.storage).to.equal(FileStorage.OBJECT_STORAGE) + } else { + expect(file.storage).to.equal(FileStorage.FILE_SYSTEM) + } } else { - expect(file.storage).to.equal(FileStorage.FILE_SYSTEM) + expect(file.storage).to.be.null } expect(file.magnetUri).to.have.lengthOf.above(2) diff --git a/packages/tests/src/shared/videos.ts b/packages/tests/src/shared/videos.ts index f707d7954..723e169bd 100644 --- a/packages/tests/src/shared/videos.ts +++ b/packages/tests/src/shared/videos.ts @@ -64,10 +64,14 @@ export async function completeWebVideoFilesCheck (options: { expect(file.id).to.exist expect(file.magnetUri).to.have.lengthOf.above(2) - if (objectStorageBaseUrl) { - expect(file.storage).to.equal(FileStorage.OBJECT_STORAGE) + if (server.internalServerNumber === originServer.internalServerNumber) { + if (objectStorageBaseUrl) { + expect(file.storage).to.equal(FileStorage.OBJECT_STORAGE) + } else { + expect(file.storage).to.equal(FileStorage.FILE_SYSTEM) + } } else { - expect(file.storage).to.equal(FileStorage.FILE_SYSTEM) + expect(file.storage).to.be.null } { diff --git a/server/core/models/video/formatter/video-api-format.ts b/server/core/models/video/formatter/video-api-format.ts index e12c2b0fe..b95b7565e 100644 --- a/server/core/models/video/formatter/video-api-format.ts +++ b/server/core/models/video/formatter/video-api-format.ts @@ -1,3 +1,4 @@ +import { getResolutionLabel } from '@peertube/peertube-core-utils' import { Video, VideoAdditionalAttributes, @@ -25,7 +26,6 @@ import { import { MServer, MStreamingPlaylistRedundanciesOpt, MVideoFormattable, MVideoFormattableDetails } from '../../../types/models/index.js' import { MVideoFileRedundanciesOpt } from '../../../types/models/video/video-file.js' import { sortByResolutionDesc } from './shared/index.js' -import { getResolutionLabel } from '@peertube/peertube-core-utils' export type VideoFormattingJSONOptions = { completeDescription?: boolean @@ -260,7 +260,9 @@ export function videoFilesModelToFormattedJSON ( hasAudio: videoFile.hasAudio(), hasVideo: videoFile.hasVideo(), - storage: videoFile.storage + storage: video.remote + ? null + : videoFile.storage } }) }