ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix mime type handling from remote instances
Chocobozzzd0f8a0e677de
diff --git a/client/src/app/shared/shared-instance/instance-features-table.component.html b/client/src/app/shared/shared-instance/instance-features-table.component.htmlindex 37f53b7c69..4c355c392e 100644--- a/client/src/app/shared/shared-instance/instance-features-table.component.html+++ b/client/src/app/shared/shared-instance/instance-features-table.component.html@@ -9,9 +9,9 @@</tr><tr>- <th i18n class="label" scope="row">- <div>Default NSFW/sensitive videos policy</div>- <span class="fs-7 fw-normal fst-italic">can be redefined by the users</span>+ <th class="label" scope="row">+ <div i18n>Default NSFW/sensitive videos policy</div>+ <span i18n class="fs-7 fw-normal fst-italic">can be redefined by the users</span></th><td class="value">{{ buildNSFWLabel() }}</td>diff --git a/packages/models/src/activitypub/objects/common-objects.ts b/packages/models/src/activitypub/objects/common-objects.tsindex a332c26f3d..df5dcb56fd 100644--- a/packages/models/src/activitypub/objects/common-objects.ts+++ b/packages/models/src/activitypub/objects/common-objects.ts@@ -16,7 +16,7 @@ export interface ActivityIconObject {export type ActivityVideoUrlObject = {type: 'Link'- mediaType: 'video/mp4' | 'video/webm' | 'video/ogg'+ mediaType: 'video/mp4' | 'video/webm' | 'video/ogg' | 'audio/mp4'href: stringheight: numbersize: numberdiff --git a/server/server/helpers/custom-validators/activitypub/videos.ts b/server/server/helpers/custom-validators/activitypub/videos.tsindex b7298c4742..7ef9723ca4 100644--- a/server/server/helpers/custom-validators/activitypub/videos.ts+++ b/server/server/helpers/custom-validators/activitypub/videos.ts@@ -8,7 +8,7 @@ import {VideoState} from '@peertube/peertube-models'import { logger } from '@server/helpers/logger.js'-import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers/constants.js'+import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants.js'import { peertubeTruncate } from '../../core-utils.js'import { isArray, isBooleanValid, isDateValid, isUUIDValid } from '../misc.js'import { isLiveLatencyModeValid } from '../video-lives.js'@@ -91,7 +91,7 @@ function isRemoteVideoUrlValid (url: any) {return url.type === 'Link' &&// Video file link(- ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.includes(url.mediaType) &&+ MIMETYPES.AP_VIDEO.MIMETYPE_EXT[url.mediaType] &&isActivityPubUrlValid(url.href) &&validator.default.isInt(url.height + '', { min: 0 }) &&validator.default.isInt(url.size + '', { min: 0 }) &&@@ -99,13 +99,13 @@ function isRemoteVideoUrlValid (url: any) {) ||// Torrent link(- ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.includes(url.mediaType) &&+ MIMETYPES.AP_TORRENT.MIMETYPE_EXT[url.mediaType] &&isActivityPubUrlValid(url.href) &&validator.default.isInt(url.height + '', { min: 0 })) ||// Magnet link(- ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.includes(url.mediaType) &&+ MIMETYPES.AP_MAGNET.MIMETYPE_EXT[url.mediaType] &&validator.default.isLength(url.href, { min: 5 }) &&validator.default.isInt(url.height + '', { min: 0 })) ||diff --git a/server/server/initializers/constants.ts b/server/server/initializers/constants.tsindex 121433caf2..4c58c19c8c 100644--- a/server/server/initializers/constants.ts+++ b/server/server/initializers/constants.ts@@ -672,8 +672,27 @@ const MIMETYPES = {MIMETYPE_EXT: {'application/vnd.apple.mpegurl': '.m3u8'}+ },+ AP_VIDEO: {+ MIMETYPE_EXT: {+ 'video/mp4': '.mp4',+ 'video/ogg': '.ogv',+ 'video/webm': '.webm',+ 'audio/mp4': '.mp4'+ }+ },+ AP_TORRENT: {+ MIMETYPE_EXT: {+ 'application/x-bittorrent': '.torrent'+ }+ },+ AP_MAGNET: {+ MIMETYPE_EXT: {+ 'application/x-bittorrent;x-scheme-handler/magnet': '.magnet'+ }}}+MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT)MIMETYPES.VIDEO_CAPTIONS.EXT_MIMETYPE = invert(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT)@@ -707,11 +726,6 @@ const ACTIVITY_PUB = {PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',COLLECTION_ITEMS_PER_PAGE: 10,FETCH_PAGE_LIMIT: 2000,- URL_MIME_TYPES: {- VIDEO: [] as string[],- TORRENT: [ 'application/x-bittorrent' ],- MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]- },MAX_RECURSION_COMMENTS: 100,ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 daysVIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days@@ -1313,8 +1327,6 @@ function updateWebserverConfig () {MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT)- ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)-MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT)CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE)diff --git a/server/server/lib/activitypub/videos/shared/object-to-model-attributes.ts b/server/server/lib/activitypub/videos/shared/object-to-model-attributes.tsindex c0a9453312..9657bd1721 100644--- a/server/server/lib/activitypub/videos/shared/object-to-model-attributes.ts+++ b/server/server/lib/activitypub/videos/shared/object-to-model-attributes.ts@@ -264,9 +264,7 @@ export {// ---------------------------------------------------------------------------function isAPVideoUrlObject (url: any): url is ActivityVideoUrlObject {- const urlMediaType = url.mediaType-- return MIMETYPES.VIDEO.MIMETYPE_EXT[urlMediaType] && urlMediaType.startsWith('video/')+ return !!MIMETYPES.AP_VIDEO.MIMETYPE_EXT[url.mediaType]}function isAPStreamingPlaylistUrlObject (url: any): url is ActivityPlaylistUrlObject {diff --git a/server/server/models/video/formatter/video-activity-pub-format.ts b/server/server/models/video/formatter/video-activity-pub-format.tsindex 7beec741a0..691948a476 100644--- a/server/server/models/video/formatter/video-activity-pub-format.ts+++ b/server/server/models/video/formatter/video-activity-pub-format.ts@@ -181,7 +181,8 @@ function buildVideoFileUrls (options: {.sort(sortByResolutionDesc)for (const file of sortedFiles) {- const mimeType = getVideoFileMimeType(file.extname, file.isAudio())+ // FIXME: Replace false by file.isAudio(), federation breaking change correctly handled in 6.0+ const mimeType = getVideoFileMimeType(file.extname, false)urls.push({type: 'Link',