Fix RSS feed when HLS only is enabled
This commit is contained in:
parent
74055dc882
commit
97816649b7
4 changed files with 117 additions and 13 deletions
|
@ -59,7 +59,11 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor
|
|||
label: VideoModel.getPrivacyLabel(video.privacy)
|
||||
},
|
||||
nsfw: video.nsfw,
|
||||
description: options && options.completeDescription === true ? video.description : video.getTruncatedDescription(),
|
||||
|
||||
description: options && options.completeDescription === true
|
||||
? video.description
|
||||
: video.getTruncatedDescription(),
|
||||
|
||||
isLocal: video.isOwned(),
|
||||
duration: video.duration,
|
||||
views: video.views,
|
||||
|
|
|
@ -156,7 +156,16 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
|
|||
}
|
||||
|
||||
if (options.withFiles === true) {
|
||||
and.push('EXISTS (SELECT 1 FROM "videoFile" WHERE "videoFile"."videoId" = "video"."id")')
|
||||
and.push(
|
||||
'(' +
|
||||
' EXISTS (SELECT 1 FROM "videoFile" WHERE "videoFile"."videoId" = "video"."id") ' +
|
||||
' OR EXISTS (' +
|
||||
' SELECT 1 FROM "videoStreamingPlaylist" ' +
|
||||
' INNER JOIN "videoFile" ON "videoFile"."videoStreamingPlaylistId" = "videoStreamingPlaylist"."id" ' +
|
||||
' WHERE "videoStreamingPlaylist"."videoId" = "video"."id"' +
|
||||
' )' +
|
||||
')'
|
||||
)
|
||||
}
|
||||
|
||||
if (options.tagsOneOf) {
|
||||
|
@ -443,7 +452,13 @@ function wrapForAPIResults (baseQuery: string, replacements: any, options: Build
|
|||
]
|
||||
|
||||
if (options.withFiles) {
|
||||
joins.push('INNER JOIN "videoFile" AS "VideoFiles" ON "VideoFiles"."videoId" = "video"."id"')
|
||||
joins.push('LEFT JOIN "videoFile" AS "VideoFiles" ON "VideoFiles"."videoId" = "video"."id"')
|
||||
|
||||
joins.push('LEFT JOIN "videoStreamingPlaylist" AS "VideoStreamingPlaylists" ON "VideoStreamingPlaylists"."videoId" = "video"."id"')
|
||||
joins.push(
|
||||
'LEFT JOIN "videoFile" AS "VideoStreamingPlaylists->VideoFiles" ' +
|
||||
'ON "VideoStreamingPlaylists->VideoFiles"."videoStreamingPlaylistId" = "VideoStreamingPlaylists"."id"'
|
||||
)
|
||||
|
||||
Object.assign(attributes, {
|
||||
'"VideoFiles"."id"': '"VideoFiles.id"',
|
||||
|
@ -454,7 +469,18 @@ function wrapForAPIResults (baseQuery: string, replacements: any, options: Build
|
|||
'"VideoFiles"."extname"': '"VideoFiles.extname"',
|
||||
'"VideoFiles"."infoHash"': '"VideoFiles.infoHash"',
|
||||
'"VideoFiles"."fps"': '"VideoFiles.fps"',
|
||||
'"VideoFiles"."videoId"': '"VideoFiles.videoId"'
|
||||
'"VideoFiles"."videoId"': '"VideoFiles.videoId"',
|
||||
|
||||
'"VideoStreamingPlaylists"."id"': '"VideoStreamingPlaylists.id"',
|
||||
'"VideoStreamingPlaylists->VideoFiles"."id"': '"VideoStreamingPlaylists.VideoFiles.id"',
|
||||
'"VideoStreamingPlaylists->VideoFiles"."createdAt"': '"VideoStreamingPlaylists.VideoFiles.createdAt"',
|
||||
'"VideoStreamingPlaylists->VideoFiles"."updatedAt"': '"VideoStreamingPlaylists.VideoFiles.updatedAt"',
|
||||
'"VideoStreamingPlaylists->VideoFiles"."resolution"': '"VideoStreamingPlaylists.VideoFiles.resolution"',
|
||||
'"VideoStreamingPlaylists->VideoFiles"."size"': '"VideoStreamingPlaylists.VideoFiles.size"',
|
||||
'"VideoStreamingPlaylists->VideoFiles"."extname"': '"VideoStreamingPlaylists.VideoFiles.extname"',
|
||||
'"VideoStreamingPlaylists->VideoFiles"."infoHash"': '"VideoStreamingPlaylists.VideoFiles.infoHash"',
|
||||
'"VideoStreamingPlaylists->VideoFiles"."fps"': '"VideoStreamingPlaylists.VideoFiles.fps"',
|
||||
'"VideoStreamingPlaylists->VideoFiles"."videoId"': '"VideoStreamingPlaylists.VideoFiles.videoId"'
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ import {
|
|||
MVideoWithRights
|
||||
} from '../../types/models'
|
||||
import { MThumbnail } from '../../types/models/video/thumbnail'
|
||||
import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../types/models/video/video-file'
|
||||
import { MVideoFile, MVideoFileStreamingPlaylistVideo, MVideoFileRedundanciesOpt } from '../../types/models/video/video-file'
|
||||
import { VideoAbuseModel } from '../abuse/video-abuse'
|
||||
import { AccountModel } from '../account/account'
|
||||
import { AccountVideoRateModel } from '../account/account-video-rate'
|
||||
|
@ -127,6 +127,7 @@ import { VideoShareModel } from './video-share'
|
|||
import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
|
||||
import { VideoTagModel } from './video-tag'
|
||||
import { VideoViewModel } from './video-view'
|
||||
import { stream } from 'winston'
|
||||
|
||||
export enum ScopeNames {
|
||||
AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
|
||||
|
@ -1472,11 +1473,13 @@ export class VideoModel extends Model<VideoModel> {
|
|||
}
|
||||
|
||||
private static buildAPIResult (rows: any[]) {
|
||||
const memo: { [ id: number ]: VideoModel } = {}
|
||||
const videosMemo: { [ id: number ]: VideoModel } = {}
|
||||
const videoStreamingPlaylistMemo: { [ id: number ]: VideoStreamingPlaylistModel } = {}
|
||||
|
||||
const thumbnailsDone = new Set<number>()
|
||||
const historyDone = new Set<number>()
|
||||
const videoFilesDone = new Set<number>()
|
||||
const videoStreamingPlaylistsDone = new Set<number>()
|
||||
|
||||
const videos: VideoModel[] = []
|
||||
|
||||
|
@ -1484,6 +1487,7 @@ export class VideoModel extends Model<VideoModel> {
|
|||
const actorKeys = [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ]
|
||||
const serverKeys = [ 'id', 'host' ]
|
||||
const videoFileKeys = [ 'id', 'createdAt', 'updatedAt', 'resolution', 'size', 'extname', 'infoHash', 'fps', 'videoId' ]
|
||||
const videoStreamingPlaylistKeys = [ 'id' ]
|
||||
const videoKeys = [
|
||||
'id',
|
||||
'uuid',
|
||||
|
@ -1529,7 +1533,7 @@ export class VideoModel extends Model<VideoModel> {
|
|||
}
|
||||
|
||||
for (const row of rows) {
|
||||
if (!memo[row.id]) {
|
||||
if (!videosMemo[row.id]) {
|
||||
// Build Channel
|
||||
const channel = row.VideoChannel
|
||||
const channelModel = new VideoChannelModel(pick(channel, [ 'id', 'name', 'description', 'actorId' ]))
|
||||
|
@ -1547,13 +1551,14 @@ export class VideoModel extends Model<VideoModel> {
|
|||
videoModel.UserVideoHistories = []
|
||||
videoModel.Thumbnails = []
|
||||
videoModel.VideoFiles = []
|
||||
videoModel.VideoStreamingPlaylists = []
|
||||
|
||||
memo[row.id] = videoModel
|
||||
videosMemo[row.id] = videoModel
|
||||
// Don't take object value to have a sorted array
|
||||
videos.push(videoModel)
|
||||
}
|
||||
|
||||
const videoModel = memo[row.id]
|
||||
const videoModel = videosMemo[row.id]
|
||||
|
||||
if (row.userVideoHistory?.id && !historyDone.has(row.userVideoHistory.id)) {
|
||||
const historyModel = new UserVideoHistoryModel(pick(row.userVideoHistory, [ 'id', 'currentTime' ]))
|
||||
|
@ -1575,6 +1580,31 @@ export class VideoModel extends Model<VideoModel> {
|
|||
|
||||
videoFilesDone.add(row.VideoFiles.id)
|
||||
}
|
||||
|
||||
if (row.VideoFiles?.id && !videoFilesDone.has(row.VideoFiles.id)) {
|
||||
const videoFileModel = new VideoFileModel(pick(row.VideoFiles, videoFileKeys))
|
||||
videoModel.VideoFiles.push(videoFileModel)
|
||||
|
||||
videoFilesDone.add(row.VideoFiles.id)
|
||||
}
|
||||
|
||||
if (row.VideoStreamingPlaylists?.id && !videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) {
|
||||
const streamingPlaylist = new VideoStreamingPlaylistModel(pick(row.VideoStreamingPlaylists, videoStreamingPlaylistKeys))
|
||||
streamingPlaylist.VideoFiles = []
|
||||
|
||||
videoModel.VideoStreamingPlaylists.push(streamingPlaylist)
|
||||
|
||||
videoStreamingPlaylistMemo[streamingPlaylist.id] = streamingPlaylist
|
||||
}
|
||||
|
||||
if (row.VideoStreamingPlaylists?.VideoFiles?.id && !videoFilesDone.has(row.VideoStreamingPlaylists.VideoFiles.id)) {
|
||||
const streamingPlaylist = videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]
|
||||
|
||||
const videoFileModel = new VideoFileModel(pick(row.VideoStreamingPlaylists.VideoFiles, videoFileKeys))
|
||||
streamingPlaylist.VideoFiles.push(videoFileModel)
|
||||
|
||||
videoFilesDone.add(row.VideoStreamingPlaylists.VideoFiles.id)
|
||||
}
|
||||
}
|
||||
|
||||
return videos
|
||||
|
@ -1717,7 +1747,21 @@ export class VideoModel extends Model<VideoModel> {
|
|||
|
||||
getFormattedVideoFilesJSON (): VideoFile[] {
|
||||
const { baseUrlHttp, baseUrlWs } = this.getBaseUrls()
|
||||
return videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, this.VideoFiles)
|
||||
let files: MVideoFileRedundanciesOpt[] = []
|
||||
|
||||
logger.info('coucou', { files })
|
||||
|
||||
if (Array.isArray(this.VideoFiles)) {
|
||||
files = files.concat(this.VideoFiles)
|
||||
}
|
||||
|
||||
for (const p of (this.VideoStreamingPlaylists || [])) {
|
||||
files = files.concat(p.VideoFiles || [])
|
||||
}
|
||||
|
||||
logger.info('coucou', { files, video: this.VideoStreamingPlaylists })
|
||||
|
||||
return videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, files)
|
||||
}
|
||||
|
||||
toActivityPubObject (this: MVideoAP): VideoTorrentObject {
|
||||
|
|
|
@ -21,7 +21,8 @@ import {
|
|||
setAccessTokensToServers,
|
||||
uploadVideo,
|
||||
uploadVideoAndGetId,
|
||||
userLogin
|
||||
userLogin,
|
||||
flushAndRunServer
|
||||
} from '../../../shared/extra-utils'
|
||||
import { waitJobs } from '../../../shared/extra-utils/server/jobs'
|
||||
import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
|
||||
|
@ -34,6 +35,7 @@ const expect = chai.expect
|
|||
|
||||
describe('Test syndication feeds', () => {
|
||||
let servers: ServerInfo[] = []
|
||||
let serverHLSOnly: ServerInfo
|
||||
let userAccessToken: string
|
||||
let rootAccountId: number
|
||||
let rootChannelId: number
|
||||
|
@ -45,8 +47,15 @@ describe('Test syndication feeds', () => {
|
|||
|
||||
// Run servers
|
||||
servers = await flushAndRunMultipleServers(2)
|
||||
serverHLSOnly = await flushAndRunServer(3, {
|
||||
transcoding: {
|
||||
enabled: true,
|
||||
webtorrent: { enabled: false },
|
||||
hls: { enabled: true }
|
||||
}
|
||||
})
|
||||
|
||||
await setAccessTokensToServers(servers)
|
||||
await setAccessTokensToServers([ ...servers, serverHLSOnly ])
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
|
||||
{
|
||||
|
@ -116,6 +125,7 @@ describe('Test syndication feeds', () => {
|
|||
})
|
||||
|
||||
describe('Videos feed', function () {
|
||||
|
||||
it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
|
||||
for (const server of servers) {
|
||||
const rss = await getXMLfeed(server.url, 'videos')
|
||||
|
@ -208,6 +218,26 @@ describe('Test syndication feeds', () => {
|
|||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('Should correctly have videos feed with HLS only', async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
await uploadVideo(serverHLSOnly.url, serverHLSOnly.accessToken, { name: 'hls only video' })
|
||||
|
||||
await waitJobs([ serverHLSOnly ])
|
||||
|
||||
const json = await getJSONfeed(serverHLSOnly.url, 'videos')
|
||||
const jsonObj = JSON.parse(json.text)
|
||||
expect(jsonObj.items.length).to.be.equal(1)
|
||||
expect(jsonObj.items[0].attachments).to.exist
|
||||
expect(jsonObj.items[0].attachments.length).to.be.eq(4)
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
expect(jsonObj.items[0].attachments[i].mime_type).to.be.eq('application/x-bittorrent')
|
||||
expect(jsonObj.items[0].attachments[i].size_in_bytes).to.be.greaterThan(0)
|
||||
expect(jsonObj.items[0].attachments[i].url).to.exist
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('Video comments feed', function () {
|
||||
|
@ -260,6 +290,6 @@ describe('Test syndication feeds', () => {
|
|||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests(servers)
|
||||
await cleanupTests([ ...servers, serverHLSOnly ])
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue