Use height instead of width to represent the video resolution

pull/974/head
Chocobozzz 2018-08-17 11:24:36 +02:00
parent 06a05d5f47
commit 965c4b22d0
4 changed files with 13 additions and 10 deletions

View File

@ -148,22 +148,25 @@ function setRemoteVideoTruncatedContent (video: any) {
} }
function isRemoteVideoUrlValid (url: any) { function isRemoteVideoUrlValid (url: any) {
// FIXME: Old bug, we used the width to represent the resolution. Remove it in a few realease (currently beta.11)
if (url.width && !url.height) url.height = url.width
return url.type === 'Link' && return url.type === 'Link' &&
( (
ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 && ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 &&
isActivityPubUrlValid(url.href) && isActivityPubUrlValid(url.href) &&
validator.isInt(url.width + '', { min: 0 }) && validator.isInt(url.height + '', { min: 0 }) &&
validator.isInt(url.size + '', { min: 0 }) && validator.isInt(url.size + '', { min: 0 }) &&
(!url.fps || validator.isInt(url.fps + '', { min: 0 })) (!url.fps || validator.isInt(url.fps + '', { min: 0 }))
) || ) ||
( (
ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 && ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 &&
isActivityPubUrlValid(url.href) && isActivityPubUrlValid(url.href) &&
validator.isInt(url.width + '', { min: 0 }) validator.isInt(url.height + '', { min: 0 })
) || ) ||
( (
ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mimeType) !== -1 && ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mimeType) !== -1 &&
validator.isLength(url.href, { min: 5 }) && validator.isLength(url.href, { min: 5 }) &&
validator.isInt(url.width + '', { min: 0 }) validator.isInt(url.height + '', { min: 0 })
) )
} }

View File

@ -11,7 +11,7 @@ import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos
import { retryTransactionWrapper } from '../../helpers/database-utils' import { retryTransactionWrapper } from '../../helpers/database-utils'
import { logger } from '../../helpers/logger' import { logger } from '../../helpers/logger'
import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, STATIC_PATHS, VIDEO_MIMETYPE_EXT } from '../../initializers' import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, VIDEO_MIMETYPE_EXT } from '../../initializers'
import { AccountVideoRateModel } from '../../models/account/account-video-rate' import { AccountVideoRateModel } from '../../models/account/account-video-rate'
import { ActorModel } from '../../models/activitypub/actor' import { ActorModel } from '../../models/activitypub/actor'
import { TagModel } from '../../models/video/tag' import { TagModel } from '../../models/video/tag'
@ -147,7 +147,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje
for (const fileUrl of fileUrls) { for (const fileUrl of fileUrls) {
// Fetch associated magnet uri // Fetch associated magnet uri
const magnet = videoObject.url.find(u => { const magnet = videoObject.url.find(u => {
return u.mimeType === 'application/x-bittorrent;x-scheme-handler/magnet' && u.width === fileUrl.width return u.mimeType === 'application/x-bittorrent;x-scheme-handler/magnet' && u.height === fileUrl.height
}) })
if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href) if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href)
@ -160,7 +160,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje
const attribute = { const attribute = {
extname: VIDEO_MIMETYPE_EXT[ fileUrl.mimeType ], extname: VIDEO_MIMETYPE_EXT[ fileUrl.mimeType ],
infoHash: parsed.infoHash, infoHash: parsed.infoHash,
resolution: fileUrl.width, resolution: fileUrl.height,
size: fileUrl.size, size: fileUrl.size,
videoId: videoCreated.id, videoId: videoCreated.id,
fps: fileUrl.fps fps: fileUrl.fps

View File

@ -1402,7 +1402,7 @@ export class VideoModel extends Model<VideoModel> {
type: 'Link', type: 'Link',
mimeType: VIDEO_EXT_MIMETYPE[file.extname], mimeType: VIDEO_EXT_MIMETYPE[file.extname],
href: this.getVideoFileUrl(file, baseUrlHttp), href: this.getVideoFileUrl(file, baseUrlHttp),
width: file.resolution, height: file.resolution,
size: file.size, size: file.size,
fps: file.fps fps: file.fps
}) })
@ -1411,14 +1411,14 @@ export class VideoModel extends Model<VideoModel> {
type: 'Link', type: 'Link',
mimeType: 'application/x-bittorrent', mimeType: 'application/x-bittorrent',
href: this.getTorrentUrl(file, baseUrlHttp), href: this.getTorrentUrl(file, baseUrlHttp),
width: file.resolution height: file.resolution
}) })
url.push({ url.push({
type: 'Link', type: 'Link',
mimeType: 'application/x-bittorrent;x-scheme-handler/magnet', mimeType: 'application/x-bittorrent;x-scheme-handler/magnet',
href: this.generateMagnetUri(file, baseUrlHttp, baseUrlWs), href: this.generateMagnetUri(file, baseUrlHttp, baseUrlWs),
width: file.resolution height: file.resolution
}) })
} }

View File

@ -21,7 +21,7 @@ export interface ActivityUrlObject {
type: 'Link' type: 'Link'
mimeType: 'video/mp4' | 'video/webm' | 'application/x-bittorrent' | 'application/x-bittorrent;x-scheme-handler/magnet' mimeType: 'video/mp4' | 'video/webm' | 'application/x-bittorrent' | 'application/x-bittorrent;x-scheme-handler/magnet'
href: string href: string
width: number height: number
size?: number size?: number
fps?: number fps?: number