Skip to content

Commit

Permalink
Fix video file storage attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Aug 20, 2024
1 parent 27bf922 commit 1870626
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
20 changes: 12 additions & 8 deletions packages/tests/src/shared/streaming-playlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions packages/tests/src/shared/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

{
Expand Down
6 changes: 4 additions & 2 deletions server/core/models/video/formatter/video-api-format.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getResolutionLabel } from '@peertube/peertube-core-utils'
import {
Video,
VideoAdditionalAttributes,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -260,7 +260,9 @@ export function videoFilesModelToFormattedJSON (
hasAudio: videoFile.hasAudio(),
hasVideo: videoFile.hasVideo(),

storage: videoFile.storage
storage: video.remote
? null
: videoFile.storage
}
})
}
Expand Down

0 comments on commit 1870626

Please sign in to comment.