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 ]
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 ]
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 })
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 })
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 = {
Table,
UpdatedAt
} from 'sequelize-typescript'
-import { UserRight, VideoPrivacy, VideoState } from '../../../shared'
+import { UserRight, VideoPrivacy, VideoResolution, VideoState } from '../../../shared'
import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
import { VideoFilter } from '../../../shared/models/videos/video-query.type'
return maxBy(this.VideoFiles, file => file.resolution)
}
+ getFile (resolution: VideoResolution) {
+ if (Array.isArray(this.VideoFiles) === false) return undefined
+
+ return this.VideoFiles.find(f => f.resolution === resolution)
+ }
+
async addAndSaveThumbnail (thumbnail: ThumbnailModel, transaction: Transaction) {
thumbnail.videoId = this.id