mirror of https://github.com/Chocobozzz/PeerTube
Don't always replace actor avatar
parent
d7a25329f9
commit
66fb2aa39b
|
@ -1,4 +1,6 @@
|
||||||
import { registerTSPaths } from '../server/helpers/register-ts-paths'
|
import { registerTSPaths } from '../server/helpers/register-ts-paths'
|
||||||
|
registerTSPaths()
|
||||||
|
|
||||||
import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
|
import { VIDEO_TRANSCODING_FPS } from '../server/initializers/constants'
|
||||||
import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
|
import { getDurationFromVideoFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../server/helpers/ffmpeg-utils'
|
||||||
import { getMaxBitrate } from '../shared/models/videos'
|
import { getMaxBitrate } from '../shared/models/videos'
|
||||||
|
@ -10,8 +12,6 @@ import { copy, move, remove } from 'fs-extra'
|
||||||
import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
|
import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
|
||||||
import { getVideoFilePath } from '@server/lib/video-paths'
|
import { getVideoFilePath } from '@server/lib/video-paths'
|
||||||
|
|
||||||
registerTSPaths()
|
|
||||||
|
|
||||||
run()
|
run()
|
||||||
.then(() => process.exit(0))
|
.then(() => process.exit(0))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
|
@ -173,8 +173,12 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ
|
||||||
|
|
||||||
type AvatarInfo = { name: string, onDisk: boolean, fileUrl: string }
|
type AvatarInfo = { name: string, onDisk: boolean, fileUrl: string }
|
||||||
async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo, t: Transaction) {
|
async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo, t: Transaction) {
|
||||||
if (info.name !== undefined) {
|
if (!info.name) return actor
|
||||||
if (actor.avatarId) {
|
|
||||||
|
if (actor.Avatar) {
|
||||||
|
// Don't update the avatar if the filename did not change
|
||||||
|
if (actor.Avatar.filename === info.name) return actor
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await actor.Avatar.destroy({ transaction: t })
|
await actor.Avatar.destroy({ transaction: t })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -190,7 +194,6 @@ async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo
|
||||||
|
|
||||||
actor.avatarId = avatar.id
|
actor.avatarId = avatar.id
|
||||||
actor.Avatar = avatar
|
actor.Avatar = avatar
|
||||||
}
|
|
||||||
|
|
||||||
return actor
|
return actor
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '../activitypub'
|
||||||
import { downloadPlaylistSegments } from '../hls'
|
import { downloadPlaylistSegments } from '../hls'
|
||||||
import { CONFIG } from '../../initializers/config'
|
import { CONFIG } from '../../initializers/config'
|
||||||
import {
|
import {
|
||||||
MStreamingPlaylist,
|
MStreamingPlaylist, MStreamingPlaylistFiles,
|
||||||
MStreamingPlaylistVideo,
|
MStreamingPlaylistVideo,
|
||||||
MVideoAccountLight,
|
MVideoAccountLight,
|
||||||
MVideoFile,
|
MVideoFile,
|
||||||
|
@ -30,7 +30,7 @@ type CandidateToDuplicate = {
|
||||||
redundancy: VideosRedundancy,
|
redundancy: VideosRedundancy,
|
||||||
video: MVideoWithAllFiles,
|
video: MVideoWithAllFiles,
|
||||||
files: MVideoFile[],
|
files: MVideoFile[],
|
||||||
streamingPlaylists: MStreamingPlaylist[]
|
streamingPlaylists: MStreamingPlaylistFiles[]
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMVideoRedundancyFileVideo (
|
function isMVideoRedundancyFileVideo (
|
||||||
|
@ -196,7 +196,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
|
||||||
logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy)
|
logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy)
|
||||||
|
|
||||||
const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
|
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)
|
const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT)
|
||||||
|
|
||||||
|
@ -290,12 +290,15 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
|
||||||
return `${object.VideoStreamingPlaylist.playlistUrl}`
|
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 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) {
|
private async loadAndRefreshVideo (videoUrl: string) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/typings/models'
|
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/typings/models'
|
||||||
import { extractVideo } from './videos'
|
import { extractVideo } from './videos'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { CONFIG } from '@server/initializers/config'
|
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 ##################
|
// ################## Video file name ##################
|
||||||
|
|
||||||
|
@ -34,6 +34,14 @@ function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, vi
|
||||||
return join(baseDir, getVideoFilename(videoOrPlaylist, videoFile))
|
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 ##################
|
// ################## Torrents ##################
|
||||||
|
|
||||||
function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
|
function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
|
||||||
|
@ -60,5 +68,7 @@ export {
|
||||||
getVideoFilePath,
|
getVideoFilePath,
|
||||||
|
|
||||||
getTorrentFileName,
|
getTorrentFileName,
|
||||||
getTorrentFilePath
|
getTorrentFilePath,
|
||||||
|
|
||||||
|
getHLSDirectory
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ import {
|
||||||
import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
|
import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
|
||||||
import { MThumbnail } from '../../typings/models/video/thumbnail'
|
import { MThumbnail } from '../../typings/models/video/thumbnail'
|
||||||
import { VideoFile } from '@shared/models/videos/video-file.model'
|
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
|
// 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 })[] = [
|
const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [
|
||||||
|
@ -1950,11 +1950,10 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
}
|
}
|
||||||
|
|
||||||
removeStreamingPlaylist (isRedundancy = false) {
|
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(directoryPath)
|
||||||
return remove(filePath)
|
.catch(err => logger.warn('Cannot delete playlist directory %s.', directoryPath, { err }))
|
||||||
.catch(err => logger.warn('Cannot delete playlist directory %s.', filePath, { err }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isOutdated () {
|
isOutdated () {
|
||||||
|
|
|
@ -106,7 +106,7 @@ describe('Test AP refresher', function () {
|
||||||
|
|
||||||
await reRunServer(servers[ 1 ])
|
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 getVideo(servers[ 0 ].url, videoUUID3)
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
execCLI,
|
execCLI,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
getAccount,
|
getAccount,
|
||||||
getEnvCli,
|
getEnvCli, makeGetRequest, makeRawRequest,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers, setDefaultVideoChannel,
|
setAccessTokensToServers, setDefaultVideoChannel,
|
||||||
updateMyAvatar,
|
updateMyAvatar,
|
||||||
|
@ -46,7 +46,7 @@ async function assertCountAreOkay (servers: ServerInfo[]) {
|
||||||
expect(videosCount).to.equal(8)
|
expect(videosCount).to.equal(8)
|
||||||
|
|
||||||
const torrentsCount = await countFiles(server.internalServerNumber, 'torrents')
|
const torrentsCount = await countFiles(server.internalServerNumber, 'torrents')
|
||||||
expect(torrentsCount).to.equal(8)
|
expect(torrentsCount).to.equal(16)
|
||||||
|
|
||||||
const previewsCount = await countFiles(server.internalServerNumber, 'previews')
|
const previewsCount = await countFiles(server.internalServerNumber, 'previews')
|
||||||
expect(previewsCount).to.equal(2)
|
expect(previewsCount).to.equal(2)
|
||||||
|
@ -94,13 +94,21 @@ describe('Test prune storage scripts', function () {
|
||||||
{
|
{
|
||||||
const res = await getAccount(servers[ 0 ].url, 'root@localhost:' + servers[ 1 ].port)
|
const res = await getAccount(servers[ 0 ].url, 'root@localhost:' + servers[ 1 ].port)
|
||||||
const account: Account = res.body
|
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 res = await getAccount(servers[ 1 ].url, 'root@localhost:' + servers[ 0 ].port)
|
||||||
const account: Account = res.body
|
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)
|
await wait(1000)
|
||||||
|
|
Loading…
Reference in New Issue