]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Use height instead of width to represent the video resolution
authorChocobozzz <me@florianbigard.com>
Fri, 17 Aug 2018 09:24:36 +0000 (11:24 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 27 Aug 2018 07:41:54 +0000 (09:41 +0200)
server/helpers/custom-validators/activitypub/videos.ts
server/lib/activitypub/videos.ts
server/models/video/video.ts
shared/models/activitypub/objects/common-objects.ts

index 702c09842e23918fe5ffffbef057754827faa55f..0362f43ab2b7a3c521d0497e85ad0d9677671d26 100644 (file)
@@ -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 })
     )
 }
index e2f46bd02dbf4cafa8c8925feb7f0eb58e9df69b..d1888556c0df182cc7c5d8c571533834acca2921 100644 (file)
@@ -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
index 5db718061cd02ffa4223c23a4e45bf4c66310cd4..25a1cd177dbeb2ff00d9b54ae1452ac91cec0ec1 100644 (file)
@@ -1402,7 +1402,7 @@ export class VideoModel extends Model<VideoModel> {
         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<VideoModel> {
         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
       })
     }
 
index 5b2b3adaedb19f455635742c6aab529e50400e1f..ff2cfdbb4894850d0cf9120f1ebcd0a4bf9c550e 100644 (file)
@@ -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