diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-01 14:19:18 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-01 14:19:18 +0200 |
commit | 29d4e1375fdac88595347184c3d1b214804794b0 (patch) | |
tree | 4f66651218c1a7dee579d006e6e396f141382228 | |
parent | 16b5525950c27172b8426e03cbb1c59794cfc44c (diff) | |
download | PeerTube-29d4e1375fdac88595347184c3d1b214804794b0.tar.gz PeerTube-29d4e1375fdac88595347184c3d1b214804794b0.tar.zst PeerTube-29d4e1375fdac88595347184c3d1b214804794b0.zip |
Fix HLS transcoding
-rw-r--r-- | server/lib/activitypub/process/process-dislike.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 10 | ||||
-rw-r--r-- | server/lib/video-transcoding.ts | 2 | ||||
-rw-r--r-- | server/models/video/video.ts | 8 |
5 files changed, 20 insertions, 8 deletions
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 | |||
43 | 43 | ||
44 | await video.increment('dislikes', { transaction: t }) | 44 | await video.increment('dislikes', { transaction: t }) |
45 | 45 | ||
46 | if (existingRate && existingRate.type === 'like') { | ||
47 | await video.decrement('likes', { transaction: t }) | ||
48 | } | ||
49 | |||
46 | if (video.isOwned()) { | 50 | if (video.isOwned()) { |
47 | // Don't resend the activity to the sender | 51 | // Don't resend the activity to the sender |
48 | const exceptions = [ byActor ] | 52 | 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) { | |||
43 | 43 | ||
44 | await video.increment('likes', { transaction: t }) | 44 | await video.increment('likes', { transaction: t }) |
45 | 45 | ||
46 | if (existingRate && existingRate.type === 'dislike') { | ||
47 | await video.decrement('dislikes', { transaction: t }) | ||
48 | } | ||
49 | |||
46 | if (video.isOwned()) { | 50 | if (video.isOwned()) { |
47 | // Don't resend the activity to the sender | 51 | // Don't resend the activity to the sender |
48 | const exceptions = [ byActor ] | 52 | 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) { | |||
59 | return sequelizeTypescript.transaction(async t => { | 59 | return sequelizeTypescript.transaction(async t => { |
60 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) | 60 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) |
61 | 61 | ||
62 | let rate = await AccountVideoRateModel.loadByUrl(likeActivity.id, t) | 62 | const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, likeActivity.id, t) |
63 | if (!rate) rate = await AccountVideoRateModel.load(byActor.Account.id, video.id, t) | 63 | if (!rate || rate.type !== 'like') throw new Error(`Unknown like by account ${byActor.Account.id} for video ${video.id}.`) |
64 | if (!rate) throw new Error(`Unknown rate by account ${byActor.Account.id} for video ${video.id}.`) | ||
65 | 64 | ||
66 | await rate.destroy({ transaction: t }) | 65 | await rate.destroy({ transaction: t }) |
67 | await video.decrement('likes', { transaction: t }) | 66 | await video.decrement('likes', { transaction: t }) |
@@ -85,9 +84,8 @@ async function processUndoDislike (byActor: ActorModel, activity: ActivityUndo) | |||
85 | return sequelizeTypescript.transaction(async t => { | 84 | return sequelizeTypescript.transaction(async t => { |
86 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) | 85 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) |
87 | 86 | ||
88 | let rate = await AccountVideoRateModel.loadByUrl(dislike.id, t) | 87 | const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, dislike.id, t) |
89 | if (!rate) rate = await AccountVideoRateModel.load(byActor.Account.id, video.id, t) | 88 | if (!rate || rate.type !== 'dislike') throw new Error(`Unknown dislike by account ${byActor.Account.id} for video ${video.id}.`) |
90 | if (!rate) throw new Error(`Unknown rate by account ${byActor.Account.id} for video ${video.id}.`) | ||
91 | 89 | ||
92 | await rate.destroy({ transaction: t }) | 90 | await rate.destroy({ transaction: t }) |
93 | await video.decrement('dislikes', { transaction: t }) | 91 | 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 | |||
121 | const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) | 121 | const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) |
122 | await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)) | 122 | await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)) |
123 | 123 | ||
124 | const videoInputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(video.getOriginalFile())) | 124 | const videoInputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(video.getFile(resolution))) |
125 | const outputPath = join(baseHlsDirectory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution)) | 125 | const outputPath = join(baseHlsDirectory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution)) |
126 | 126 | ||
127 | const transcodeOptions = { | 127 | const transcodeOptions = { |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 05d625fc1..ae29cf286 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -36,7 +36,7 @@ import { | |||
36 | Table, | 36 | Table, |
37 | UpdatedAt | 37 | UpdatedAt |
38 | } from 'sequelize-typescript' | 38 | } from 'sequelize-typescript' |
39 | import { UserRight, VideoPrivacy, VideoState } from '../../../shared' | 39 | import { UserRight, VideoPrivacy, VideoResolution, VideoState } from '../../../shared' |
40 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 40 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' |
41 | import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' | 41 | import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' |
42 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' | 42 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' |
@@ -1753,6 +1753,12 @@ export class VideoModel extends Model<VideoModel> { | |||
1753 | return maxBy(this.VideoFiles, file => file.resolution) | 1753 | return maxBy(this.VideoFiles, file => file.resolution) |
1754 | } | 1754 | } |
1755 | 1755 | ||
1756 | getFile (resolution: VideoResolution) { | ||
1757 | if (Array.isArray(this.VideoFiles) === false) return undefined | ||
1758 | |||
1759 | return this.VideoFiles.find(f => f.resolution === resolution) | ||
1760 | } | ||
1761 | |||
1756 | async addAndSaveThumbnail (thumbnail: ThumbnailModel, transaction: Transaction) { | 1762 | async addAndSaveThumbnail (thumbnail: ThumbnailModel, transaction: Transaction) { |
1757 | thumbnail.videoId = this.id | 1763 | thumbnail.videoId = this.id |
1758 | 1764 | ||