From d7a25329f9e607894d29ab342b9cb66638b56dc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 15 Nov 2019 15:06:03 +0100 Subject: Add ability to disable webtorrent In favour of HLS --- shared/extra-utils/server/config.ts | 3 ++ shared/extra-utils/videos/videos.ts | 3 +- .../models/activitypub/objects/common-objects.ts | 51 ++++++++++++++-------- shared/models/server/custom-config.model.ts | 7 +++ shared/models/server/server-config.model.ts | 4 ++ shared/models/videos/index.ts | 1 + shared/models/videos/video-file.model.ts | 12 +++++ .../videos/video-streaming-playlist.model.ts | 3 ++ shared/models/videos/video.model.ts | 12 +---- 9 files changed, 65 insertions(+), 31 deletions(-) create mode 100644 shared/models/videos/video-file.model.ts (limited to 'shared') diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts index 578dd35cf..ada173313 100644 --- a/shared/extra-utils/server/config.ts +++ b/shared/extra-utils/server/config.ts @@ -118,6 +118,9 @@ function updateCustomSubConfig (url: string, token: string, newConfig: DeepParti '1080p': false, '2160p': false }, + webtorrent: { + enabled: true + }, hls: { enabled: false } diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 75f7d58d7..1fcc949da 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts @@ -573,7 +573,6 @@ async function completeVideoCheck ( // Transcoding enabled: extension will always be .mp4 if (attributes.files.length > 1) extension = '.mp4' - const magnetUri = file.magnetUri expect(file.magnetUri).to.have.lengthOf.above(2) expect(file.torrentUrl).to.equal(`http://${attributes.account.host}/static/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`) expect(file.fileUrl).to.equal(`http://${attributes.account.host}/static/webseed/${videoDetails.uuid}-${file.resolution.id}${extension}`) @@ -594,7 +593,7 @@ async function completeVideoCheck ( await testImage(url, attributes.previewfile, videoDetails.previewPath) } - const torrent = await webtorrentAdd(magnetUri, true) + const torrent = await webtorrentAdd(file.magnetUri, true) expect(torrent.files).to.be.an('array') expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') diff --git a/shared/models/activitypub/objects/common-objects.ts b/shared/models/activitypub/objects/common-objects.ts index 8c89810d6..2a6529fed 100644 --- a/shared/models/activitypub/objects/common-objects.ts +++ b/shared/models/activitypub/objects/common-objects.ts @@ -3,12 +3,6 @@ export interface ActivityIdentifierObject { name: string } -export interface ActivityTagObject { - type: 'Hashtag' | 'Mention' - href?: string - name: string -} - export interface ActivityIconObject { type: 'Image' url: string @@ -19,8 +13,6 @@ export interface ActivityIconObject { export type ActivityVideoUrlObject = { type: 'Link' - // TODO: remove mimeType (backward compatibility, introduced in v1.1.0) - mimeType?: 'video/mp4' | 'video/webm' | 'video/ogg' mediaType: 'video/mp4' | 'video/webm' | 'video/ogg' href: string height: number @@ -31,8 +23,6 @@ export type ActivityVideoUrlObject = { export type ActivityPlaylistSegmentHashesObject = { type: 'Link' name: 'sha256' - // TODO: remove mimeType (backward compatibility, introduced in v1.1.0) - mimeType?: 'application/json' mediaType: 'application/json' href: string } @@ -44,31 +34,56 @@ export type ActivityPlaylistInfohashesObject = { export type ActivityPlaylistUrlObject = { type: 'Link' - // TODO: remove mimeType (backward compatibility, introduced in v1.1.0) - mimeType?: 'application/x-mpegURL' mediaType: 'application/x-mpegURL' href: string - tag?: (ActivityPlaylistSegmentHashesObject | ActivityPlaylistInfohashesObject)[] + tag?: ActivityTagObject[] } export type ActivityBitTorrentUrlObject = { type: 'Link' - // TODO: remove mimeType (backward compatibility, introduced in v1.1.0) - mimeType?: 'application/x-bittorrent' | 'application/x-bittorrent;x-scheme-handler/magnet' mediaType: 'application/x-bittorrent' | 'application/x-bittorrent;x-scheme-handler/magnet' href: string height: number } +export type ActivityMagnetUrlObject = { + type: 'Link' + mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' + href: string + height: number +} + export type ActivityHtmlUrlObject = { type: 'Link' - // TODO: remove mimeType (backward compatibility, introduced in v1.1.0) - mimeType?: 'text/html' mediaType: 'text/html' href: string } -export type ActivityUrlObject = ActivityVideoUrlObject | ActivityPlaylistUrlObject | ActivityBitTorrentUrlObject | ActivityHtmlUrlObject +export interface ActivityHashTagObject { + type: 'Hashtag' | 'Mention' + href?: string + name: string +} + +export interface ActivityMentionObject { + type: 'Hashtag' | 'Mention' + href?: string + name: string +} + +export type ActivityTagObject = ActivityPlaylistSegmentHashesObject | + ActivityPlaylistInfohashesObject | + ActivityVideoUrlObject | + ActivityHashTagObject | + ActivityMentionObject | + ActivityBitTorrentUrlObject | + ActivityMagnetUrlObject + +export type ActivityUrlObject = ActivityVideoUrlObject | + ActivityPlaylistUrlObject | + ActivityBitTorrentUrlObject | + ActivityMagnetUrlObject | + ActivityHtmlUrlObject export interface ActivityPubAttributedTo { type: 'Group' | 'Person' diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts index c9957f825..97972b759 100644 --- a/shared/models/server/custom-config.model.ts +++ b/shared/models/server/custom-config.model.ts @@ -69,8 +69,10 @@ export interface CustomConfig { transcoding: { enabled: boolean + allowAdditionalExtensions: boolean allowAudioFiles: boolean + threads: number resolutions: { '240p': boolean @@ -80,6 +82,11 @@ export interface CustomConfig { '1080p': boolean '2160p': boolean } + + webtorrent: { + enabled: boolean + } + hls: { enabled: boolean } diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts index 3498f86d7..6d1072333 100644 --- a/shared/models/server/server-config.model.ts +++ b/shared/models/server/server-config.model.ts @@ -56,6 +56,10 @@ export interface ServerConfig { enabled: boolean } + webtorrent: { + enabled: boolean + } + enabledResolutions: number[] } diff --git a/shared/models/videos/index.ts b/shared/models/videos/index.ts index 194ae1b96..51ccb9fbd 100644 --- a/shared/models/videos/index.ts +++ b/shared/models/videos/index.ts @@ -23,6 +23,7 @@ export * from './playlist/video-playlist-element.model' export * from './video-change-ownership.model' export * from './video-change-ownership-create.model' export * from './video-create.model' +export * from './video-file.model' export * from './video-privacy.enum' export * from './video-rate.type' export * from './video-resolution.enum' diff --git a/shared/models/videos/video-file.model.ts b/shared/models/videos/video-file.model.ts new file mode 100644 index 000000000..04da0627e --- /dev/null +++ b/shared/models/videos/video-file.model.ts @@ -0,0 +1,12 @@ +import { VideoConstant, VideoResolution } from '@shared/models' + +export interface VideoFile { + magnetUri: string + resolution: VideoConstant + size: number // Bytes + torrentUrl: string + torrentDownloadUrl: string + fileUrl: string + fileDownloadUrl: string + fps: number +} diff --git a/shared/models/videos/video-streaming-playlist.model.ts b/shared/models/videos/video-streaming-playlist.model.ts index 17f8fe865..42fce4bdc 100644 --- a/shared/models/videos/video-streaming-playlist.model.ts +++ b/shared/models/videos/video-streaming-playlist.model.ts @@ -1,4 +1,5 @@ import { VideoStreamingPlaylistType } from './video-streaming-playlist.type' +import { VideoFile } from '@shared/models/videos/video-file.model' export class VideoStreamingPlaylist { id: number @@ -9,4 +10,6 @@ export class VideoStreamingPlaylist { redundancies: { baseUrl: string }[] + + files: VideoFile[] } diff --git a/shared/models/videos/video.model.ts b/shared/models/videos/video.model.ts index e057b3e06..7576439fe 100644 --- a/shared/models/videos/video.model.ts +++ b/shared/models/videos/video.model.ts @@ -5,17 +5,7 @@ import { VideoPrivacy } from './video-privacy.enum' import { VideoScheduleUpdate } from './video-schedule-update.model' import { VideoConstant } from './video-constant.model' import { VideoStreamingPlaylist } from './video-streaming-playlist.model' - -export interface VideoFile { - magnetUri: string - resolution: VideoConstant - size: number // Bytes - torrentUrl: string - torrentDownloadUrl: string - fileUrl: string - fileDownloadUrl: string - fps: number -} +import { VideoFile } from './video-file.model' export interface Video { id: number -- cgit v1.2.3