diff options
author | Chocobozzz <me@florianbigard.com> | 2020-03-10 14:49:02 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-03-10 16:18:29 +0100 |
commit | 7b81edc854902a536083298472bf92bb6726edcf (patch) | |
tree | 822dae6b6d4755ac9afffe2569b74dcb45da5535 /server/helpers | |
parent | 8319d6ae72d4da6de51bd3d4b5c68040fc8dc3b4 (diff) | |
download | PeerTube-7b81edc854902a536083298472bf92bb6726edcf.tar.gz PeerTube-7b81edc854902a536083298472bf92bb6726edcf.tar.zst PeerTube-7b81edc854902a536083298472bf92bb6726edcf.zip |
Video file metadata PR cleanup
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 14 | ||||
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 2 |
2 files changed, 13 insertions, 3 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index af8c8a0c8..876cc7f50 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -13,6 +13,7 @@ import { | |||
13 | import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' | 13 | import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' |
14 | import { VideoState } from '../../../../shared/models/videos' | 14 | import { VideoState } from '../../../../shared/models/videos' |
15 | import { logger } from '@server/helpers/logger' | 15 | import { logger } from '@server/helpers/logger' |
16 | import { ActivityVideoFileMetadataObject } from '@shared/models' | ||
16 | 17 | ||
17 | function sanitizeAndCheckVideoTorrentUpdateActivity (activity: any) { | 18 | function sanitizeAndCheckVideoTorrentUpdateActivity (activity: any) { |
18 | return isBaseActivityValid(activity, 'Update') && | 19 | return isBaseActivityValid(activity, 'Update') && |
@@ -104,7 +105,15 @@ function isRemoteVideoUrlValid (url: any) { | |||
104 | (url.mediaType || url.mimeType) === 'application/x-mpegURL' && | 105 | (url.mediaType || url.mimeType) === 'application/x-mpegURL' && |
105 | isActivityPubUrlValid(url.href) && | 106 | isActivityPubUrlValid(url.href) && |
106 | isArray(url.tag) | 107 | isArray(url.tag) |
107 | ) | 108 | ) || |
109 | isAPVideoFileMetadataObject(url) | ||
110 | } | ||
111 | |||
112 | function isAPVideoFileMetadataObject (url: any): url is ActivityVideoFileMetadataObject { | ||
113 | return url && | ||
114 | url.type === 'Link' && | ||
115 | url.mediaType === 'application/json' && | ||
116 | isArray(url.rel) && url.rel.includes('metadata') | ||
108 | } | 117 | } |
109 | 118 | ||
110 | // --------------------------------------------------------------------------- | 119 | // --------------------------------------------------------------------------- |
@@ -113,7 +122,8 @@ export { | |||
113 | sanitizeAndCheckVideoTorrentUpdateActivity, | 122 | sanitizeAndCheckVideoTorrentUpdateActivity, |
114 | isRemoteStringIdentifierValid, | 123 | isRemoteStringIdentifierValid, |
115 | sanitizeAndCheckVideoTorrentObject, | 124 | sanitizeAndCheckVideoTorrentObject, |
116 | isRemoteVideoUrlValid | 125 | isRemoteVideoUrlValid, |
126 | isAPVideoFileMetadataObject | ||
117 | } | 127 | } |
118 | 128 | ||
119 | // --------------------------------------------------------------------------- | 129 | // --------------------------------------------------------------------------- |
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 5ee295635..e0e408ea0 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -170,7 +170,7 @@ async function getVideoFileFPS (path: string) { | |||
170 | return 0 | 170 | return 0 |
171 | } | 171 | } |
172 | 172 | ||
173 | async function getMetadataFromFile<T> (path: string, cb = metadata => metadata) { | 173 | async function getMetadataFromFile <T> (path: string, cb = metadata => metadata) { |
174 | return new Promise<T>((res, rej) => { | 174 | return new Promise<T>((res, rej) => { |
175 | ffmpeg.ffprobe(path, (err, metadata) => { | 175 | ffmpeg.ffprobe(path, (err, metadata) => { |
176 | if (err) return rej(err) | 176 | if (err) return rej(err) |