From 29d4e1375fdac88595347184c3d1b214804794b0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 1 Aug 2019 14:19:18 +0200 Subject: Fix HLS transcoding --- server/lib/activitypub/process/process-dislike.ts | 4 ++++ server/lib/activitypub/process/process-like.ts | 4 ++++ server/lib/activitypub/process/process-undo.ts | 10 ++++------ server/lib/video-transcoding.ts | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts index ed8afd3d2..c46180617 100644 --- a/server/lib/activitypub/process/process-dislike.ts +++ b/server/lib/activitypub/process/process-dislike.ts @@ -43,6 +43,10 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct await video.increment('dislikes', { transaction: t }) + if (existingRate && existingRate.type === 'like') { + await video.decrement('likes', { transaction: t }) + } + if (video.isOwned()) { // Don't resend the activity to the sender const exceptions = [ byActor ] diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index 8b97aae55..5b2ab4b66 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts @@ -43,6 +43,10 @@ async function processLikeVideo (byActor: ActorModel, activity: ActivityLike) { await video.increment('likes', { transaction: t }) + if (existingRate && existingRate.type === 'dislike') { + await video.decrement('dislikes', { transaction: t }) + } + if (video.isOwned()) { // Don't resend the activity to the sender const exceptions = [ byActor ] diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index 2d48848fe..692c51904 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts @@ -59,9 +59,8 @@ async function processUndoLike (byActor: ActorModel, activity: ActivityUndo) { return sequelizeTypescript.transaction(async t => { if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) - let rate = await AccountVideoRateModel.loadByUrl(likeActivity.id, t) - if (!rate) rate = await AccountVideoRateModel.load(byActor.Account.id, video.id, t) - if (!rate) throw new Error(`Unknown rate by account ${byActor.Account.id} for video ${video.id}.`) + const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, likeActivity.id, t) + if (!rate || rate.type !== 'like') throw new Error(`Unknown like by account ${byActor.Account.id} for video ${video.id}.`) await rate.destroy({ transaction: t }) await video.decrement('likes', { transaction: t }) @@ -85,9 +84,8 @@ async function processUndoDislike (byActor: ActorModel, activity: ActivityUndo) return sequelizeTypescript.transaction(async t => { if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) - let rate = await AccountVideoRateModel.loadByUrl(dislike.id, t) - if (!rate) rate = await AccountVideoRateModel.load(byActor.Account.id, video.id, t) - if (!rate) throw new Error(`Unknown rate by account ${byActor.Account.id} for video ${video.id}.`) + const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, dislike.id, t) + if (!rate || rate.type !== 'dislike') throw new Error(`Unknown dislike by account ${byActor.Account.id} for video ${video.id}.`) await rate.destroy({ transaction: t }) await video.decrement('dislikes', { transaction: t }) diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index 8d786e0ef..ba6b29163 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts @@ -121,7 +121,7 @@ async function generateHlsPlaylist (video: VideoModel, resolution: VideoResoluti const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)) - const videoInputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(video.getOriginalFile())) + const videoInputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(video.getFile(resolution))) const outputPath = join(baseHlsDirectory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution)) const transcodeOptions = { -- cgit v1.2.3