From 965c4b22d0e4d2f853501e844e6ebbb861bd389d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 17 Aug 2018 11:24:36 +0200 Subject: Use height instead of width to represent the video resolution --- server/helpers/custom-validators/activitypub/videos.ts | 9 ++++++--- server/lib/activitypub/videos.ts | 6 +++--- server/models/video/video.ts | 6 +++--- shared/models/activitypub/objects/common-objects.ts | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 702c09842..0362f43ab 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts @@ -148,22 +148,25 @@ function setRemoteVideoTruncatedContent (video: 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' && ( ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 && isActivityPubUrlValid(url.href) && - validator.isInt(url.width + '', { min: 0 }) && + validator.isInt(url.height + '', { min: 0 }) && validator.isInt(url.size + '', { min: 0 }) && (!url.fps || validator.isInt(url.fps + '', { min: 0 })) ) || ( ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 && 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 && validator.isLength(url.href, { min: 5 }) && - validator.isInt(url.width + '', { min: 0 }) + validator.isInt(url.height + '', { min: 0 }) ) } diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index e2f46bd02..d1888556c 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -11,7 +11,7 @@ import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos import { retryTransactionWrapper } from '../../helpers/database-utils' import { logger } from '../../helpers/logger' 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 { ActorModel } from '../../models/activitypub/actor' import { TagModel } from '../../models/video/tag' @@ -147,7 +147,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje for (const fileUrl of fileUrls) { // Fetch associated magnet uri 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) @@ -160,7 +160,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje const attribute = { extname: VIDEO_MIMETYPE_EXT[ fileUrl.mimeType ], infoHash: parsed.infoHash, - resolution: fileUrl.width, + resolution: fileUrl.height, size: fileUrl.size, videoId: videoCreated.id, fps: fileUrl.fps diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 5db718061..25a1cd177 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1402,7 +1402,7 @@ export class VideoModel extends Model { type: 'Link', mimeType: VIDEO_EXT_MIMETYPE[file.extname], href: this.getVideoFileUrl(file, baseUrlHttp), - width: file.resolution, + height: file.resolution, size: file.size, fps: file.fps }) @@ -1411,14 +1411,14 @@ export class VideoModel extends Model { type: 'Link', mimeType: 'application/x-bittorrent', href: this.getTorrentUrl(file, baseUrlHttp), - width: file.resolution + height: file.resolution }) url.push({ type: 'Link', mimeType: 'application/x-bittorrent;x-scheme-handler/magnet', href: this.generateMagnetUri(file, baseUrlHttp, baseUrlWs), - width: file.resolution + height: file.resolution }) } diff --git a/shared/models/activitypub/objects/common-objects.ts b/shared/models/activitypub/objects/common-objects.ts index 5b2b3adae..ff2cfdbb4 100644 --- a/shared/models/activitypub/objects/common-objects.ts +++ b/shared/models/activitypub/objects/common-objects.ts @@ -21,7 +21,7 @@ export interface ActivityUrlObject { type: 'Link' mimeType: 'video/mp4' | 'video/webm' | 'application/x-bittorrent' | 'application/x-bittorrent;x-scheme-handler/magnet' href: string - width: number + height: number size?: number fps?: number -- cgit v1.2.3