import { registerTSPaths } from '../server/helpers/register-ts-paths'
+registerTSPaths()
+
import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
import { getMaxBitrate } from '../shared/models/videos'
import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
import { getVideoFilePath } from '@server/lib/video-paths'
-registerTSPaths()
-
run()
.then(() => process.exit(0))
.catch(err => {
type AvatarInfo = { name: string, onDisk: boolean, fileUrl: string }
async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo, t: Transaction) {
- if (info.name !== undefined) {
- if (actor.avatarId) {
- try {
- await actor.Avatar.destroy({ transaction: t })
- } catch (err) {
- logger.error('Cannot remove old avatar of actor %s.', actor.url, { err })
- }
- }
+ if (!info.name) return actor
- const avatar = await AvatarModel.create({
- filename: info.name,
- onDisk: info.onDisk,
- fileUrl: info.fileUrl
- }, { transaction: t })
+ if (actor.Avatar) {
+ // Don't update the avatar if the filename did not change
+ if (actor.Avatar.filename === info.name) return actor
- actor.avatarId = avatar.id
- actor.Avatar = avatar
+ try {
+ await actor.Avatar.destroy({ transaction: t })
+ } catch (err) {
+ logger.error('Cannot remove old avatar of actor %s.', actor.url, { err })
+ }
}
+ const avatar = await AvatarModel.create({
+ filename: info.name,
+ onDisk: info.onDisk,
+ fileUrl: info.fileUrl
+ }, { transaction: t })
+
+ actor.avatarId = avatar.id
+ actor.Avatar = avatar
+
return actor
}
import { downloadPlaylistSegments } from '../hls'
import { CONFIG } from '../../initializers/config'
import {
- MStreamingPlaylist,
+ MStreamingPlaylist, MStreamingPlaylistFiles,
MStreamingPlaylistVideo,
MVideoAccountLight,
MVideoFile,
redundancy: VideosRedundancy,
video: MVideoWithAllFiles,
files: MVideoFile[],
- streamingPlaylists: MStreamingPlaylist[]
+ streamingPlaylists: MStreamingPlaylistFiles[]
}
function isMVideoRedundancyFileVideo (
logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy)
const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
- const magnetUri = await generateMagnetUri(video, file, baseUrlHttp, baseUrlWs)
+ const magnetUri = generateMagnetUri(video, file, baseUrlHttp, baseUrlWs)
const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT)
return `${object.VideoStreamingPlaylist.playlistUrl}`
}
- private getTotalFileSizes (files: MVideoFile[], playlists: MStreamingPlaylist[]) {
+ private getTotalFileSizes (files: MVideoFile[], playlists: MStreamingPlaylistFiles[]) {
const fileReducer = (previous: number, current: MVideoFile) => previous + current.size
- const totalSize = files.reduce(fileReducer, 0)
+ let allFiles = files
+ for (const p of playlists) {
+ allFiles = allFiles.concat(p.VideoFiles)
+ }
- return totalSize + (totalSize * playlists.length)
+ return allFiles.reduce(fileReducer, 0)
}
private async loadAndRefreshVideo (videoUrl: string) {
-import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/typings/models'
+import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/typings/models'
import { extractVideo } from './videos'
import { join } from 'path'
import { CONFIG } from '@server/initializers/config'
-import { HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
+import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
// ################## Video file name ##################
return join(baseDir, getVideoFilename(videoOrPlaylist, videoFile))
}
+// ################## Streaming playlist ##################
+
+function getHLSDirectory (video: MVideoUUID, isRedundancy = false) {
+ const baseDir = isRedundancy ? HLS_REDUNDANCY_DIRECTORY : HLS_STREAMING_PLAYLIST_DIRECTORY
+
+ return join(baseDir, video.uuid)
+}
+
// ################## Torrents ##################
function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
getVideoFilePath,
getTorrentFileName,
- getTorrentFilePath
+ getTorrentFilePath,
+
+ getHLSDirectory
}
import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
import { MThumbnail } from '../../typings/models/video/thumbnail'
import { VideoFile } from '@shared/models/videos/video-file.model'
-import { getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
+import { getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath, getHLSDirectory } from '@server/lib/video-paths'
// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [
}
removeStreamingPlaylist (isRedundancy = false) {
- const baseDir = isRedundancy ? HLS_REDUNDANCY_DIRECTORY : HLS_STREAMING_PLAYLIST_DIRECTORY
+ const directoryPath = getHLSDirectory(this, isRedundancy)
- const filePath = join(baseDir, this.uuid)
- return remove(filePath)
- .catch(err => logger.warn('Cannot delete playlist directory %s.', filePath, { err }))
+ return remove(directoryPath)
+ .catch(err => logger.warn('Cannot delete playlist directory %s.', directoryPath, { err }))
}
isOutdated () {
await reRunServer(servers[ 1 ])
- // Should not refresh the video, even if the last refresh failed (to avoir a loop on dead instances)
+ // Should not refresh the video, even if the last refresh failed (to avoid a loop on dead instances)
await getVideo(servers[ 0 ].url, videoUUID3)
await waitJobs(servers)
execCLI,
flushAndRunMultipleServers,
getAccount,
- getEnvCli,
+ getEnvCli, makeGetRequest, makeRawRequest,
ServerInfo,
setAccessTokensToServers, setDefaultVideoChannel,
updateMyAvatar,
expect(videosCount).to.equal(8)
const torrentsCount = await countFiles(server.internalServerNumber, 'torrents')
- expect(torrentsCount).to.equal(8)
+ expect(torrentsCount).to.equal(16)
const previewsCount = await countFiles(server.internalServerNumber, 'previews')
expect(previewsCount).to.equal(2)
{
const res = await getAccount(servers[ 0 ].url, 'root@localhost:' + servers[ 1 ].port)
const account: Account = res.body
- await request('http://localhost:' + servers[ 0 ].port).get(account.avatar.path).expect(200)
+ await makeGetRequest({
+ url: servers[ 0 ].url,
+ path: account.avatar.path,
+ statusCodeExpected: 200
+ })
}
{
const res = await getAccount(servers[ 1 ].url, 'root@localhost:' + servers[ 0 ].port)
const account: Account = res.body
- await request('http://localhost:' + servers[ 1 ].port).get(account.avatar.path).expect(200)
+ await makeGetRequest({
+ url: servers[ 1 ].url,
+ path: account.avatar.path,
+ statusCodeExpected: 200
+ })
}
await wait(1000)