diff options
Diffstat (limited to 'shared')
391 files changed, 0 insertions, 16003 deletions
diff --git a/shared/core-utils/abuse/abuse-predefined-reasons.ts b/shared/core-utils/abuse/abuse-predefined-reasons.ts deleted file mode 100644 index 9967e54dd..000000000 --- a/shared/core-utils/abuse/abuse-predefined-reasons.ts +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | import { AbusePredefinedReasons, AbusePredefinedReasonsString } from '../../models/moderation/abuse/abuse-reason.model' | ||
2 | |||
3 | export const abusePredefinedReasonsMap: { | ||
4 | [key in AbusePredefinedReasonsString]: AbusePredefinedReasons | ||
5 | } = { | ||
6 | violentOrRepulsive: AbusePredefinedReasons.VIOLENT_OR_REPULSIVE, | ||
7 | hatefulOrAbusive: AbusePredefinedReasons.HATEFUL_OR_ABUSIVE, | ||
8 | spamOrMisleading: AbusePredefinedReasons.SPAM_OR_MISLEADING, | ||
9 | privacy: AbusePredefinedReasons.PRIVACY, | ||
10 | rights: AbusePredefinedReasons.RIGHTS, | ||
11 | serverRules: AbusePredefinedReasons.SERVER_RULES, | ||
12 | thumbnails: AbusePredefinedReasons.THUMBNAILS, | ||
13 | captions: AbusePredefinedReasons.CAPTIONS | ||
14 | } | ||
diff --git a/shared/core-utils/abuse/index.ts b/shared/core-utils/abuse/index.ts deleted file mode 100644 index 244b83cff..000000000 --- a/shared/core-utils/abuse/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './abuse-predefined-reasons' | ||
diff --git a/shared/core-utils/common/array.ts b/shared/core-utils/common/array.ts deleted file mode 100644 index 878ed1ffe..000000000 --- a/shared/core-utils/common/array.ts +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | function findCommonElement <T> (array1: T[], array2: T[]) { | ||
2 | for (const a of array1) { | ||
3 | for (const b of array2) { | ||
4 | if (a === b) return a | ||
5 | } | ||
6 | } | ||
7 | |||
8 | return null | ||
9 | } | ||
10 | |||
11 | // Avoid conflict with other toArray() functions | ||
12 | function arrayify <T> (element: T | T[]) { | ||
13 | if (Array.isArray(element)) return element | ||
14 | |||
15 | return [ element ] | ||
16 | } | ||
17 | |||
18 | // Avoid conflict with other uniq() functions | ||
19 | function uniqify <T> (elements: T[]) { | ||
20 | return Array.from(new Set(elements)) | ||
21 | } | ||
22 | |||
23 | // Thanks: https://stackoverflow.com/a/12646864 | ||
24 | function shuffle <T> (elements: T[]) { | ||
25 | const shuffled = [ ...elements ] | ||
26 | |||
27 | for (let i = shuffled.length - 1; i > 0; i--) { | ||
28 | const j = Math.floor(Math.random() * (i + 1)); | ||
29 | |||
30 | [ shuffled[i], shuffled[j] ] = [ shuffled[j], shuffled[i] ] | ||
31 | } | ||
32 | |||
33 | return shuffled | ||
34 | } | ||
35 | |||
36 | export { | ||
37 | uniqify, | ||
38 | findCommonElement, | ||
39 | shuffle, | ||
40 | arrayify | ||
41 | } | ||
diff --git a/shared/core-utils/common/date.ts b/shared/core-utils/common/date.ts deleted file mode 100644 index f0684ff86..000000000 --- a/shared/core-utils/common/date.ts +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | function isToday (d: Date) { | ||
2 | const today = new Date() | ||
3 | |||
4 | return areDatesEqual(d, today) | ||
5 | } | ||
6 | |||
7 | function isYesterday (d: Date) { | ||
8 | const yesterday = new Date() | ||
9 | yesterday.setDate(yesterday.getDate() - 1) | ||
10 | |||
11 | return areDatesEqual(d, yesterday) | ||
12 | } | ||
13 | |||
14 | function isThisWeek (d: Date) { | ||
15 | const minDateOfThisWeek = new Date() | ||
16 | minDateOfThisWeek.setHours(0, 0, 0) | ||
17 | |||
18 | // getDay() -> Sunday - Saturday : 0 - 6 | ||
19 | // We want to start our week on Monday | ||
20 | let dayOfWeek = minDateOfThisWeek.getDay() - 1 | ||
21 | if (dayOfWeek < 0) dayOfWeek = 6 // Sunday | ||
22 | |||
23 | minDateOfThisWeek.setDate(minDateOfThisWeek.getDate() - dayOfWeek) | ||
24 | |||
25 | return d >= minDateOfThisWeek | ||
26 | } | ||
27 | |||
28 | function isThisMonth (d: Date) { | ||
29 | const thisMonth = new Date().getMonth() | ||
30 | |||
31 | return d.getMonth() === thisMonth | ||
32 | } | ||
33 | |||
34 | function isLastMonth (d: Date) { | ||
35 | const now = new Date() | ||
36 | |||
37 | return getDaysDifferences(now, d) <= 30 | ||
38 | } | ||
39 | |||
40 | function isLastWeek (d: Date) { | ||
41 | const now = new Date() | ||
42 | |||
43 | return getDaysDifferences(now, d) <= 7 | ||
44 | } | ||
45 | |||
46 | // --------------------------------------------------------------------------- | ||
47 | |||
48 | function timeToInt (time: number | string) { | ||
49 | if (!time) return 0 | ||
50 | if (typeof time === 'number') return time | ||
51 | |||
52 | const reg = /^((\d+)[h:])?((\d+)[m:])?((\d+)s?)?$/ | ||
53 | const matches = time.match(reg) | ||
54 | |||
55 | if (!matches) return 0 | ||
56 | |||
57 | const hours = parseInt(matches[2] || '0', 10) | ||
58 | const minutes = parseInt(matches[4] || '0', 10) | ||
59 | const seconds = parseInt(matches[6] || '0', 10) | ||
60 | |||
61 | return hours * 3600 + minutes * 60 + seconds | ||
62 | } | ||
63 | |||
64 | function secondsToTime (seconds: number, full = false, symbol?: string) { | ||
65 | let time = '' | ||
66 | |||
67 | if (seconds === 0 && !full) return '0s' | ||
68 | |||
69 | const hourSymbol = (symbol || 'h') | ||
70 | const minuteSymbol = (symbol || 'm') | ||
71 | const secondsSymbol = full ? '' : 's' | ||
72 | |||
73 | const hours = Math.floor(seconds / 3600) | ||
74 | if (hours >= 1) time = hours + hourSymbol | ||
75 | else if (full) time = '0' + hourSymbol | ||
76 | |||
77 | seconds %= 3600 | ||
78 | const minutes = Math.floor(seconds / 60) | ||
79 | if (minutes >= 1 && minutes < 10 && full) time += '0' + minutes + minuteSymbol | ||
80 | else if (minutes >= 1) time += minutes + minuteSymbol | ||
81 | else if (full) time += '00' + minuteSymbol | ||
82 | |||
83 | seconds %= 60 | ||
84 | if (seconds >= 1 && seconds < 10 && full) time += '0' + seconds + secondsSymbol | ||
85 | else if (seconds >= 1) time += seconds + secondsSymbol | ||
86 | else if (full) time += '00' | ||
87 | |||
88 | return time | ||
89 | } | ||
90 | |||
91 | // --------------------------------------------------------------------------- | ||
92 | |||
93 | export { | ||
94 | isYesterday, | ||
95 | isThisWeek, | ||
96 | isThisMonth, | ||
97 | isToday, | ||
98 | isLastMonth, | ||
99 | isLastWeek, | ||
100 | timeToInt, | ||
101 | secondsToTime | ||
102 | } | ||
103 | |||
104 | // --------------------------------------------------------------------------- | ||
105 | |||
106 | function areDatesEqual (d1: Date, d2: Date) { | ||
107 | return d1.getFullYear() === d2.getFullYear() && | ||
108 | d1.getMonth() === d2.getMonth() && | ||
109 | d1.getDate() === d2.getDate() | ||
110 | } | ||
111 | |||
112 | function getDaysDifferences (d1: Date, d2: Date) { | ||
113 | return (d1.getTime() - d2.getTime()) / (86400000) | ||
114 | } | ||
diff --git a/shared/core-utils/common/env.ts b/shared/core-utils/common/env.ts deleted file mode 100644 index 973f895d4..000000000 --- a/shared/core-utils/common/env.ts +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | function parallelTests () { | ||
2 | return process.env.MOCHA_PARALLEL === 'true' | ||
3 | } | ||
4 | |||
5 | function isGithubCI () { | ||
6 | return !!process.env.GITHUB_WORKSPACE | ||
7 | } | ||
8 | |||
9 | function areHttpImportTestsDisabled () { | ||
10 | const disabled = process.env.DISABLE_HTTP_IMPORT_TESTS === 'true' | ||
11 | |||
12 | if (disabled) console.log('DISABLE_HTTP_IMPORT_TESTS env set to "true" so import tests are disabled') | ||
13 | |||
14 | return disabled | ||
15 | } | ||
16 | |||
17 | function areMockObjectStorageTestsDisabled () { | ||
18 | const disabled = process.env.ENABLE_OBJECT_STORAGE_TESTS !== 'true' | ||
19 | |||
20 | if (disabled) console.log('ENABLE_OBJECT_STORAGE_TESTS env is not set to "true" so object storage tests are disabled') | ||
21 | |||
22 | return disabled | ||
23 | } | ||
24 | |||
25 | function areScalewayObjectStorageTestsDisabled () { | ||
26 | if (areMockObjectStorageTestsDisabled()) return true | ||
27 | |||
28 | const enabled = process.env.OBJECT_STORAGE_SCALEWAY_KEY_ID && process.env.OBJECT_STORAGE_SCALEWAY_ACCESS_KEY | ||
29 | if (!enabled) { | ||
30 | console.log( | ||
31 | 'OBJECT_STORAGE_SCALEWAY_KEY_ID and/or OBJECT_STORAGE_SCALEWAY_ACCESS_KEY are not set, so scaleway object storage tests are disabled' | ||
32 | ) | ||
33 | |||
34 | return true | ||
35 | } | ||
36 | |||
37 | return false | ||
38 | } | ||
39 | |||
40 | export { | ||
41 | parallelTests, | ||
42 | isGithubCI, | ||
43 | areHttpImportTestsDisabled, | ||
44 | areMockObjectStorageTestsDisabled, | ||
45 | areScalewayObjectStorageTestsDisabled | ||
46 | } | ||
diff --git a/shared/core-utils/common/index.ts b/shared/core-utils/common/index.ts deleted file mode 100644 index 8d63ee1b2..000000000 --- a/shared/core-utils/common/index.ts +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | export * from './array' | ||
2 | export * from './random' | ||
3 | export * from './date' | ||
4 | export * from './env' | ||
5 | export * from './number' | ||
6 | export * from './object' | ||
7 | export * from './path' | ||
8 | export * from './regexp' | ||
9 | export * from './time' | ||
10 | export * from './promises' | ||
11 | export * from './url' | ||
12 | export * from './version' | ||
diff --git a/shared/core-utils/common/number.ts b/shared/core-utils/common/number.ts deleted file mode 100644 index ce5a6041a..000000000 --- a/shared/core-utils/common/number.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | export function forceNumber (value: any) { | ||
2 | return parseInt(value + '') | ||
3 | } | ||
4 | |||
5 | export function isOdd (num: number) { | ||
6 | return (num % 2) !== 0 | ||
7 | } | ||
8 | |||
9 | export function toEven (num: number) { | ||
10 | if (isOdd(num)) return num + 1 | ||
11 | |||
12 | return num | ||
13 | } | ||
diff --git a/shared/core-utils/common/object.ts b/shared/core-utils/common/object.ts deleted file mode 100644 index 1276bfcc7..000000000 --- a/shared/core-utils/common/object.ts +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | function pick <O extends object, K extends keyof O> (object: O, keys: K[]): Pick<O, K> { | ||
2 | const result: any = {} | ||
3 | |||
4 | for (const key of keys) { | ||
5 | if (Object.prototype.hasOwnProperty.call(object, key)) { | ||
6 | result[key] = object[key] | ||
7 | } | ||
8 | } | ||
9 | |||
10 | return result | ||
11 | } | ||
12 | |||
13 | function omit <O extends object, K extends keyof O> (object: O, keys: K[]): Exclude<O, K> { | ||
14 | const result: any = {} | ||
15 | const keysSet = new Set(keys) as Set<string> | ||
16 | |||
17 | for (const [ key, value ] of Object.entries(object)) { | ||
18 | if (keysSet.has(key)) continue | ||
19 | |||
20 | result[key] = value | ||
21 | } | ||
22 | |||
23 | return result | ||
24 | } | ||
25 | |||
26 | function objectKeysTyped <O extends object, K extends keyof O> (object: O): K[] { | ||
27 | return (Object.keys(object) as K[]) | ||
28 | } | ||
29 | |||
30 | function getKeys <O extends object, K extends keyof O> (object: O, keys: K[]): K[] { | ||
31 | return (Object.keys(object) as K[]).filter(k => keys.includes(k)) | ||
32 | } | ||
33 | |||
34 | function hasKey <T extends object> (obj: T, k: keyof any): k is keyof T { | ||
35 | return k in obj | ||
36 | } | ||
37 | |||
38 | function sortObjectComparator (key: string, order: 'asc' | 'desc') { | ||
39 | return (a: any, b: any) => { | ||
40 | if (a[key] < b[key]) { | ||
41 | return order === 'asc' ? -1 : 1 | ||
42 | } | ||
43 | |||
44 | if (a[key] > b[key]) { | ||
45 | return order === 'asc' ? 1 : -1 | ||
46 | } | ||
47 | |||
48 | return 0 | ||
49 | } | ||
50 | } | ||
51 | |||
52 | function shallowCopy <T> (o: T): T { | ||
53 | return Object.assign(Object.create(Object.getPrototypeOf(o)), o) | ||
54 | } | ||
55 | |||
56 | function simpleObjectsDeepEqual (a: any, b: any) { | ||
57 | if (a === b) return true | ||
58 | |||
59 | if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) { | ||
60 | return false | ||
61 | } | ||
62 | |||
63 | const keysA = Object.keys(a) | ||
64 | const keysB = Object.keys(b) | ||
65 | |||
66 | if (keysA.length !== keysB.length) return false | ||
67 | |||
68 | for (const key of keysA) { | ||
69 | if (!keysB.includes(key)) return false | ||
70 | |||
71 | if (!simpleObjectsDeepEqual(a[key], b[key])) return false | ||
72 | } | ||
73 | |||
74 | return true | ||
75 | } | ||
76 | |||
77 | export { | ||
78 | pick, | ||
79 | omit, | ||
80 | objectKeysTyped, | ||
81 | getKeys, | ||
82 | hasKey, | ||
83 | shallowCopy, | ||
84 | sortObjectComparator, | ||
85 | simpleObjectsDeepEqual | ||
86 | } | ||
diff --git a/shared/core-utils/common/path.ts b/shared/core-utils/common/path.ts deleted file mode 100644 index 006505316..000000000 --- a/shared/core-utils/common/path.ts +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | import { basename, extname, isAbsolute, join, resolve } from 'path' | ||
2 | |||
3 | let rootPath: string | ||
4 | |||
5 | function root () { | ||
6 | if (rootPath) return rootPath | ||
7 | |||
8 | rootPath = __dirname | ||
9 | |||
10 | if (basename(rootPath) === 'tools') rootPath = resolve(rootPath, '..') | ||
11 | if (basename(rootPath) === 'scripts') rootPath = resolve(rootPath, '..') | ||
12 | if (basename(rootPath) === 'common') rootPath = resolve(rootPath, '..') | ||
13 | if (basename(rootPath) === 'core-utils') rootPath = resolve(rootPath, '..') | ||
14 | if (basename(rootPath) === 'shared') rootPath = resolve(rootPath, '..') | ||
15 | if (basename(rootPath) === 'server') rootPath = resolve(rootPath, '..') | ||
16 | if (basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..') | ||
17 | |||
18 | return rootPath | ||
19 | } | ||
20 | |||
21 | function buildPath (path: string) { | ||
22 | if (isAbsolute(path)) return path | ||
23 | |||
24 | return join(root(), path) | ||
25 | } | ||
26 | |||
27 | function getLowercaseExtension (filename: string) { | ||
28 | const ext = extname(filename) || '' | ||
29 | |||
30 | return ext.toLowerCase() | ||
31 | } | ||
32 | |||
33 | function buildAbsoluteFixturePath (path: string, customCIPath = false) { | ||
34 | if (isAbsolute(path)) return path | ||
35 | |||
36 | if (customCIPath && process.env.GITHUB_WORKSPACE) { | ||
37 | return join(process.env.GITHUB_WORKSPACE, 'fixtures', path) | ||
38 | } | ||
39 | |||
40 | return join(root(), 'server', 'tests', 'fixtures', path) | ||
41 | } | ||
42 | |||
43 | export { | ||
44 | root, | ||
45 | buildPath, | ||
46 | buildAbsoluteFixturePath, | ||
47 | getLowercaseExtension | ||
48 | } | ||
diff --git a/shared/core-utils/common/promises.ts b/shared/core-utils/common/promises.ts deleted file mode 100644 index e3792d12e..000000000 --- a/shared/core-utils/common/promises.ts +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | export function isPromise <T = unknown> (value: T | Promise<T>): value is Promise<T> { | ||
2 | return value && typeof (value as Promise<T>).then === 'function' | ||
3 | } | ||
4 | |||
5 | export function isCatchable (value: any) { | ||
6 | return value && typeof value.catch === 'function' | ||
7 | } | ||
8 | |||
9 | export function timeoutPromise <T> (promise: Promise<T>, timeoutMs: number) { | ||
10 | let timer: ReturnType<typeof setTimeout> | ||
11 | |||
12 | return Promise.race([ | ||
13 | promise, | ||
14 | |||
15 | new Promise((_res, rej) => { | ||
16 | timer = setTimeout(() => rej(new Error('Timeout')), timeoutMs) | ||
17 | }) | ||
18 | ]).finally(() => clearTimeout(timer)) | ||
19 | } | ||
20 | |||
21 | export function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> { | ||
22 | return function promisified (): Promise<A> { | ||
23 | return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => { | ||
24 | // eslint-disable-next-line no-useless-call | ||
25 | func.apply(null, [ (err: any, res: A) => err ? reject(err) : resolve(res) ]) | ||
26 | }) | ||
27 | } | ||
28 | } | ||
29 | |||
30 | // Thanks to https://gist.github.com/kumasento/617daa7e46f13ecdd9b2 | ||
31 | export function promisify1<T, A> (func: (arg: T, cb: (err: any, result: A) => void) => void): (arg: T) => Promise<A> { | ||
32 | return function promisified (arg: T): Promise<A> { | ||
33 | return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => { | ||
34 | // eslint-disable-next-line no-useless-call | ||
35 | func.apply(null, [ arg, (err: any, res: A) => err ? reject(err) : resolve(res) ]) | ||
36 | }) | ||
37 | } | ||
38 | } | ||
39 | |||
40 | // eslint-disable-next-line max-len | ||
41 | export function promisify2<T, U, A> (func: (arg1: T, arg2: U, cb: (err: any, result: A) => void) => void): (arg1: T, arg2: U) => Promise<A> { | ||
42 | return function promisified (arg1: T, arg2: U): Promise<A> { | ||
43 | return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => { | ||
44 | // eslint-disable-next-line no-useless-call | ||
45 | func.apply(null, [ arg1, arg2, (err: any, res: A) => err ? reject(err) : resolve(res) ]) | ||
46 | }) | ||
47 | } | ||
48 | } | ||
49 | |||
50 | // eslint-disable-next-line max-len | ||
51 | export function promisify3<T, U, V, A> (func: (arg1: T, arg2: U, arg3: V, cb: (err: any, result: A) => void) => void): (arg1: T, arg2: U, arg3: V) => Promise<A> { | ||
52 | return function promisified (arg1: T, arg2: U, arg3: V): Promise<A> { | ||
53 | return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => { | ||
54 | // eslint-disable-next-line no-useless-call | ||
55 | func.apply(null, [ arg1, arg2, arg3, (err: any, res: A) => err ? reject(err) : resolve(res) ]) | ||
56 | }) | ||
57 | } | ||
58 | } | ||
diff --git a/shared/core-utils/common/random.ts b/shared/core-utils/common/random.ts deleted file mode 100644 index 705735d09..000000000 --- a/shared/core-utils/common/random.ts +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | // high excluded | ||
2 | function randomInt (low: number, high: number) { | ||
3 | return Math.floor(Math.random() * (high - low) + low) | ||
4 | } | ||
5 | |||
6 | export { | ||
7 | randomInt | ||
8 | } | ||
diff --git a/shared/core-utils/common/regexp.ts b/shared/core-utils/common/regexp.ts deleted file mode 100644 index 59eb87eb6..000000000 --- a/shared/core-utils/common/regexp.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' | ||
2 | |||
3 | export function removeFragmentedMP4Ext (path: string) { | ||
4 | return path.replace(/-fragmented.mp4$/i, '') | ||
5 | } | ||
diff --git a/shared/core-utils/common/time.ts b/shared/core-utils/common/time.ts deleted file mode 100644 index 2992609ca..000000000 --- a/shared/core-utils/common/time.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | function wait (milliseconds: number) { | ||
2 | return new Promise(resolve => setTimeout(resolve, milliseconds)) | ||
3 | } | ||
4 | |||
5 | export { | ||
6 | wait | ||
7 | } | ||
diff --git a/shared/core-utils/common/url.ts b/shared/core-utils/common/url.ts deleted file mode 100644 index 33fc5ee3a..000000000 --- a/shared/core-utils/common/url.ts +++ /dev/null | |||
@@ -1,150 +0,0 @@ | |||
1 | import { Video, VideoPlaylist } from '../../models' | ||
2 | import { secondsToTime } from './date' | ||
3 | |||
4 | function addQueryParams (url: string, params: { [ id: string ]: string }) { | ||
5 | const objUrl = new URL(url) | ||
6 | |||
7 | for (const key of Object.keys(params)) { | ||
8 | objUrl.searchParams.append(key, params[key]) | ||
9 | } | ||
10 | |||
11 | return objUrl.toString() | ||
12 | } | ||
13 | |||
14 | function removeQueryParams (url: string) { | ||
15 | const objUrl = new URL(url) | ||
16 | |||
17 | objUrl.searchParams.forEach((_v, k) => objUrl.searchParams.delete(k)) | ||
18 | |||
19 | return objUrl.toString() | ||
20 | } | ||
21 | |||
22 | function buildPlaylistLink (playlist: Pick<VideoPlaylist, 'shortUUID'>, base?: string) { | ||
23 | return (base ?? window.location.origin) + buildPlaylistWatchPath(playlist) | ||
24 | } | ||
25 | |||
26 | function buildPlaylistWatchPath (playlist: Pick<VideoPlaylist, 'shortUUID'>) { | ||
27 | return '/w/p/' + playlist.shortUUID | ||
28 | } | ||
29 | |||
30 | function buildVideoWatchPath (video: Pick<Video, 'shortUUID'>) { | ||
31 | return '/w/' + video.shortUUID | ||
32 | } | ||
33 | |||
34 | function buildVideoLink (video: Pick<Video, 'shortUUID'>, base?: string) { | ||
35 | return (base ?? window.location.origin) + buildVideoWatchPath(video) | ||
36 | } | ||
37 | |||
38 | function buildPlaylistEmbedPath (playlist: Pick<VideoPlaylist, 'uuid'>) { | ||
39 | return '/video-playlists/embed/' + playlist.uuid | ||
40 | } | ||
41 | |||
42 | function buildPlaylistEmbedLink (playlist: Pick<VideoPlaylist, 'uuid'>, base?: string) { | ||
43 | return (base ?? window.location.origin) + buildPlaylistEmbedPath(playlist) | ||
44 | } | ||
45 | |||
46 | function buildVideoEmbedPath (video: Pick<Video, 'uuid'>) { | ||
47 | return '/videos/embed/' + video.uuid | ||
48 | } | ||
49 | |||
50 | function buildVideoEmbedLink (video: Pick<Video, 'uuid'>, base?: string) { | ||
51 | return (base ?? window.location.origin) + buildVideoEmbedPath(video) | ||
52 | } | ||
53 | |||
54 | function decorateVideoLink (options: { | ||
55 | url: string | ||
56 | |||
57 | startTime?: number | ||
58 | stopTime?: number | ||
59 | |||
60 | subtitle?: string | ||
61 | |||
62 | loop?: boolean | ||
63 | autoplay?: boolean | ||
64 | muted?: boolean | ||
65 | |||
66 | // Embed options | ||
67 | title?: boolean | ||
68 | warningTitle?: boolean | ||
69 | |||
70 | controls?: boolean | ||
71 | controlBar?: boolean | ||
72 | |||
73 | peertubeLink?: boolean | ||
74 | p2p?: boolean | ||
75 | }) { | ||
76 | const { url } = options | ||
77 | |||
78 | const params = new URLSearchParams() | ||
79 | |||
80 | if (options.startTime !== undefined && options.startTime !== null) { | ||
81 | const startTimeInt = Math.floor(options.startTime) | ||
82 | params.set('start', secondsToTime(startTimeInt)) | ||
83 | } | ||
84 | |||
85 | if (options.stopTime) { | ||
86 | const stopTimeInt = Math.floor(options.stopTime) | ||
87 | params.set('stop', secondsToTime(stopTimeInt)) | ||
88 | } | ||
89 | |||
90 | if (options.subtitle) params.set('subtitle', options.subtitle) | ||
91 | |||
92 | if (options.loop === true) params.set('loop', '1') | ||
93 | if (options.autoplay === true) params.set('autoplay', '1') | ||
94 | if (options.muted === true) params.set('muted', '1') | ||
95 | if (options.title === false) params.set('title', '0') | ||
96 | if (options.warningTitle === false) params.set('warningTitle', '0') | ||
97 | |||
98 | if (options.controls === false) params.set('controls', '0') | ||
99 | if (options.controlBar === false) params.set('controlBar', '0') | ||
100 | |||
101 | if (options.peertubeLink === false) params.set('peertubeLink', '0') | ||
102 | if (options.p2p !== undefined) params.set('p2p', options.p2p ? '1' : '0') | ||
103 | |||
104 | return buildUrl(url, params) | ||
105 | } | ||
106 | |||
107 | function decoratePlaylistLink (options: { | ||
108 | url: string | ||
109 | |||
110 | playlistPosition?: number | ||
111 | }) { | ||
112 | const { url } = options | ||
113 | |||
114 | const params = new URLSearchParams() | ||
115 | |||
116 | if (options.playlistPosition) params.set('playlistPosition', '' + options.playlistPosition) | ||
117 | |||
118 | return buildUrl(url, params) | ||
119 | } | ||
120 | |||
121 | // --------------------------------------------------------------------------- | ||
122 | |||
123 | export { | ||
124 | addQueryParams, | ||
125 | removeQueryParams, | ||
126 | |||
127 | buildPlaylistLink, | ||
128 | buildVideoLink, | ||
129 | |||
130 | buildVideoWatchPath, | ||
131 | buildPlaylistWatchPath, | ||
132 | |||
133 | buildPlaylistEmbedPath, | ||
134 | buildVideoEmbedPath, | ||
135 | |||
136 | buildPlaylistEmbedLink, | ||
137 | buildVideoEmbedLink, | ||
138 | |||
139 | decorateVideoLink, | ||
140 | decoratePlaylistLink | ||
141 | } | ||
142 | |||
143 | function buildUrl (url: string, params: URLSearchParams) { | ||
144 | let hasParams = false | ||
145 | params.forEach(() => { hasParams = true }) | ||
146 | |||
147 | if (hasParams) return url + '?' + params.toString() | ||
148 | |||
149 | return url | ||
150 | } | ||
diff --git a/shared/core-utils/common/version.ts b/shared/core-utils/common/version.ts deleted file mode 100644 index 305287233..000000000 --- a/shared/core-utils/common/version.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | // Thanks https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb | ||
2 | function compareSemVer (a: string, b: string) { | ||
3 | if (a.startsWith(b + '-')) return -1 | ||
4 | if (b.startsWith(a + '-')) return 1 | ||
5 | |||
6 | return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'case', caseFirst: 'upper' }) | ||
7 | } | ||
8 | |||
9 | export { | ||
10 | compareSemVer | ||
11 | } | ||
diff --git a/shared/core-utils/i18n/i18n.ts b/shared/core-utils/i18n/i18n.ts deleted file mode 100644 index 54b54077a..000000000 --- a/shared/core-utils/i18n/i18n.ts +++ /dev/null | |||
@@ -1,119 +0,0 @@ | |||
1 | export const LOCALE_FILES = [ 'player', 'server' ] | ||
2 | |||
3 | export const I18N_LOCALES = { | ||
4 | // Always first to avoid issues when using express acceptLanguages function when no accept language header is set | ||
5 | 'en-US': 'English', | ||
6 | |||
7 | // Keep it alphabetically sorted | ||
8 | 'ar': 'العربية', | ||
9 | 'ca-ES': 'Català', | ||
10 | 'cs-CZ': 'Čeština', | ||
11 | 'de-DE': 'Deutsch', | ||
12 | 'el-GR': 'ελληνικά', | ||
13 | 'eo': 'Esperanto', | ||
14 | 'es-ES': 'Español', | ||
15 | 'eu-ES': 'Euskara', | ||
16 | 'fa-IR': 'فارسی', | ||
17 | 'fi-FI': 'Suomi', | ||
18 | 'fr-FR': 'Français', | ||
19 | 'gd': 'Gàidhlig', | ||
20 | 'gl-ES': 'Galego', | ||
21 | 'hr': 'Hrvatski', | ||
22 | 'hu-HU': 'Magyar', | ||
23 | 'is': 'Íslenska', | ||
24 | 'it-IT': 'Italiano', | ||
25 | 'ja-JP': '日本語', | ||
26 | 'kab': 'Taqbaylit', | ||
27 | 'nb-NO': 'Norsk bokmål', | ||
28 | 'nl-NL': 'Nederlands', | ||
29 | 'nn': 'Norsk nynorsk', | ||
30 | 'oc': 'Occitan', | ||
31 | 'pl-PL': 'Polski', | ||
32 | 'pt-BR': 'Português (Brasil)', | ||
33 | 'pt-PT': 'Português (Portugal)', | ||
34 | 'ru-RU': 'Pусский', | ||
35 | 'sq': 'Shqip', | ||
36 | 'sv-SE': 'Svenska', | ||
37 | 'th-TH': 'ไทย', | ||
38 | 'tok': 'Toki Pona', | ||
39 | 'uk-UA': 'украї́нська мо́ва', | ||
40 | 'vi-VN': 'Tiếng Việt', | ||
41 | 'zh-Hans-CN': '简体中文(中国)', | ||
42 | 'zh-Hant-TW': '繁體中文(台灣)' | ||
43 | } | ||
44 | |||
45 | // Keep it alphabetically sorted | ||
46 | const I18N_LOCALE_ALIAS = { | ||
47 | 'ar-001': 'ar', | ||
48 | 'ca': 'ca-ES', | ||
49 | 'cs': 'cs-CZ', | ||
50 | 'de': 'de-DE', | ||
51 | 'el': 'el-GR', | ||
52 | 'en': 'en-US', | ||
53 | 'es': 'es-ES', | ||
54 | 'eu': 'eu-ES', | ||
55 | 'fa': 'fa-IR', | ||
56 | 'fi': 'fi-FI', | ||
57 | 'fr': 'fr-FR', | ||
58 | 'gl': 'gl-ES', | ||
59 | 'hu': 'hu-HU', | ||
60 | 'it': 'it-IT', | ||
61 | 'ja': 'ja-JP', | ||
62 | 'nb': 'nb-NO', | ||
63 | 'nl': 'nl-NL', | ||
64 | 'pl': 'pl-PL', | ||
65 | 'pt': 'pt-BR', | ||
66 | 'ru': 'ru-RU', | ||
67 | 'sv': 'sv-SE', | ||
68 | 'th': 'th-TH', | ||
69 | 'uk': 'uk-UA', | ||
70 | 'vi': 'vi-VN', | ||
71 | 'zh-CN': 'zh-Hans-CN', | ||
72 | 'zh-Hans': 'zh-Hans-CN', | ||
73 | 'zh-Hant': 'zh-Hant-TW', | ||
74 | 'zh-TW': 'zh-Hant-TW', | ||
75 | 'zh': 'zh-Hans-CN' | ||
76 | } | ||
77 | |||
78 | export const POSSIBLE_LOCALES = (Object.keys(I18N_LOCALES) as string[]).concat(Object.keys(I18N_LOCALE_ALIAS)) | ||
79 | |||
80 | export function getDefaultLocale () { | ||
81 | return 'en-US' | ||
82 | } | ||
83 | |||
84 | export function isDefaultLocale (locale: string) { | ||
85 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) | ||
86 | } | ||
87 | |||
88 | export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) { | ||
89 | if (!translations?.[str]) return str | ||
90 | |||
91 | return translations[str] | ||
92 | } | ||
93 | |||
94 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) | ||
95 | export function is18nPath (path: string) { | ||
96 | return possiblePaths.includes(path) | ||
97 | } | ||
98 | |||
99 | export function is18nLocale (locale: string) { | ||
100 | return POSSIBLE_LOCALES.includes(locale) | ||
101 | } | ||
102 | |||
103 | export function getCompleteLocale (locale: string) { | ||
104 | if (!locale) return locale | ||
105 | |||
106 | const found = (I18N_LOCALE_ALIAS as any)[locale] as string | ||
107 | |||
108 | return found || locale | ||
109 | } | ||
110 | |||
111 | export function getShortLocale (locale: string) { | ||
112 | if (locale.includes('-') === false) return locale | ||
113 | |||
114 | return locale.split('-')[0] | ||
115 | } | ||
116 | |||
117 | export function buildFileLocale (locale: string) { | ||
118 | return getCompleteLocale(locale) | ||
119 | } | ||
diff --git a/shared/core-utils/i18n/index.ts b/shared/core-utils/i18n/index.ts deleted file mode 100644 index 8f7cbe2c7..000000000 --- a/shared/core-utils/i18n/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './i18n' | ||
diff --git a/shared/core-utils/index.ts b/shared/core-utils/index.ts deleted file mode 100644 index 8daaa2d04..000000000 --- a/shared/core-utils/index.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | export * from './abuse' | ||
2 | export * from './common' | ||
3 | export * from './i18n' | ||
4 | export * from './plugins' | ||
5 | export * from './renderer' | ||
6 | export * from './users' | ||
7 | export * from './videos' | ||
diff --git a/shared/core-utils/plugins/hooks.ts b/shared/core-utils/plugins/hooks.ts deleted file mode 100644 index 96bcc945e..000000000 --- a/shared/core-utils/plugins/hooks.ts +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | import { RegisteredExternalAuthConfig } from '@shared/models' | ||
2 | import { HookType } from '../../models/plugins/hook-type.enum' | ||
3 | import { isCatchable, isPromise } from '../common/promises' | ||
4 | |||
5 | function getHookType (hookName: string) { | ||
6 | if (hookName.startsWith('filter:')) return HookType.FILTER | ||
7 | if (hookName.startsWith('action:')) return HookType.ACTION | ||
8 | |||
9 | return HookType.STATIC | ||
10 | } | ||
11 | |||
12 | async function internalRunHook <T> (options: { | ||
13 | handler: Function | ||
14 | hookType: HookType | ||
15 | result: T | ||
16 | params: any | ||
17 | onError: (err: Error) => void | ||
18 | }) { | ||
19 | const { handler, hookType, result, params, onError } = options | ||
20 | |||
21 | try { | ||
22 | if (hookType === HookType.FILTER) { | ||
23 | const p = handler(result, params) | ||
24 | |||
25 | const newResult = isPromise(p) | ||
26 | ? await p | ||
27 | : p | ||
28 | |||
29 | return newResult | ||
30 | } | ||
31 | |||
32 | // Action/static hooks do not have result value | ||
33 | const p = handler(params) | ||
34 | |||
35 | if (hookType === HookType.STATIC) { | ||
36 | if (isPromise(p)) await p | ||
37 | |||
38 | return undefined | ||
39 | } | ||
40 | |||
41 | if (hookType === HookType.ACTION) { | ||
42 | if (isCatchable(p)) p.catch((err: any) => onError(err)) | ||
43 | |||
44 | return undefined | ||
45 | } | ||
46 | } catch (err) { | ||
47 | onError(err) | ||
48 | } | ||
49 | |||
50 | return result | ||
51 | } | ||
52 | |||
53 | function getExternalAuthHref (apiUrl: string, auth: RegisteredExternalAuthConfig) { | ||
54 | return apiUrl + `/plugins/${auth.name}/${auth.version}/auth/${auth.authName}` | ||
55 | } | ||
56 | |||
57 | export { | ||
58 | getHookType, | ||
59 | internalRunHook, | ||
60 | getExternalAuthHref | ||
61 | } | ||
diff --git a/shared/core-utils/plugins/index.ts b/shared/core-utils/plugins/index.ts deleted file mode 100644 index fc78d3512..000000000 --- a/shared/core-utils/plugins/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './hooks' | ||
diff --git a/shared/core-utils/renderer/html.ts b/shared/core-utils/renderer/html.ts deleted file mode 100644 index 365bf7612..000000000 --- a/shared/core-utils/renderer/html.ts +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | export function getDefaultSanitizeOptions () { | ||
2 | return { | ||
3 | allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ], | ||
4 | allowedSchemes: [ 'http', 'https' ], | ||
5 | allowedAttributes: { | ||
6 | 'a': [ 'href', 'class', 'target', 'rel' ], | ||
7 | '*': [ 'data-*' ] | ||
8 | }, | ||
9 | transformTags: { | ||
10 | a: (tagName: string, attribs: any) => { | ||
11 | let rel = 'noopener noreferrer' | ||
12 | if (attribs.rel === 'me') rel += ' me' | ||
13 | |||
14 | return { | ||
15 | tagName, | ||
16 | attribs: Object.assign(attribs, { | ||
17 | target: '_blank', | ||
18 | rel | ||
19 | }) | ||
20 | } | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | } | ||
25 | |||
26 | export function getTextOnlySanitizeOptions () { | ||
27 | return { | ||
28 | allowedTags: [] as string[] | ||
29 | } | ||
30 | } | ||
31 | |||
32 | export function getCustomMarkupSanitizeOptions (additionalAllowedTags: string[] = []) { | ||
33 | const base = getDefaultSanitizeOptions() | ||
34 | |||
35 | return { | ||
36 | allowedTags: [ | ||
37 | ...base.allowedTags, | ||
38 | ...additionalAllowedTags, | ||
39 | 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img' | ||
40 | ], | ||
41 | allowedSchemes: [ | ||
42 | ...base.allowedSchemes, | ||
43 | |||
44 | 'mailto' | ||
45 | ], | ||
46 | allowedAttributes: { | ||
47 | ...base.allowedAttributes, | ||
48 | |||
49 | 'img': [ 'src', 'alt' ], | ||
50 | '*': [ 'data-*', 'style' ] | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | // Thanks: https://stackoverflow.com/a/12034334 | ||
56 | export function escapeHTML (stringParam: string) { | ||
57 | if (!stringParam) return '' | ||
58 | |||
59 | const entityMap: { [id: string ]: string } = { | ||
60 | '&': '&', | ||
61 | '<': '<', | ||
62 | '>': '>', | ||
63 | '"': '"', | ||
64 | '\'': ''', | ||
65 | '/': '/', | ||
66 | '`': '`', | ||
67 | '=': '=' | ||
68 | } | ||
69 | |||
70 | return String(stringParam).replace(/[&<>"'`=/]/g, s => entityMap[s]) | ||
71 | } | ||
diff --git a/shared/core-utils/renderer/index.ts b/shared/core-utils/renderer/index.ts deleted file mode 100644 index 0ad29d782..000000000 --- a/shared/core-utils/renderer/index.ts +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | export * from './markdown' | ||
2 | export * from './html' | ||
diff --git a/shared/core-utils/renderer/markdown.ts b/shared/core-utils/renderer/markdown.ts deleted file mode 100644 index ddf608d7b..000000000 --- a/shared/core-utils/renderer/markdown.ts +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | export const TEXT_RULES = [ | ||
2 | 'linkify', | ||
3 | 'autolink', | ||
4 | 'emphasis', | ||
5 | 'link', | ||
6 | 'newline', | ||
7 | 'entity', | ||
8 | 'list' | ||
9 | ] | ||
10 | |||
11 | export const TEXT_WITH_HTML_RULES = TEXT_RULES.concat([ | ||
12 | 'html_inline', | ||
13 | 'html_block' | ||
14 | ]) | ||
15 | |||
16 | export const ENHANCED_RULES = TEXT_RULES.concat([ 'image' ]) | ||
17 | export const ENHANCED_WITH_HTML_RULES = TEXT_WITH_HTML_RULES.concat([ 'image' ]) | ||
18 | |||
19 | export const COMPLETE_RULES = ENHANCED_WITH_HTML_RULES.concat([ | ||
20 | 'block', | ||
21 | 'inline', | ||
22 | 'heading', | ||
23 | 'paragraph' | ||
24 | ]) | ||
diff --git a/shared/core-utils/users/index.ts b/shared/core-utils/users/index.ts deleted file mode 100644 index 1cbf0af1b..000000000 --- a/shared/core-utils/users/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './user-role' | ||
diff --git a/shared/core-utils/users/user-role.ts b/shared/core-utils/users/user-role.ts deleted file mode 100644 index 5f3b9a10f..000000000 --- a/shared/core-utils/users/user-role.ts +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | import { UserRight, UserRole } from '../../models/users' | ||
2 | |||
3 | export const USER_ROLE_LABELS: { [ id in UserRole ]: string } = { | ||
4 | [UserRole.USER]: 'User', | ||
5 | [UserRole.MODERATOR]: 'Moderator', | ||
6 | [UserRole.ADMINISTRATOR]: 'Administrator' | ||
7 | } | ||
8 | |||
9 | const userRoleRights: { [ id in UserRole ]: UserRight[] } = { | ||
10 | [UserRole.ADMINISTRATOR]: [ | ||
11 | UserRight.ALL | ||
12 | ], | ||
13 | |||
14 | [UserRole.MODERATOR]: [ | ||
15 | UserRight.MANAGE_VIDEO_BLACKLIST, | ||
16 | UserRight.MANAGE_ABUSES, | ||
17 | UserRight.MANAGE_ANY_VIDEO_CHANNEL, | ||
18 | UserRight.REMOVE_ANY_VIDEO, | ||
19 | UserRight.REMOVE_ANY_VIDEO_PLAYLIST, | ||
20 | UserRight.REMOVE_ANY_VIDEO_COMMENT, | ||
21 | UserRight.UPDATE_ANY_VIDEO, | ||
22 | UserRight.SEE_ALL_VIDEOS, | ||
23 | UserRight.MANAGE_ACCOUNTS_BLOCKLIST, | ||
24 | UserRight.MANAGE_SERVERS_BLOCKLIST, | ||
25 | UserRight.MANAGE_USERS, | ||
26 | UserRight.SEE_ALL_COMMENTS, | ||
27 | UserRight.MANAGE_REGISTRATIONS | ||
28 | ], | ||
29 | |||
30 | [UserRole.USER]: [] | ||
31 | } | ||
32 | |||
33 | export function hasUserRight (userRole: UserRole, userRight: UserRight) { | ||
34 | const userRights = userRoleRights[userRole] | ||
35 | |||
36 | return userRights.includes(UserRight.ALL) || userRights.includes(userRight) | ||
37 | } | ||
diff --git a/shared/core-utils/videos/bitrate.ts b/shared/core-utils/videos/bitrate.ts deleted file mode 100644 index 6be027826..000000000 --- a/shared/core-utils/videos/bitrate.ts +++ /dev/null | |||
@@ -1,113 +0,0 @@ | |||
1 | import { VideoResolution } from '@shared/models' | ||
2 | |||
3 | type BitPerPixel = { [ id in VideoResolution ]: number } | ||
4 | |||
5 | // https://bitmovin.com/video-bitrate-streaming-hls-dash/ | ||
6 | |||
7 | const minLimitBitPerPixel: BitPerPixel = { | ||
8 | [VideoResolution.H_NOVIDEO]: 0, | ||
9 | [VideoResolution.H_144P]: 0.02, | ||
10 | [VideoResolution.H_240P]: 0.02, | ||
11 | [VideoResolution.H_360P]: 0.02, | ||
12 | [VideoResolution.H_480P]: 0.02, | ||
13 | [VideoResolution.H_720P]: 0.02, | ||
14 | [VideoResolution.H_1080P]: 0.02, | ||
15 | [VideoResolution.H_1440P]: 0.02, | ||
16 | [VideoResolution.H_4K]: 0.02 | ||
17 | } | ||
18 | |||
19 | const averageBitPerPixel: BitPerPixel = { | ||
20 | [VideoResolution.H_NOVIDEO]: 0, | ||
21 | [VideoResolution.H_144P]: 0.19, | ||
22 | [VideoResolution.H_240P]: 0.17, | ||
23 | [VideoResolution.H_360P]: 0.15, | ||
24 | [VideoResolution.H_480P]: 0.12, | ||
25 | [VideoResolution.H_720P]: 0.11, | ||
26 | [VideoResolution.H_1080P]: 0.10, | ||
27 | [VideoResolution.H_1440P]: 0.09, | ||
28 | [VideoResolution.H_4K]: 0.08 | ||
29 | } | ||
30 | |||
31 | const maxBitPerPixel: BitPerPixel = { | ||
32 | [VideoResolution.H_NOVIDEO]: 0, | ||
33 | [VideoResolution.H_144P]: 0.32, | ||
34 | [VideoResolution.H_240P]: 0.29, | ||
35 | [VideoResolution.H_360P]: 0.26, | ||
36 | [VideoResolution.H_480P]: 0.22, | ||
37 | [VideoResolution.H_720P]: 0.19, | ||
38 | [VideoResolution.H_1080P]: 0.17, | ||
39 | [VideoResolution.H_1440P]: 0.16, | ||
40 | [VideoResolution.H_4K]: 0.14 | ||
41 | } | ||
42 | |||
43 | function getAverageTheoreticalBitrate (options: { | ||
44 | resolution: VideoResolution | ||
45 | ratio: number | ||
46 | fps: number | ||
47 | }) { | ||
48 | const targetBitrate = calculateBitrate({ ...options, bitPerPixel: averageBitPerPixel }) | ||
49 | if (!targetBitrate) return 192 * 1000 | ||
50 | |||
51 | return targetBitrate | ||
52 | } | ||
53 | |||
54 | function getMaxTheoreticalBitrate (options: { | ||
55 | resolution: VideoResolution | ||
56 | ratio: number | ||
57 | fps: number | ||
58 | }) { | ||
59 | const targetBitrate = calculateBitrate({ ...options, bitPerPixel: maxBitPerPixel }) | ||
60 | if (!targetBitrate) return 256 * 1000 | ||
61 | |||
62 | return targetBitrate | ||
63 | } | ||
64 | |||
65 | function getMinTheoreticalBitrate (options: { | ||
66 | resolution: VideoResolution | ||
67 | ratio: number | ||
68 | fps: number | ||
69 | }) { | ||
70 | const minLimitBitrate = calculateBitrate({ ...options, bitPerPixel: minLimitBitPerPixel }) | ||
71 | if (!minLimitBitrate) return 10 * 1000 | ||
72 | |||
73 | return minLimitBitrate | ||
74 | } | ||
75 | |||
76 | // --------------------------------------------------------------------------- | ||
77 | |||
78 | export { | ||
79 | getAverageTheoreticalBitrate, | ||
80 | getMaxTheoreticalBitrate, | ||
81 | getMinTheoreticalBitrate | ||
82 | } | ||
83 | |||
84 | // --------------------------------------------------------------------------- | ||
85 | |||
86 | function calculateBitrate (options: { | ||
87 | bitPerPixel: BitPerPixel | ||
88 | resolution: VideoResolution | ||
89 | ratio: number | ||
90 | fps: number | ||
91 | }) { | ||
92 | const { bitPerPixel, resolution, ratio, fps } = options | ||
93 | |||
94 | const resolutionsOrder = [ | ||
95 | VideoResolution.H_4K, | ||
96 | VideoResolution.H_1440P, | ||
97 | VideoResolution.H_1080P, | ||
98 | VideoResolution.H_720P, | ||
99 | VideoResolution.H_480P, | ||
100 | VideoResolution.H_360P, | ||
101 | VideoResolution.H_240P, | ||
102 | VideoResolution.H_144P, | ||
103 | VideoResolution.H_NOVIDEO | ||
104 | ] | ||
105 | |||
106 | for (const toTestResolution of resolutionsOrder) { | ||
107 | if (toTestResolution <= resolution) { | ||
108 | return Math.floor(resolution * resolution * ratio * fps * bitPerPixel[toTestResolution]) | ||
109 | } | ||
110 | } | ||
111 | |||
112 | throw new Error('Unknown resolution ' + resolution) | ||
113 | } | ||
diff --git a/shared/core-utils/videos/common.ts b/shared/core-utils/videos/common.ts deleted file mode 100644 index 0431edaaf..000000000 --- a/shared/core-utils/videos/common.ts +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | import { VideoStreamingPlaylistType } from '@shared/models' | ||
2 | import { VideoPrivacy } from '../../models/videos/video-privacy.enum' | ||
3 | import { VideoDetails } from '../../models/videos/video.model' | ||
4 | |||
5 | function getAllPrivacies () { | ||
6 | return [ VideoPrivacy.PUBLIC, VideoPrivacy.INTERNAL, VideoPrivacy.PRIVATE, VideoPrivacy.UNLISTED, VideoPrivacy.PASSWORD_PROTECTED ] | ||
7 | } | ||
8 | |||
9 | function getAllFiles (video: Partial<Pick<VideoDetails, 'files' | 'streamingPlaylists'>>) { | ||
10 | const files = video.files | ||
11 | |||
12 | const hls = getHLS(video) | ||
13 | if (hls) return files.concat(hls.files) | ||
14 | |||
15 | return files | ||
16 | } | ||
17 | |||
18 | function getHLS (video: Partial<Pick<VideoDetails, 'streamingPlaylists'>>) { | ||
19 | return video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | ||
20 | } | ||
21 | |||
22 | export { | ||
23 | getAllPrivacies, | ||
24 | getAllFiles, | ||
25 | getHLS | ||
26 | } | ||
diff --git a/shared/core-utils/videos/index.ts b/shared/core-utils/videos/index.ts deleted file mode 100644 index 2cf319395..000000000 --- a/shared/core-utils/videos/index.ts +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | export * from './bitrate' | ||
2 | export * from './common' | ||
diff --git a/shared/extra-utils/crypto.ts b/shared/extra-utils/crypto.ts deleted file mode 100644 index 1a583f1a0..000000000 --- a/shared/extra-utils/crypto.ts +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | import { BinaryToTextEncoding, createHash } from 'crypto' | ||
2 | |||
3 | function sha256 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') { | ||
4 | return createHash('sha256').update(str).digest(encoding) | ||
5 | } | ||
6 | |||
7 | function sha1 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') { | ||
8 | return createHash('sha1').update(str).digest(encoding) | ||
9 | } | ||
10 | |||
11 | // high excluded | ||
12 | function randomInt (low: number, high: number) { | ||
13 | return Math.floor(Math.random() * (high - low) + low) | ||
14 | } | ||
15 | |||
16 | export { | ||
17 | randomInt, | ||
18 | sha256, | ||
19 | sha1 | ||
20 | } | ||
diff --git a/shared/extra-utils/file.ts b/shared/extra-utils/file.ts deleted file mode 100644 index 8060ab520..000000000 --- a/shared/extra-utils/file.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | import { stat } from 'fs-extra' | ||
2 | |||
3 | async function getFileSize (path: string) { | ||
4 | const stats = await stat(path) | ||
5 | |||
6 | return stats.size | ||
7 | } | ||
8 | |||
9 | export { | ||
10 | getFileSize | ||
11 | } | ||
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts deleted file mode 100644 index d4cfcbec8..000000000 --- a/shared/extra-utils/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './crypto' | ||
2 | export * from './file' | ||
3 | export * from './uuid' | ||
diff --git a/shared/extra-utils/uuid.ts b/shared/extra-utils/uuid.ts deleted file mode 100644 index f3c80e046..000000000 --- a/shared/extra-utils/uuid.ts +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | import short, { uuid } from 'short-uuid' | ||
2 | |||
3 | const translator = short() | ||
4 | |||
5 | function buildUUID () { | ||
6 | return uuid() | ||
7 | } | ||
8 | |||
9 | function uuidToShort (uuid: string) { | ||
10 | if (!uuid) return uuid | ||
11 | |||
12 | return translator.fromUUID(uuid) | ||
13 | } | ||
14 | |||
15 | function shortToUUID (shortUUID: string) { | ||
16 | if (!shortUUID) return shortUUID | ||
17 | |||
18 | return translator.toUUID(shortUUID) | ||
19 | } | ||
20 | |||
21 | function isShortUUID (value: string) { | ||
22 | if (!value) return false | ||
23 | |||
24 | return value.length === translator.maxLength | ||
25 | } | ||
26 | |||
27 | export { | ||
28 | buildUUID, | ||
29 | uuidToShort, | ||
30 | shortToUUID, | ||
31 | isShortUUID | ||
32 | } | ||
diff --git a/shared/ffmpeg/ffmpeg-command-wrapper.ts b/shared/ffmpeg/ffmpeg-command-wrapper.ts deleted file mode 100644 index efb75c198..000000000 --- a/shared/ffmpeg/ffmpeg-command-wrapper.ts +++ /dev/null | |||
@@ -1,246 +0,0 @@ | |||
1 | import ffmpeg, { FfmpegCommand, getAvailableEncoders } from 'fluent-ffmpeg' | ||
2 | import { pick, promisify0 } from '@shared/core-utils' | ||
3 | import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptionsBuilderParams, EncoderProfile } from '@shared/models' | ||
4 | |||
5 | type FFmpegLogger = { | ||
6 | info: (msg: string, obj?: any) => void | ||
7 | debug: (msg: string, obj?: any) => void | ||
8 | warn: (msg: string, obj?: any) => void | ||
9 | error: (msg: string, obj?: any) => void | ||
10 | } | ||
11 | |||
12 | export interface FFmpegCommandWrapperOptions { | ||
13 | availableEncoders?: AvailableEncoders | ||
14 | profile?: string | ||
15 | |||
16 | niceness: number | ||
17 | tmpDirectory: string | ||
18 | threads: number | ||
19 | |||
20 | logger: FFmpegLogger | ||
21 | lTags?: { tags: string[] } | ||
22 | |||
23 | updateJobProgress?: (progress?: number) => void | ||
24 | onEnd?: () => void | ||
25 | onError?: (err: Error) => void | ||
26 | } | ||
27 | |||
28 | export class FFmpegCommandWrapper { | ||
29 | private static supportedEncoders: Map<string, boolean> | ||
30 | |||
31 | private readonly availableEncoders: AvailableEncoders | ||
32 | private readonly profile: string | ||
33 | |||
34 | private readonly niceness: number | ||
35 | private readonly tmpDirectory: string | ||
36 | private readonly threads: number | ||
37 | |||
38 | private readonly logger: FFmpegLogger | ||
39 | private readonly lTags: { tags: string[] } | ||
40 | |||
41 | private readonly updateJobProgress: (progress?: number) => void | ||
42 | private readonly onEnd?: () => void | ||
43 | private readonly onError?: (err: Error) => void | ||
44 | |||
45 | private command: FfmpegCommand | ||
46 | |||
47 | constructor (options: FFmpegCommandWrapperOptions) { | ||
48 | this.availableEncoders = options.availableEncoders | ||
49 | this.profile = options.profile | ||
50 | this.niceness = options.niceness | ||
51 | this.tmpDirectory = options.tmpDirectory | ||
52 | this.threads = options.threads | ||
53 | this.logger = options.logger | ||
54 | this.lTags = options.lTags || { tags: [] } | ||
55 | |||
56 | this.updateJobProgress = options.updateJobProgress | ||
57 | |||
58 | this.onEnd = options.onEnd | ||
59 | this.onError = options.onError | ||
60 | } | ||
61 | |||
62 | getAvailableEncoders () { | ||
63 | return this.availableEncoders | ||
64 | } | ||
65 | |||
66 | getProfile () { | ||
67 | return this.profile | ||
68 | } | ||
69 | |||
70 | getCommand () { | ||
71 | return this.command | ||
72 | } | ||
73 | |||
74 | // --------------------------------------------------------------------------- | ||
75 | |||
76 | debugLog (msg: string, meta: any) { | ||
77 | this.logger.debug(msg, { ...meta, ...this.lTags }) | ||
78 | } | ||
79 | |||
80 | // --------------------------------------------------------------------------- | ||
81 | |||
82 | buildCommand (input: string) { | ||
83 | if (this.command) throw new Error('Command is already built') | ||
84 | |||
85 | // We set cwd explicitly because ffmpeg appears to create temporary files when trancoding which fails in read-only file systems | ||
86 | this.command = ffmpeg(input, { | ||
87 | niceness: this.niceness, | ||
88 | cwd: this.tmpDirectory | ||
89 | }) | ||
90 | |||
91 | if (this.threads > 0) { | ||
92 | // If we don't set any threads ffmpeg will chose automatically | ||
93 | this.command.outputOption('-threads ' + this.threads) | ||
94 | } | ||
95 | |||
96 | return this.command | ||
97 | } | ||
98 | |||
99 | async runCommand (options: { | ||
100 | silent?: boolean // false by default | ||
101 | } = {}) { | ||
102 | const { silent = false } = options | ||
103 | |||
104 | return new Promise<void>((res, rej) => { | ||
105 | let shellCommand: string | ||
106 | |||
107 | this.command.on('start', cmdline => { shellCommand = cmdline }) | ||
108 | |||
109 | this.command.on('error', (err, stdout, stderr) => { | ||
110 | if (silent !== true) this.logger.error('Error in ffmpeg.', { stdout, stderr, shellCommand, ...this.lTags }) | ||
111 | |||
112 | if (this.onError) this.onError(err) | ||
113 | |||
114 | rej(err) | ||
115 | }) | ||
116 | |||
117 | this.command.on('end', (stdout, stderr) => { | ||
118 | this.logger.debug('FFmpeg command ended.', { stdout, stderr, shellCommand, ...this.lTags }) | ||
119 | |||
120 | if (this.onEnd) this.onEnd() | ||
121 | |||
122 | res() | ||
123 | }) | ||
124 | |||
125 | if (this.updateJobProgress) { | ||
126 | this.command.on('progress', progress => { | ||
127 | if (!progress.percent) return | ||
128 | |||
129 | // Sometimes ffmpeg returns an invalid progress | ||
130 | let percent = Math.round(progress.percent) | ||
131 | if (percent < 0) percent = 0 | ||
132 | if (percent > 100) percent = 100 | ||
133 | |||
134 | this.updateJobProgress(percent) | ||
135 | }) | ||
136 | } | ||
137 | |||
138 | this.command.run() | ||
139 | }) | ||
140 | } | ||
141 | |||
142 | // --------------------------------------------------------------------------- | ||
143 | |||
144 | static resetSupportedEncoders () { | ||
145 | FFmpegCommandWrapper.supportedEncoders = undefined | ||
146 | } | ||
147 | |||
148 | // Run encoder builder depending on available encoders | ||
149 | // Try encoders by priority: if the encoder is available, run the chosen profile or fallback to the default one | ||
150 | // If the default one does not exist, check the next encoder | ||
151 | async getEncoderBuilderResult (options: EncoderOptionsBuilderParams & { | ||
152 | streamType: 'video' | 'audio' | ||
153 | input: string | ||
154 | |||
155 | videoType: 'vod' | 'live' | ||
156 | }) { | ||
157 | if (!this.availableEncoders) { | ||
158 | throw new Error('There is no available encoders') | ||
159 | } | ||
160 | |||
161 | const { streamType, videoType } = options | ||
162 | |||
163 | const encodersToTry = this.availableEncoders.encodersToTry[videoType][streamType] | ||
164 | const encoders = this.availableEncoders.available[videoType] | ||
165 | |||
166 | for (const encoder of encodersToTry) { | ||
167 | if (!(await this.checkFFmpegEncoders(this.availableEncoders)).get(encoder)) { | ||
168 | this.logger.debug(`Encoder ${encoder} not available in ffmpeg, skipping.`, this.lTags) | ||
169 | continue | ||
170 | } | ||
171 | |||
172 | if (!encoders[encoder]) { | ||
173 | this.logger.debug(`Encoder ${encoder} not available in peertube encoders, skipping.`, this.lTags) | ||
174 | continue | ||
175 | } | ||
176 | |||
177 | // An object containing available profiles for this encoder | ||
178 | const builderProfiles: EncoderProfile<EncoderOptionsBuilder> = encoders[encoder] | ||
179 | let builder = builderProfiles[this.profile] | ||
180 | |||
181 | if (!builder) { | ||
182 | this.logger.debug(`Profile ${this.profile} for encoder ${encoder} not available. Fallback to default.`, this.lTags) | ||
183 | builder = builderProfiles.default | ||
184 | |||
185 | if (!builder) { | ||
186 | this.logger.debug(`Default profile for encoder ${encoder} not available. Try next available encoder.`, this.lTags) | ||
187 | continue | ||
188 | } | ||
189 | } | ||
190 | |||
191 | const result = await builder( | ||
192 | pick(options, [ | ||
193 | 'input', | ||
194 | 'canCopyAudio', | ||
195 | 'canCopyVideo', | ||
196 | 'resolution', | ||
197 | 'inputBitrate', | ||
198 | 'fps', | ||
199 | 'inputRatio', | ||
200 | 'streamNum' | ||
201 | ]) | ||
202 | ) | ||
203 | |||
204 | return { | ||
205 | result, | ||
206 | |||
207 | // If we don't have output options, then copy the input stream | ||
208 | encoder: result.copy === true | ||
209 | ? 'copy' | ||
210 | : encoder | ||
211 | } | ||
212 | } | ||
213 | |||
214 | return null | ||
215 | } | ||
216 | |||
217 | // Detect supported encoders by ffmpeg | ||
218 | private async checkFFmpegEncoders (peertubeAvailableEncoders: AvailableEncoders): Promise<Map<string, boolean>> { | ||
219 | if (FFmpegCommandWrapper.supportedEncoders !== undefined) { | ||
220 | return FFmpegCommandWrapper.supportedEncoders | ||
221 | } | ||
222 | |||
223 | const getAvailableEncodersPromise = promisify0(getAvailableEncoders) | ||
224 | const availableFFmpegEncoders = await getAvailableEncodersPromise() | ||
225 | |||
226 | const searchEncoders = new Set<string>() | ||
227 | for (const type of [ 'live', 'vod' ]) { | ||
228 | for (const streamType of [ 'audio', 'video' ]) { | ||
229 | for (const encoder of peertubeAvailableEncoders.encodersToTry[type][streamType]) { | ||
230 | searchEncoders.add(encoder) | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | |||
235 | const supportedEncoders = new Map<string, boolean>() | ||
236 | |||
237 | for (const searchEncoder of searchEncoders) { | ||
238 | supportedEncoders.set(searchEncoder, availableFFmpegEncoders[searchEncoder] !== undefined) | ||
239 | } | ||
240 | |||
241 | this.logger.info('Built supported ffmpeg encoders.', { supportedEncoders, searchEncoders, ...this.lTags }) | ||
242 | |||
243 | FFmpegCommandWrapper.supportedEncoders = supportedEncoders | ||
244 | return supportedEncoders | ||
245 | } | ||
246 | } | ||
diff --git a/shared/ffmpeg/ffmpeg-default-transcoding-profile.ts b/shared/ffmpeg/ffmpeg-default-transcoding-profile.ts deleted file mode 100644 index 8a3f32011..000000000 --- a/shared/ffmpeg/ffmpeg-default-transcoding-profile.ts +++ /dev/null | |||
@@ -1,187 +0,0 @@ | |||
1 | import { FfprobeData } from 'fluent-ffmpeg' | ||
2 | import { getAverageTheoreticalBitrate, getMaxTheoreticalBitrate, getMinTheoreticalBitrate } from '@shared/core-utils' | ||
3 | import { | ||
4 | buildStreamSuffix, | ||
5 | ffprobePromise, | ||
6 | getAudioStream, | ||
7 | getMaxAudioBitrate, | ||
8 | getVideoStream, | ||
9 | getVideoStreamBitrate, | ||
10 | getVideoStreamDimensionsInfo, | ||
11 | getVideoStreamFPS | ||
12 | } from '@shared/ffmpeg' | ||
13 | import { EncoderOptionsBuilder, EncoderOptionsBuilderParams, VideoResolution } from '@shared/models' | ||
14 | |||
15 | const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => { | ||
16 | const { fps, inputRatio, inputBitrate, resolution } = options | ||
17 | |||
18 | const targetBitrate = getTargetBitrate({ inputBitrate, ratio: inputRatio, fps, resolution }) | ||
19 | |||
20 | return { | ||
21 | outputOptions: [ | ||
22 | ...getCommonOutputOptions(targetBitrate), | ||
23 | |||
24 | `-r ${fps}` | ||
25 | ] | ||
26 | } | ||
27 | } | ||
28 | |||
29 | const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => { | ||
30 | const { streamNum, fps, inputBitrate, inputRatio, resolution } = options | ||
31 | |||
32 | const targetBitrate = getTargetBitrate({ inputBitrate, ratio: inputRatio, fps, resolution }) | ||
33 | |||
34 | return { | ||
35 | outputOptions: [ | ||
36 | ...getCommonOutputOptions(targetBitrate, streamNum), | ||
37 | |||
38 | `${buildStreamSuffix('-r:v', streamNum)} ${fps}`, | ||
39 | `${buildStreamSuffix('-b:v', streamNum)} ${targetBitrate}` | ||
40 | ] | ||
41 | } | ||
42 | } | ||
43 | |||
44 | const defaultAACOptionsBuilder: EncoderOptionsBuilder = async ({ input, streamNum, canCopyAudio }) => { | ||
45 | const probe = await ffprobePromise(input) | ||
46 | |||
47 | if (canCopyAudio && await canDoQuickAudioTranscode(input, probe)) { | ||
48 | return { copy: true, outputOptions: [ ] } | ||
49 | } | ||
50 | |||
51 | const parsedAudio = await getAudioStream(input, probe) | ||
52 | |||
53 | // We try to reduce the ceiling bitrate by making rough matches of bitrates | ||
54 | // Of course this is far from perfect, but it might save some space in the end | ||
55 | |||
56 | const audioCodecName = parsedAudio.audioStream['codec_name'] | ||
57 | |||
58 | const bitrate = getMaxAudioBitrate(audioCodecName, parsedAudio.bitrate) | ||
59 | |||
60 | // Force stereo as it causes some issues with HLS playback in Chrome | ||
61 | const base = [ '-channel_layout', 'stereo' ] | ||
62 | |||
63 | if (bitrate !== -1) { | ||
64 | return { outputOptions: base.concat([ buildStreamSuffix('-b:a', streamNum), bitrate + 'k' ]) } | ||
65 | } | ||
66 | |||
67 | return { outputOptions: base } | ||
68 | } | ||
69 | |||
70 | const defaultLibFDKAACVODOptionsBuilder: EncoderOptionsBuilder = ({ streamNum }) => { | ||
71 | return { outputOptions: [ buildStreamSuffix('-q:a', streamNum), '5' ] } | ||
72 | } | ||
73 | |||
74 | export function getDefaultAvailableEncoders () { | ||
75 | return { | ||
76 | vod: { | ||
77 | libx264: { | ||
78 | default: defaultX264VODOptionsBuilder | ||
79 | }, | ||
80 | aac: { | ||
81 | default: defaultAACOptionsBuilder | ||
82 | }, | ||
83 | libfdk_aac: { | ||
84 | default: defaultLibFDKAACVODOptionsBuilder | ||
85 | } | ||
86 | }, | ||
87 | live: { | ||
88 | libx264: { | ||
89 | default: defaultX264LiveOptionsBuilder | ||
90 | }, | ||
91 | aac: { | ||
92 | default: defaultAACOptionsBuilder | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | export function getDefaultEncodersToTry () { | ||
99 | return { | ||
100 | vod: { | ||
101 | video: [ 'libx264' ], | ||
102 | audio: [ 'libfdk_aac', 'aac' ] | ||
103 | }, | ||
104 | |||
105 | live: { | ||
106 | video: [ 'libx264' ], | ||
107 | audio: [ 'libfdk_aac', 'aac' ] | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | |||
112 | export async function canDoQuickAudioTranscode (path: string, probe?: FfprobeData): Promise<boolean> { | ||
113 | const parsedAudio = await getAudioStream(path, probe) | ||
114 | |||
115 | if (!parsedAudio.audioStream) return true | ||
116 | |||
117 | if (parsedAudio.audioStream['codec_name'] !== 'aac') return false | ||
118 | |||
119 | const audioBitrate = parsedAudio.bitrate | ||
120 | if (!audioBitrate) return false | ||
121 | |||
122 | const maxAudioBitrate = getMaxAudioBitrate('aac', audioBitrate) | ||
123 | if (maxAudioBitrate !== -1 && audioBitrate > maxAudioBitrate) return false | ||
124 | |||
125 | const channelLayout = parsedAudio.audioStream['channel_layout'] | ||
126 | // Causes playback issues with Chrome | ||
127 | if (!channelLayout || channelLayout === 'unknown' || channelLayout === 'quad') return false | ||
128 | |||
129 | return true | ||
130 | } | ||
131 | |||
132 | export async function canDoQuickVideoTranscode (path: string, probe?: FfprobeData): Promise<boolean> { | ||
133 | const videoStream = await getVideoStream(path, probe) | ||
134 | const fps = await getVideoStreamFPS(path, probe) | ||
135 | const bitRate = await getVideoStreamBitrate(path, probe) | ||
136 | const resolutionData = await getVideoStreamDimensionsInfo(path, probe) | ||
137 | |||
138 | // If ffprobe did not manage to guess the bitrate | ||
139 | if (!bitRate) return false | ||
140 | |||
141 | // check video params | ||
142 | if (!videoStream) return false | ||
143 | if (videoStream['codec_name'] !== 'h264') return false | ||
144 | if (videoStream['pix_fmt'] !== 'yuv420p') return false | ||
145 | if (fps < 2 || fps > 65) return false | ||
146 | if (bitRate > getMaxTheoreticalBitrate({ ...resolutionData, fps })) return false | ||
147 | |||
148 | return true | ||
149 | } | ||
150 | |||
151 | // --------------------------------------------------------------------------- | ||
152 | |||
153 | function getTargetBitrate (options: { | ||
154 | inputBitrate: number | ||
155 | resolution: VideoResolution | ||
156 | ratio: number | ||
157 | fps: number | ||
158 | }) { | ||
159 | const { inputBitrate, resolution, ratio, fps } = options | ||
160 | |||
161 | const capped = capBitrate(inputBitrate, getAverageTheoreticalBitrate({ resolution, fps, ratio })) | ||
162 | const limit = getMinTheoreticalBitrate({ resolution, fps, ratio }) | ||
163 | |||
164 | return Math.max(limit, capped) | ||
165 | } | ||
166 | |||
167 | function capBitrate (inputBitrate: number, targetBitrate: number) { | ||
168 | if (!inputBitrate) return targetBitrate | ||
169 | |||
170 | // Add 30% margin to input bitrate | ||
171 | const inputBitrateWithMargin = inputBitrate + (inputBitrate * 0.3) | ||
172 | |||
173 | return Math.min(targetBitrate, inputBitrateWithMargin) | ||
174 | } | ||
175 | |||
176 | function getCommonOutputOptions (targetBitrate: number, streamNum?: number) { | ||
177 | return [ | ||
178 | `-preset veryfast`, | ||
179 | `${buildStreamSuffix('-maxrate:v', streamNum)} ${targetBitrate}`, | ||
180 | `${buildStreamSuffix('-bufsize:v', streamNum)} ${targetBitrate * 2}`, | ||
181 | |||
182 | // NOTE: b-strategy 1 - heuristic algorithm, 16 is optimal B-frames for it | ||
183 | `-b_strategy 1`, | ||
184 | // NOTE: Why 16: https://github.com/Chocobozzz/PeerTube/pull/774. b-strategy 2 -> B-frames<16 | ||
185 | `-bf 16` | ||
186 | ] | ||
187 | } | ||
diff --git a/shared/ffmpeg/ffmpeg-edition.ts b/shared/ffmpeg/ffmpeg-edition.ts deleted file mode 100644 index 724ca1ea9..000000000 --- a/shared/ffmpeg/ffmpeg-edition.ts +++ /dev/null | |||
@@ -1,239 +0,0 @@ | |||
1 | import { FilterSpecification } from 'fluent-ffmpeg' | ||
2 | import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper' | ||
3 | import { presetVOD } from './shared/presets' | ||
4 | import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamDuration, getVideoStreamFPS, hasAudioStream } from './ffprobe' | ||
5 | |||
6 | export class FFmpegEdition { | ||
7 | private readonly commandWrapper: FFmpegCommandWrapper | ||
8 | |||
9 | constructor (options: FFmpegCommandWrapperOptions) { | ||
10 | this.commandWrapper = new FFmpegCommandWrapper(options) | ||
11 | } | ||
12 | |||
13 | async cutVideo (options: { | ||
14 | inputPath: string | ||
15 | outputPath: string | ||
16 | start?: number | ||
17 | end?: number | ||
18 | }) { | ||
19 | const { inputPath, outputPath } = options | ||
20 | |||
21 | const mainProbe = await ffprobePromise(inputPath) | ||
22 | const fps = await getVideoStreamFPS(inputPath, mainProbe) | ||
23 | const { resolution } = await getVideoStreamDimensionsInfo(inputPath, mainProbe) | ||
24 | |||
25 | const command = this.commandWrapper.buildCommand(inputPath) | ||
26 | .output(outputPath) | ||
27 | |||
28 | await presetVOD({ | ||
29 | commandWrapper: this.commandWrapper, | ||
30 | input: inputPath, | ||
31 | resolution, | ||
32 | fps, | ||
33 | canCopyAudio: false, | ||
34 | canCopyVideo: false | ||
35 | }) | ||
36 | |||
37 | if (options.start) { | ||
38 | command.outputOption('-ss ' + options.start) | ||
39 | } | ||
40 | |||
41 | if (options.end) { | ||
42 | command.outputOption('-to ' + options.end) | ||
43 | } | ||
44 | |||
45 | await this.commandWrapper.runCommand() | ||
46 | } | ||
47 | |||
48 | async addWatermark (options: { | ||
49 | inputPath: string | ||
50 | watermarkPath: string | ||
51 | outputPath: string | ||
52 | |||
53 | videoFilters: { | ||
54 | watermarkSizeRatio: number | ||
55 | horitonzalMarginRatio: number | ||
56 | verticalMarginRatio: number | ||
57 | } | ||
58 | }) { | ||
59 | const { watermarkPath, inputPath, outputPath, videoFilters } = options | ||
60 | |||
61 | const videoProbe = await ffprobePromise(inputPath) | ||
62 | const fps = await getVideoStreamFPS(inputPath, videoProbe) | ||
63 | const { resolution } = await getVideoStreamDimensionsInfo(inputPath, videoProbe) | ||
64 | |||
65 | const command = this.commandWrapper.buildCommand(inputPath) | ||
66 | .output(outputPath) | ||
67 | |||
68 | command.input(watermarkPath) | ||
69 | |||
70 | await presetVOD({ | ||
71 | commandWrapper: this.commandWrapper, | ||
72 | input: inputPath, | ||
73 | resolution, | ||
74 | fps, | ||
75 | canCopyAudio: true, | ||
76 | canCopyVideo: false | ||
77 | }) | ||
78 | |||
79 | const complexFilter: FilterSpecification[] = [ | ||
80 | // Scale watermark | ||
81 | { | ||
82 | inputs: [ '[1]', '[0]' ], | ||
83 | filter: 'scale2ref', | ||
84 | options: { | ||
85 | w: 'oh*mdar', | ||
86 | h: `ih*${videoFilters.watermarkSizeRatio}` | ||
87 | }, | ||
88 | outputs: [ '[watermark]', '[video]' ] | ||
89 | }, | ||
90 | |||
91 | { | ||
92 | inputs: [ '[video]', '[watermark]' ], | ||
93 | filter: 'overlay', | ||
94 | options: { | ||
95 | x: `main_w - overlay_w - (main_h * ${videoFilters.horitonzalMarginRatio})`, | ||
96 | y: `main_h * ${videoFilters.verticalMarginRatio}` | ||
97 | } | ||
98 | } | ||
99 | ] | ||
100 | |||
101 | command.complexFilter(complexFilter) | ||
102 | |||
103 | await this.commandWrapper.runCommand() | ||
104 | } | ||
105 | |||
106 | async addIntroOutro (options: { | ||
107 | inputPath: string | ||
108 | introOutroPath: string | ||
109 | outputPath: string | ||
110 | type: 'intro' | 'outro' | ||
111 | }) { | ||
112 | const { introOutroPath, inputPath, outputPath, type } = options | ||
113 | |||
114 | const mainProbe = await ffprobePromise(inputPath) | ||
115 | const fps = await getVideoStreamFPS(inputPath, mainProbe) | ||
116 | const { resolution } = await getVideoStreamDimensionsInfo(inputPath, mainProbe) | ||
117 | const mainHasAudio = await hasAudioStream(inputPath, mainProbe) | ||
118 | |||
119 | const introOutroProbe = await ffprobePromise(introOutroPath) | ||
120 | const introOutroHasAudio = await hasAudioStream(introOutroPath, introOutroProbe) | ||
121 | |||
122 | const command = this.commandWrapper.buildCommand(inputPath) | ||
123 | .output(outputPath) | ||
124 | |||
125 | command.input(introOutroPath) | ||
126 | |||
127 | if (!introOutroHasAudio && mainHasAudio) { | ||
128 | const duration = await getVideoStreamDuration(introOutroPath, introOutroProbe) | ||
129 | |||
130 | command.input('anullsrc') | ||
131 | command.withInputFormat('lavfi') | ||
132 | command.withInputOption('-t ' + duration) | ||
133 | } | ||
134 | |||
135 | await presetVOD({ | ||
136 | commandWrapper: this.commandWrapper, | ||
137 | input: inputPath, | ||
138 | resolution, | ||
139 | fps, | ||
140 | canCopyAudio: false, | ||
141 | canCopyVideo: false | ||
142 | }) | ||
143 | |||
144 | // Add black background to correctly scale intro/outro with padding | ||
145 | const complexFilter: FilterSpecification[] = [ | ||
146 | { | ||
147 | inputs: [ '1', '0' ], | ||
148 | filter: 'scale2ref', | ||
149 | options: { | ||
150 | w: 'iw', | ||
151 | h: `ih` | ||
152 | }, | ||
153 | outputs: [ 'intro-outro', 'main' ] | ||
154 | }, | ||
155 | { | ||
156 | inputs: [ 'intro-outro', 'main' ], | ||
157 | filter: 'scale2ref', | ||
158 | options: { | ||
159 | w: 'iw', | ||
160 | h: `ih` | ||
161 | }, | ||
162 | outputs: [ 'to-scale', 'main' ] | ||
163 | }, | ||
164 | { | ||
165 | inputs: 'to-scale', | ||
166 | filter: 'drawbox', | ||
167 | options: { | ||
168 | t: 'fill' | ||
169 | }, | ||
170 | outputs: [ 'to-scale-bg' ] | ||
171 | }, | ||
172 | { | ||
173 | inputs: [ '1', 'to-scale-bg' ], | ||
174 | filter: 'scale2ref', | ||
175 | options: { | ||
176 | w: 'iw', | ||
177 | h: 'ih', | ||
178 | force_original_aspect_ratio: 'decrease', | ||
179 | flags: 'spline' | ||
180 | }, | ||
181 | outputs: [ 'to-scale', 'to-scale-bg' ] | ||
182 | }, | ||
183 | { | ||
184 | inputs: [ 'to-scale-bg', 'to-scale' ], | ||
185 | filter: 'overlay', | ||
186 | options: { | ||
187 | x: '(main_w - overlay_w)/2', | ||
188 | y: '(main_h - overlay_h)/2' | ||
189 | }, | ||
190 | outputs: 'intro-outro-resized' | ||
191 | } | ||
192 | ] | ||
193 | |||
194 | const concatFilter = { | ||
195 | inputs: [], | ||
196 | filter: 'concat', | ||
197 | options: { | ||
198 | n: 2, | ||
199 | v: 1, | ||
200 | unsafe: 1 | ||
201 | }, | ||
202 | outputs: [ 'v' ] | ||
203 | } | ||
204 | |||
205 | const introOutroFilterInputs = [ 'intro-outro-resized' ] | ||
206 | const mainFilterInputs = [ 'main' ] | ||
207 | |||
208 | if (mainHasAudio) { | ||
209 | mainFilterInputs.push('0:a') | ||
210 | |||
211 | if (introOutroHasAudio) { | ||
212 | introOutroFilterInputs.push('1:a') | ||
213 | } else { | ||
214 | // Silent input | ||
215 | introOutroFilterInputs.push('2:a') | ||
216 | } | ||
217 | } | ||
218 | |||
219 | if (type === 'intro') { | ||
220 | concatFilter.inputs = [ ...introOutroFilterInputs, ...mainFilterInputs ] | ||
221 | } else { | ||
222 | concatFilter.inputs = [ ...mainFilterInputs, ...introOutroFilterInputs ] | ||
223 | } | ||
224 | |||
225 | if (mainHasAudio) { | ||
226 | concatFilter.options['a'] = 1 | ||
227 | concatFilter.outputs.push('a') | ||
228 | |||
229 | command.outputOption('-map [a]') | ||
230 | } | ||
231 | |||
232 | command.outputOption('-map [v]') | ||
233 | |||
234 | complexFilter.push(concatFilter) | ||
235 | command.complexFilter(complexFilter) | ||
236 | |||
237 | await this.commandWrapper.runCommand() | ||
238 | } | ||
239 | } | ||
diff --git a/shared/ffmpeg/ffmpeg-images.ts b/shared/ffmpeg/ffmpeg-images.ts deleted file mode 100644 index 618fac7d1..000000000 --- a/shared/ffmpeg/ffmpeg-images.ts +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper' | ||
2 | import { getVideoStreamDuration } from './ffprobe' | ||
3 | |||
4 | export class FFmpegImage { | ||
5 | private readonly commandWrapper: FFmpegCommandWrapper | ||
6 | |||
7 | constructor (options: FFmpegCommandWrapperOptions) { | ||
8 | this.commandWrapper = new FFmpegCommandWrapper(options) | ||
9 | } | ||
10 | |||
11 | convertWebPToJPG (options: { | ||
12 | path: string | ||
13 | destination: string | ||
14 | }): Promise<void> { | ||
15 | const { path, destination } = options | ||
16 | |||
17 | this.commandWrapper.buildCommand(path) | ||
18 | .output(destination) | ||
19 | |||
20 | return this.commandWrapper.runCommand({ silent: true }) | ||
21 | } | ||
22 | |||
23 | processGIF (options: { | ||
24 | path: string | ||
25 | destination: string | ||
26 | newSize: { width: number, height: number } | ||
27 | }): Promise<void> { | ||
28 | const { path, destination, newSize } = options | ||
29 | |||
30 | this.commandWrapper.buildCommand(path) | ||
31 | .fps(20) | ||
32 | .size(`${newSize.width}x${newSize.height}`) | ||
33 | .output(destination) | ||
34 | |||
35 | return this.commandWrapper.runCommand() | ||
36 | } | ||
37 | |||
38 | async generateThumbnailFromVideo (options: { | ||
39 | fromPath: string | ||
40 | output: string | ||
41 | }) { | ||
42 | const { fromPath, output } = options | ||
43 | |||
44 | let duration = await getVideoStreamDuration(fromPath) | ||
45 | if (isNaN(duration)) duration = 0 | ||
46 | |||
47 | this.commandWrapper.buildCommand(fromPath) | ||
48 | .seekInput(duration / 2) | ||
49 | .videoFilter('thumbnail=500') | ||
50 | .outputOption('-frames:v 1') | ||
51 | .output(output) | ||
52 | |||
53 | return this.commandWrapper.runCommand() | ||
54 | } | ||
55 | |||
56 | async generateStoryboardFromVideo (options: { | ||
57 | path: string | ||
58 | destination: string | ||
59 | |||
60 | sprites: { | ||
61 | size: { | ||
62 | width: number | ||
63 | height: number | ||
64 | } | ||
65 | |||
66 | count: { | ||
67 | width: number | ||
68 | height: number | ||
69 | } | ||
70 | |||
71 | duration: number | ||
72 | } | ||
73 | }) { | ||
74 | const { path, destination, sprites } = options | ||
75 | |||
76 | const command = this.commandWrapper.buildCommand(path) | ||
77 | |||
78 | const filter = [ | ||
79 | `setpts=N/round(FRAME_RATE)/TB`, | ||
80 | `select='not(mod(t,${options.sprites.duration}))'`, | ||
81 | `scale=${sprites.size.width}:${sprites.size.height}`, | ||
82 | `tile=layout=${sprites.count.width}x${sprites.count.height}` | ||
83 | ].join(',') | ||
84 | |||
85 | command.outputOption('-filter_complex', filter) | ||
86 | command.outputOption('-frames:v', '1') | ||
87 | command.outputOption('-q:v', '2') | ||
88 | command.output(destination) | ||
89 | |||
90 | return this.commandWrapper.runCommand() | ||
91 | } | ||
92 | } | ||
diff --git a/shared/ffmpeg/ffmpeg-live.ts b/shared/ffmpeg/ffmpeg-live.ts deleted file mode 100644 index cca4c6474..000000000 --- a/shared/ffmpeg/ffmpeg-live.ts +++ /dev/null | |||
@@ -1,184 +0,0 @@ | |||
1 | import { FilterSpecification } from 'fluent-ffmpeg' | ||
2 | import { join } from 'path' | ||
3 | import { pick } from '@shared/core-utils' | ||
4 | import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper' | ||
5 | import { buildStreamSuffix, getScaleFilter, StreamType } from './ffmpeg-utils' | ||
6 | import { addDefaultEncoderGlobalParams, addDefaultEncoderParams, applyEncoderOptions } from './shared' | ||
7 | |||
8 | export class FFmpegLive { | ||
9 | private readonly commandWrapper: FFmpegCommandWrapper | ||
10 | |||
11 | constructor (options: FFmpegCommandWrapperOptions) { | ||
12 | this.commandWrapper = new FFmpegCommandWrapper(options) | ||
13 | } | ||
14 | |||
15 | async getLiveTranscodingCommand (options: { | ||
16 | inputUrl: string | ||
17 | |||
18 | outPath: string | ||
19 | masterPlaylistName: string | ||
20 | |||
21 | toTranscode: { | ||
22 | resolution: number | ||
23 | fps: number | ||
24 | }[] | ||
25 | |||
26 | // Input information | ||
27 | bitrate: number | ||
28 | ratio: number | ||
29 | hasAudio: boolean | ||
30 | |||
31 | segmentListSize: number | ||
32 | segmentDuration: number | ||
33 | }) { | ||
34 | const { | ||
35 | inputUrl, | ||
36 | outPath, | ||
37 | toTranscode, | ||
38 | bitrate, | ||
39 | masterPlaylistName, | ||
40 | ratio, | ||
41 | hasAudio | ||
42 | } = options | ||
43 | const command = this.commandWrapper.buildCommand(inputUrl) | ||
44 | |||
45 | const varStreamMap: string[] = [] | ||
46 | |||
47 | const complexFilter: FilterSpecification[] = [ | ||
48 | { | ||
49 | inputs: '[v:0]', | ||
50 | filter: 'split', | ||
51 | options: toTranscode.length, | ||
52 | outputs: toTranscode.map(t => `vtemp${t.resolution}`) | ||
53 | } | ||
54 | ] | ||
55 | |||
56 | command.outputOption('-sc_threshold 0') | ||
57 | |||
58 | addDefaultEncoderGlobalParams(command) | ||
59 | |||
60 | for (let i = 0; i < toTranscode.length; i++) { | ||
61 | const streamMap: string[] = [] | ||
62 | const { resolution, fps } = toTranscode[i] | ||
63 | |||
64 | const baseEncoderBuilderParams = { | ||
65 | input: inputUrl, | ||
66 | |||
67 | canCopyAudio: true, | ||
68 | canCopyVideo: true, | ||
69 | |||
70 | inputBitrate: bitrate, | ||
71 | inputRatio: ratio, | ||
72 | |||
73 | resolution, | ||
74 | fps, | ||
75 | |||
76 | streamNum: i, | ||
77 | videoType: 'live' as 'live' | ||
78 | } | ||
79 | |||
80 | { | ||
81 | const streamType: StreamType = 'video' | ||
82 | const builderResult = await this.commandWrapper.getEncoderBuilderResult({ ...baseEncoderBuilderParams, streamType }) | ||
83 | if (!builderResult) { | ||
84 | throw new Error('No available live video encoder found') | ||
85 | } | ||
86 | |||
87 | command.outputOption(`-map [vout${resolution}]`) | ||
88 | |||
89 | addDefaultEncoderParams({ command, encoder: builderResult.encoder, fps, streamNum: i }) | ||
90 | |||
91 | this.commandWrapper.debugLog( | ||
92 | `Apply ffmpeg live video params from ${builderResult.encoder} using ${this.commandWrapper.getProfile()} profile.`, | ||
93 | { builderResult, fps, toTranscode } | ||
94 | ) | ||
95 | |||
96 | command.outputOption(`${buildStreamSuffix('-c:v', i)} ${builderResult.encoder}`) | ||
97 | applyEncoderOptions(command, builderResult.result) | ||
98 | |||
99 | complexFilter.push({ | ||
100 | inputs: `vtemp${resolution}`, | ||
101 | filter: getScaleFilter(builderResult.result), | ||
102 | options: `w=-2:h=${resolution}`, | ||
103 | outputs: `vout${resolution}` | ||
104 | }) | ||
105 | |||
106 | streamMap.push(`v:${i}`) | ||
107 | } | ||
108 | |||
109 | if (hasAudio) { | ||
110 | const streamType: StreamType = 'audio' | ||
111 | const builderResult = await this.commandWrapper.getEncoderBuilderResult({ ...baseEncoderBuilderParams, streamType }) | ||
112 | if (!builderResult) { | ||
113 | throw new Error('No available live audio encoder found') | ||
114 | } | ||
115 | |||
116 | command.outputOption('-map a:0') | ||
117 | |||
118 | addDefaultEncoderParams({ command, encoder: builderResult.encoder, fps, streamNum: i }) | ||
119 | |||
120 | this.commandWrapper.debugLog( | ||
121 | `Apply ffmpeg live audio params from ${builderResult.encoder} using ${this.commandWrapper.getProfile()} profile.`, | ||
122 | { builderResult, fps, resolution } | ||
123 | ) | ||
124 | |||
125 | command.outputOption(`${buildStreamSuffix('-c:a', i)} ${builderResult.encoder}`) | ||
126 | applyEncoderOptions(command, builderResult.result) | ||
127 | |||
128 | streamMap.push(`a:${i}`) | ||
129 | } | ||
130 | |||
131 | varStreamMap.push(streamMap.join(',')) | ||
132 | } | ||
133 | |||
134 | command.complexFilter(complexFilter) | ||
135 | |||
136 | this.addDefaultLiveHLSParams({ ...pick(options, [ 'segmentDuration', 'segmentListSize' ]), outPath, masterPlaylistName }) | ||
137 | |||
138 | command.outputOption('-var_stream_map', varStreamMap.join(' ')) | ||
139 | |||
140 | return command | ||
141 | } | ||
142 | |||
143 | getLiveMuxingCommand (options: { | ||
144 | inputUrl: string | ||
145 | outPath: string | ||
146 | masterPlaylistName: string | ||
147 | |||
148 | segmentListSize: number | ||
149 | segmentDuration: number | ||
150 | }) { | ||
151 | const { inputUrl, outPath, masterPlaylistName } = options | ||
152 | |||
153 | const command = this.commandWrapper.buildCommand(inputUrl) | ||
154 | |||
155 | command.outputOption('-c:v copy') | ||
156 | command.outputOption('-c:a copy') | ||
157 | command.outputOption('-map 0:a?') | ||
158 | command.outputOption('-map 0:v?') | ||
159 | |||
160 | this.addDefaultLiveHLSParams({ ...pick(options, [ 'segmentDuration', 'segmentListSize' ]), outPath, masterPlaylistName }) | ||
161 | |||
162 | return command | ||
163 | } | ||
164 | |||
165 | private addDefaultLiveHLSParams (options: { | ||
166 | outPath: string | ||
167 | masterPlaylistName: string | ||
168 | segmentListSize: number | ||
169 | segmentDuration: number | ||
170 | }) { | ||
171 | const { outPath, masterPlaylistName, segmentListSize, segmentDuration } = options | ||
172 | |||
173 | const command = this.commandWrapper.getCommand() | ||
174 | |||
175 | command.outputOption('-hls_time ' + segmentDuration) | ||
176 | command.outputOption('-hls_list_size ' + segmentListSize) | ||
177 | command.outputOption('-hls_flags delete_segments+independent_segments+program_date_time') | ||
178 | command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%06d.ts')}`) | ||
179 | command.outputOption('-master_pl_name ' + masterPlaylistName) | ||
180 | command.outputOption(`-f hls`) | ||
181 | |||
182 | command.output(join(outPath, '%v.m3u8')) | ||
183 | } | ||
184 | } | ||
diff --git a/shared/ffmpeg/ffmpeg-utils.ts b/shared/ffmpeg/ffmpeg-utils.ts deleted file mode 100644 index 7d09c32ca..000000000 --- a/shared/ffmpeg/ffmpeg-utils.ts +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | import { EncoderOptions } from '@shared/models' | ||
2 | |||
3 | export type StreamType = 'audio' | 'video' | ||
4 | |||
5 | export function buildStreamSuffix (base: string, streamNum?: number) { | ||
6 | if (streamNum !== undefined) { | ||
7 | return `${base}:${streamNum}` | ||
8 | } | ||
9 | |||
10 | return base | ||
11 | } | ||
12 | |||
13 | export function getScaleFilter (options: EncoderOptions): string { | ||
14 | if (options.scaleFilter) return options.scaleFilter.name | ||
15 | |||
16 | return 'scale' | ||
17 | } | ||
diff --git a/shared/ffmpeg/ffmpeg-version.ts b/shared/ffmpeg/ffmpeg-version.ts deleted file mode 100644 index 41d9b2d89..000000000 --- a/shared/ffmpeg/ffmpeg-version.ts +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | import { exec } from 'child_process' | ||
2 | import ffmpeg from 'fluent-ffmpeg' | ||
3 | |||
4 | export function getFFmpegVersion () { | ||
5 | return new Promise<string>((res, rej) => { | ||
6 | (ffmpeg() as any)._getFfmpegPath((err, ffmpegPath) => { | ||
7 | if (err) return rej(err) | ||
8 | if (!ffmpegPath) return rej(new Error('Could not find ffmpeg path')) | ||
9 | |||
10 | return exec(`${ffmpegPath} -version`, (err, stdout) => { | ||
11 | if (err) return rej(err) | ||
12 | |||
13 | const parsed = stdout.match(/ffmpeg version .?(\d+\.\d+(\.\d+)?)/) | ||
14 | if (!parsed?.[1]) return rej(new Error(`Could not find ffmpeg version in ${stdout}`)) | ||
15 | |||
16 | // Fix ffmpeg version that does not include patch version (4.4 for example) | ||
17 | let version = parsed[1] | ||
18 | if (version.match(/^\d+\.\d+$/)) { | ||
19 | version += '.0' | ||
20 | } | ||
21 | }) | ||
22 | }) | ||
23 | }) | ||
24 | } | ||
diff --git a/shared/ffmpeg/ffmpeg-vod.ts b/shared/ffmpeg/ffmpeg-vod.ts deleted file mode 100644 index e40ca0a1e..000000000 --- a/shared/ffmpeg/ffmpeg-vod.ts +++ /dev/null | |||
@@ -1,256 +0,0 @@ | |||
1 | import { MutexInterface } from 'async-mutex' | ||
2 | import { FfmpegCommand } from 'fluent-ffmpeg' | ||
3 | import { readFile, writeFile } from 'fs-extra' | ||
4 | import { dirname } from 'path' | ||
5 | import { pick } from '@shared/core-utils' | ||
6 | import { VideoResolution } from '@shared/models' | ||
7 | import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper' | ||
8 | import { ffprobePromise, getVideoStreamDimensionsInfo } from './ffprobe' | ||
9 | import { presetCopy, presetOnlyAudio, presetVOD } from './shared/presets' | ||
10 | |||
11 | export type TranscodeVODOptionsType = 'hls' | 'hls-from-ts' | 'quick-transcode' | 'video' | 'merge-audio' | 'only-audio' | ||
12 | |||
13 | export interface BaseTranscodeVODOptions { | ||
14 | type: TranscodeVODOptionsType | ||
15 | |||
16 | inputPath: string | ||
17 | outputPath: string | ||
18 | |||
19 | // Will be released after the ffmpeg started | ||
20 | // To prevent a bug where the input file does not exist anymore when running ffmpeg | ||
21 | inputFileMutexReleaser: MutexInterface.Releaser | ||
22 | |||
23 | resolution: number | ||
24 | fps: number | ||
25 | } | ||
26 | |||
27 | export interface HLSTranscodeOptions extends BaseTranscodeVODOptions { | ||
28 | type: 'hls' | ||
29 | |||
30 | copyCodecs: boolean | ||
31 | |||
32 | hlsPlaylist: { | ||
33 | videoFilename: string | ||
34 | } | ||
35 | } | ||
36 | |||
37 | export interface HLSFromTSTranscodeOptions extends BaseTranscodeVODOptions { | ||
38 | type: 'hls-from-ts' | ||
39 | |||
40 | isAAC: boolean | ||
41 | |||
42 | hlsPlaylist: { | ||
43 | videoFilename: string | ||
44 | } | ||
45 | } | ||
46 | |||
47 | export interface QuickTranscodeOptions extends BaseTranscodeVODOptions { | ||
48 | type: 'quick-transcode' | ||
49 | } | ||
50 | |||
51 | export interface VideoTranscodeOptions extends BaseTranscodeVODOptions { | ||
52 | type: 'video' | ||
53 | } | ||
54 | |||
55 | export interface MergeAudioTranscodeOptions extends BaseTranscodeVODOptions { | ||
56 | type: 'merge-audio' | ||
57 | audioPath: string | ||
58 | } | ||
59 | |||
60 | export interface OnlyAudioTranscodeOptions extends BaseTranscodeVODOptions { | ||
61 | type: 'only-audio' | ||
62 | } | ||
63 | |||
64 | export type TranscodeVODOptions = | ||
65 | HLSTranscodeOptions | ||
66 | | HLSFromTSTranscodeOptions | ||
67 | | VideoTranscodeOptions | ||
68 | | MergeAudioTranscodeOptions | ||
69 | | OnlyAudioTranscodeOptions | ||
70 | | QuickTranscodeOptions | ||
71 | |||
72 | // --------------------------------------------------------------------------- | ||
73 | |||
74 | export class FFmpegVOD { | ||
75 | private readonly commandWrapper: FFmpegCommandWrapper | ||
76 | |||
77 | private ended = false | ||
78 | |||
79 | constructor (options: FFmpegCommandWrapperOptions) { | ||
80 | this.commandWrapper = new FFmpegCommandWrapper(options) | ||
81 | } | ||
82 | |||
83 | async transcode (options: TranscodeVODOptions) { | ||
84 | const builders: { | ||
85 | [ type in TranscodeVODOptionsType ]: (options: TranscodeVODOptions) => Promise<void> | void | ||
86 | } = { | ||
87 | 'quick-transcode': this.buildQuickTranscodeCommand.bind(this), | ||
88 | 'hls': this.buildHLSVODCommand.bind(this), | ||
89 | 'hls-from-ts': this.buildHLSVODFromTSCommand.bind(this), | ||
90 | 'merge-audio': this.buildAudioMergeCommand.bind(this), | ||
91 | // TODO: remove, we merge this in buildWebVideoCommand | ||
92 | 'only-audio': this.buildOnlyAudioCommand.bind(this), | ||
93 | 'video': this.buildWebVideoCommand.bind(this) | ||
94 | } | ||
95 | |||
96 | this.commandWrapper.debugLog('Will run transcode.', { options }) | ||
97 | |||
98 | const command = this.commandWrapper.buildCommand(options.inputPath) | ||
99 | .output(options.outputPath) | ||
100 | |||
101 | await builders[options.type](options) | ||
102 | |||
103 | command.on('start', () => { | ||
104 | setTimeout(() => { | ||
105 | options.inputFileMutexReleaser() | ||
106 | }, 1000) | ||
107 | }) | ||
108 | |||
109 | await this.commandWrapper.runCommand() | ||
110 | |||
111 | await this.fixHLSPlaylistIfNeeded(options) | ||
112 | |||
113 | this.ended = true | ||
114 | } | ||
115 | |||
116 | isEnded () { | ||
117 | return this.ended | ||
118 | } | ||
119 | |||
120 | private async buildWebVideoCommand (options: TranscodeVODOptions) { | ||
121 | const { resolution, fps, inputPath } = options | ||
122 | |||
123 | if (resolution === VideoResolution.H_NOVIDEO) { | ||
124 | presetOnlyAudio(this.commandWrapper) | ||
125 | return | ||
126 | } | ||
127 | |||
128 | let scaleFilterValue: string | ||
129 | |||
130 | if (resolution !== undefined) { | ||
131 | const probe = await ffprobePromise(inputPath) | ||
132 | const videoStreamInfo = await getVideoStreamDimensionsInfo(inputPath, probe) | ||
133 | |||
134 | scaleFilterValue = videoStreamInfo?.isPortraitMode === true | ||
135 | ? `w=${resolution}:h=-2` | ||
136 | : `w=-2:h=${resolution}` | ||
137 | } | ||
138 | |||
139 | await presetVOD({ | ||
140 | commandWrapper: this.commandWrapper, | ||
141 | |||
142 | resolution, | ||
143 | input: inputPath, | ||
144 | canCopyAudio: true, | ||
145 | canCopyVideo: true, | ||
146 | fps, | ||
147 | scaleFilterValue | ||
148 | }) | ||
149 | } | ||
150 | |||
151 | private buildQuickTranscodeCommand (_options: TranscodeVODOptions) { | ||
152 | const command = this.commandWrapper.getCommand() | ||
153 | |||
154 | presetCopy(this.commandWrapper) | ||
155 | |||
156 | command.outputOption('-map_metadata -1') // strip all metadata | ||
157 | .outputOption('-movflags faststart') | ||
158 | } | ||
159 | |||
160 | // --------------------------------------------------------------------------- | ||
161 | // Audio transcoding | ||
162 | // --------------------------------------------------------------------------- | ||
163 | |||
164 | private async buildAudioMergeCommand (options: MergeAudioTranscodeOptions) { | ||
165 | const command = this.commandWrapper.getCommand() | ||
166 | |||
167 | command.loop(undefined) | ||
168 | |||
169 | await presetVOD({ | ||
170 | ...pick(options, [ 'resolution' ]), | ||
171 | |||
172 | commandWrapper: this.commandWrapper, | ||
173 | input: options.audioPath, | ||
174 | canCopyAudio: true, | ||
175 | canCopyVideo: true, | ||
176 | fps: options.fps, | ||
177 | scaleFilterValue: this.getMergeAudioScaleFilterValue() | ||
178 | }) | ||
179 | |||
180 | command.outputOption('-preset:v veryfast') | ||
181 | |||
182 | command.input(options.audioPath) | ||
183 | .outputOption('-tune stillimage') | ||
184 | .outputOption('-shortest') | ||
185 | } | ||
186 | |||
187 | private buildOnlyAudioCommand (_options: OnlyAudioTranscodeOptions) { | ||
188 | presetOnlyAudio(this.commandWrapper) | ||
189 | } | ||
190 | |||
191 | // Avoid "height not divisible by 2" error | ||
192 | private getMergeAudioScaleFilterValue () { | ||
193 | return 'trunc(iw/2)*2:trunc(ih/2)*2' | ||
194 | } | ||
195 | |||
196 | // --------------------------------------------------------------------------- | ||
197 | // HLS transcoding | ||
198 | // --------------------------------------------------------------------------- | ||
199 | |||
200 | private async buildHLSVODCommand (options: HLSTranscodeOptions) { | ||
201 | const command = this.commandWrapper.getCommand() | ||
202 | |||
203 | const videoPath = this.getHLSVideoPath(options) | ||
204 | |||
205 | if (options.copyCodecs) presetCopy(this.commandWrapper) | ||
206 | else if (options.resolution === VideoResolution.H_NOVIDEO) presetOnlyAudio(this.commandWrapper) | ||
207 | else await this.buildWebVideoCommand(options) | ||
208 | |||
209 | this.addCommonHLSVODCommandOptions(command, videoPath) | ||
210 | } | ||
211 | |||
212 | private buildHLSVODFromTSCommand (options: HLSFromTSTranscodeOptions) { | ||
213 | const command = this.commandWrapper.getCommand() | ||
214 | |||
215 | const videoPath = this.getHLSVideoPath(options) | ||
216 | |||
217 | command.outputOption('-c copy') | ||
218 | |||
219 | if (options.isAAC) { | ||
220 | // Required for example when copying an AAC stream from an MPEG-TS | ||
221 | // Since it's a bitstream filter, we don't need to reencode the audio | ||
222 | command.outputOption('-bsf:a aac_adtstoasc') | ||
223 | } | ||
224 | |||
225 | this.addCommonHLSVODCommandOptions(command, videoPath) | ||
226 | } | ||
227 | |||
228 | private addCommonHLSVODCommandOptions (command: FfmpegCommand, outputPath: string) { | ||
229 | return command.outputOption('-hls_time 4') | ||
230 | .outputOption('-hls_list_size 0') | ||
231 | .outputOption('-hls_playlist_type vod') | ||
232 | .outputOption('-hls_segment_filename ' + outputPath) | ||
233 | .outputOption('-hls_segment_type fmp4') | ||
234 | .outputOption('-f hls') | ||
235 | .outputOption('-hls_flags single_file') | ||
236 | } | ||
237 | |||
238 | private async fixHLSPlaylistIfNeeded (options: TranscodeVODOptions) { | ||
239 | if (options.type !== 'hls' && options.type !== 'hls-from-ts') return | ||
240 | |||
241 | const fileContent = await readFile(options.outputPath) | ||
242 | |||
243 | const videoFileName = options.hlsPlaylist.videoFilename | ||
244 | const videoFilePath = this.getHLSVideoPath(options) | ||
245 | |||
246 | // Fix wrong mapping with some ffmpeg versions | ||
247 | const newContent = fileContent.toString() | ||
248 | .replace(`#EXT-X-MAP:URI="${videoFilePath}",`, `#EXT-X-MAP:URI="${videoFileName}",`) | ||
249 | |||
250 | await writeFile(options.outputPath, newContent) | ||
251 | } | ||
252 | |||
253 | private getHLSVideoPath (options: HLSTranscodeOptions | HLSFromTSTranscodeOptions) { | ||
254 | return `${dirname(options.outputPath)}/${options.hlsPlaylist.videoFilename}` | ||
255 | } | ||
256 | } | ||
diff --git a/shared/ffmpeg/ffprobe.ts b/shared/ffmpeg/ffprobe.ts deleted file mode 100644 index fda08c28e..000000000 --- a/shared/ffmpeg/ffprobe.ts +++ /dev/null | |||
@@ -1,184 +0,0 @@ | |||
1 | import { ffprobe, FfprobeData } from 'fluent-ffmpeg' | ||
2 | import { forceNumber } from '@shared/core-utils' | ||
3 | import { VideoResolution } from '@shared/models/videos' | ||
4 | |||
5 | /** | ||
6 | * | ||
7 | * Helpers to run ffprobe and extract data from the JSON output | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | function ffprobePromise (path: string) { | ||
12 | return new Promise<FfprobeData>((res, rej) => { | ||
13 | ffprobe(path, (err, data) => { | ||
14 | if (err) return rej(err) | ||
15 | |||
16 | return res(data) | ||
17 | }) | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | // Audio | ||
23 | // --------------------------------------------------------------------------- | ||
24 | |||
25 | const imageCodecs = new Set([ | ||
26 | 'ansi', 'apng', 'bintext', 'bmp', 'brender_pix', 'dpx', 'exr', 'fits', 'gem', 'gif', 'jpeg2000', 'jpgls', 'mjpeg', 'mjpegb', 'msp2', | ||
27 | 'pam', 'pbm', 'pcx', 'pfm', 'pgm', 'pgmyuv', 'pgx', 'photocd', 'pictor', 'png', 'ppm', 'psd', 'sgi', 'sunrast', 'svg', 'targa', 'tiff', | ||
28 | 'txd', 'webp', 'xbin', 'xbm', 'xface', 'xpm', 'xwd' | ||
29 | ]) | ||
30 | |||
31 | async function isAudioFile (path: string, existingProbe?: FfprobeData) { | ||
32 | const videoStream = await getVideoStream(path, existingProbe) | ||
33 | if (!videoStream) return true | ||
34 | |||
35 | if (imageCodecs.has(videoStream.codec_name)) return true | ||
36 | |||
37 | return false | ||
38 | } | ||
39 | |||
40 | async function hasAudioStream (path: string, existingProbe?: FfprobeData) { | ||
41 | const { audioStream } = await getAudioStream(path, existingProbe) | ||
42 | |||
43 | return !!audioStream | ||
44 | } | ||
45 | |||
46 | async function getAudioStream (videoPath: string, existingProbe?: FfprobeData) { | ||
47 | // without position, ffprobe considers the last input only | ||
48 | // we make it consider the first input only | ||
49 | // if you pass a file path to pos, then ffprobe acts on that file directly | ||
50 | const data = existingProbe || await ffprobePromise(videoPath) | ||
51 | |||
52 | if (Array.isArray(data.streams)) { | ||
53 | const audioStream = data.streams.find(stream => stream['codec_type'] === 'audio') | ||
54 | |||
55 | if (audioStream) { | ||
56 | return { | ||
57 | absolutePath: data.format.filename, | ||
58 | audioStream, | ||
59 | bitrate: forceNumber(audioStream['bit_rate']) | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | |||
64 | return { absolutePath: data.format.filename } | ||
65 | } | ||
66 | |||
67 | function getMaxAudioBitrate (type: 'aac' | 'mp3' | string, bitrate: number) { | ||
68 | const maxKBitrate = 384 | ||
69 | const kToBits = (kbits: number) => kbits * 1000 | ||
70 | |||
71 | // If we did not manage to get the bitrate, use an average value | ||
72 | if (!bitrate) return 256 | ||
73 | |||
74 | if (type === 'aac') { | ||
75 | switch (true) { | ||
76 | case bitrate > kToBits(maxKBitrate): | ||
77 | return maxKBitrate | ||
78 | |||
79 | default: | ||
80 | return -1 // we interpret it as a signal to copy the audio stream as is | ||
81 | } | ||
82 | } | ||
83 | |||
84 | /* | ||
85 | a 192kbit/sec mp3 doesn't hold as much information as a 192kbit/sec aac. | ||
86 | That's why, when using aac, we can go to lower kbit/sec. The equivalences | ||
87 | made here are not made to be accurate, especially with good mp3 encoders. | ||
88 | */ | ||
89 | switch (true) { | ||
90 | case bitrate <= kToBits(192): | ||
91 | return 128 | ||
92 | |||
93 | case bitrate <= kToBits(384): | ||
94 | return 256 | ||
95 | |||
96 | default: | ||
97 | return maxKBitrate | ||
98 | } | ||
99 | } | ||
100 | |||
101 | // --------------------------------------------------------------------------- | ||
102 | // Video | ||
103 | // --------------------------------------------------------------------------- | ||
104 | |||
105 | async function getVideoStreamDimensionsInfo (path: string, existingProbe?: FfprobeData) { | ||
106 | const videoStream = await getVideoStream(path, existingProbe) | ||
107 | if (!videoStream) { | ||
108 | return { | ||
109 | width: 0, | ||
110 | height: 0, | ||
111 | ratio: 0, | ||
112 | resolution: VideoResolution.H_NOVIDEO, | ||
113 | isPortraitMode: false | ||
114 | } | ||
115 | } | ||
116 | |||
117 | return { | ||
118 | width: videoStream.width, | ||
119 | height: videoStream.height, | ||
120 | ratio: Math.max(videoStream.height, videoStream.width) / Math.min(videoStream.height, videoStream.width), | ||
121 | resolution: Math.min(videoStream.height, videoStream.width), | ||
122 | isPortraitMode: videoStream.height > videoStream.width | ||
123 | } | ||
124 | } | ||
125 | |||
126 | async function getVideoStreamFPS (path: string, existingProbe?: FfprobeData) { | ||
127 | const videoStream = await getVideoStream(path, existingProbe) | ||
128 | if (!videoStream) return 0 | ||
129 | |||
130 | for (const key of [ 'avg_frame_rate', 'r_frame_rate' ]) { | ||
131 | const valuesText: string = videoStream[key] | ||
132 | if (!valuesText) continue | ||
133 | |||
134 | const [ frames, seconds ] = valuesText.split('/') | ||
135 | if (!frames || !seconds) continue | ||
136 | |||
137 | const result = parseInt(frames, 10) / parseInt(seconds, 10) | ||
138 | if (result > 0) return Math.round(result) | ||
139 | } | ||
140 | |||
141 | return 0 | ||
142 | } | ||
143 | |||
144 | async function getVideoStreamBitrate (path: string, existingProbe?: FfprobeData): Promise<number> { | ||
145 | const metadata = existingProbe || await ffprobePromise(path) | ||
146 | |||
147 | let bitrate = metadata.format.bit_rate | ||
148 | if (bitrate && !isNaN(bitrate)) return bitrate | ||
149 | |||
150 | const videoStream = await getVideoStream(path, existingProbe) | ||
151 | if (!videoStream) return undefined | ||
152 | |||
153 | bitrate = forceNumber(videoStream?.bit_rate) | ||
154 | if (bitrate && !isNaN(bitrate)) return bitrate | ||
155 | |||
156 | return undefined | ||
157 | } | ||
158 | |||
159 | async function getVideoStreamDuration (path: string, existingProbe?: FfprobeData) { | ||
160 | const metadata = existingProbe || await ffprobePromise(path) | ||
161 | |||
162 | return Math.round(metadata.format.duration) | ||
163 | } | ||
164 | |||
165 | async function getVideoStream (path: string, existingProbe?: FfprobeData) { | ||
166 | const metadata = existingProbe || await ffprobePromise(path) | ||
167 | |||
168 | return metadata.streams.find(s => s.codec_type === 'video') | ||
169 | } | ||
170 | |||
171 | // --------------------------------------------------------------------------- | ||
172 | |||
173 | export { | ||
174 | getVideoStreamDimensionsInfo, | ||
175 | getMaxAudioBitrate, | ||
176 | getVideoStream, | ||
177 | getVideoStreamDuration, | ||
178 | getAudioStream, | ||
179 | getVideoStreamFPS, | ||
180 | isAudioFile, | ||
181 | ffprobePromise, | ||
182 | getVideoStreamBitrate, | ||
183 | hasAudioStream | ||
184 | } | ||
diff --git a/shared/ffmpeg/index.ts b/shared/ffmpeg/index.ts deleted file mode 100644 index 1dab292da..000000000 --- a/shared/ffmpeg/index.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | export * from './ffmpeg-command-wrapper' | ||
2 | export * from './ffmpeg-default-transcoding-profile' | ||
3 | export * from './ffmpeg-edition' | ||
4 | export * from './ffmpeg-images' | ||
5 | export * from './ffmpeg-live' | ||
6 | export * from './ffmpeg-utils' | ||
7 | export * from './ffmpeg-version' | ||
8 | export * from './ffmpeg-vod' | ||
9 | export * from './ffprobe' | ||
diff --git a/shared/ffmpeg/shared/encoder-options.ts b/shared/ffmpeg/shared/encoder-options.ts deleted file mode 100644 index 9692a6b02..000000000 --- a/shared/ffmpeg/shared/encoder-options.ts +++ /dev/null | |||
@@ -1,39 +0,0 @@ | |||
1 | import { FfmpegCommand } from 'fluent-ffmpeg' | ||
2 | import { EncoderOptions } from '@shared/models' | ||
3 | import { buildStreamSuffix } from '../ffmpeg-utils' | ||
4 | |||
5 | export function addDefaultEncoderGlobalParams (command: FfmpegCommand) { | ||
6 | // avoid issues when transcoding some files: https://trac.ffmpeg.org/ticket/6375 | ||
7 | command.outputOption('-max_muxing_queue_size 1024') | ||
8 | // strip all metadata | ||
9 | .outputOption('-map_metadata -1') | ||
10 | // allows import of source material with incompatible pixel formats (e.g. MJPEG video) | ||
11 | .outputOption('-pix_fmt yuv420p') | ||
12 | } | ||
13 | |||
14 | export function addDefaultEncoderParams (options: { | ||
15 | command: FfmpegCommand | ||
16 | encoder: 'libx264' | string | ||
17 | fps: number | ||
18 | |||
19 | streamNum?: number | ||
20 | }) { | ||
21 | const { command, encoder, fps, streamNum } = options | ||
22 | |||
23 | if (encoder === 'libx264') { | ||
24 | // 3.1 is the minimal resource allocation for our highest supported resolution | ||
25 | command.outputOption(buildStreamSuffix('-level:v', streamNum) + ' 3.1') | ||
26 | |||
27 | if (fps) { | ||
28 | // Keyframe interval of 2 seconds for faster seeking and resolution switching. | ||
29 | // https://streaminglearningcenter.com/blogs/whats-the-right-keyframe-interval.html | ||
30 | // https://superuser.com/a/908325 | ||
31 | command.outputOption(buildStreamSuffix('-g:v', streamNum) + ' ' + (fps * 2)) | ||
32 | } | ||
33 | } | ||
34 | } | ||
35 | |||
36 | export function applyEncoderOptions (command: FfmpegCommand, options: EncoderOptions) { | ||
37 | command.inputOptions(options.inputOptions ?? []) | ||
38 | .outputOptions(options.outputOptions ?? []) | ||
39 | } | ||
diff --git a/shared/ffmpeg/shared/index.ts b/shared/ffmpeg/shared/index.ts deleted file mode 100644 index 51de0316f..000000000 --- a/shared/ffmpeg/shared/index.ts +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | export * from './encoder-options' | ||
2 | export * from './presets' | ||
diff --git a/shared/ffmpeg/shared/presets.ts b/shared/ffmpeg/shared/presets.ts deleted file mode 100644 index dcebdc1cf..000000000 --- a/shared/ffmpeg/shared/presets.ts +++ /dev/null | |||
@@ -1,93 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { FFmpegCommandWrapper } from '../ffmpeg-command-wrapper' | ||
3 | import { ffprobePromise, getVideoStreamBitrate, getVideoStreamDimensionsInfo, hasAudioStream } from '../ffprobe' | ||
4 | import { addDefaultEncoderGlobalParams, addDefaultEncoderParams, applyEncoderOptions } from './encoder-options' | ||
5 | import { getScaleFilter, StreamType } from '../ffmpeg-utils' | ||
6 | |||
7 | export async function presetVOD (options: { | ||
8 | commandWrapper: FFmpegCommandWrapper | ||
9 | |||
10 | input: string | ||
11 | |||
12 | canCopyAudio: boolean | ||
13 | canCopyVideo: boolean | ||
14 | |||
15 | resolution: number | ||
16 | fps: number | ||
17 | |||
18 | scaleFilterValue?: string | ||
19 | }) { | ||
20 | const { commandWrapper, input, resolution, fps, scaleFilterValue } = options | ||
21 | const command = commandWrapper.getCommand() | ||
22 | |||
23 | command.format('mp4') | ||
24 | .outputOption('-movflags faststart') | ||
25 | |||
26 | addDefaultEncoderGlobalParams(command) | ||
27 | |||
28 | const probe = await ffprobePromise(input) | ||
29 | |||
30 | // Audio encoder | ||
31 | const bitrate = await getVideoStreamBitrate(input, probe) | ||
32 | const videoStreamDimensions = await getVideoStreamDimensionsInfo(input, probe) | ||
33 | |||
34 | let streamsToProcess: StreamType[] = [ 'audio', 'video' ] | ||
35 | |||
36 | if (!await hasAudioStream(input, probe)) { | ||
37 | command.noAudio() | ||
38 | streamsToProcess = [ 'video' ] | ||
39 | } | ||
40 | |||
41 | for (const streamType of streamsToProcess) { | ||
42 | const builderResult = await commandWrapper.getEncoderBuilderResult({ | ||
43 | ...pick(options, [ 'canCopyAudio', 'canCopyVideo' ]), | ||
44 | |||
45 | input, | ||
46 | inputBitrate: bitrate, | ||
47 | inputRatio: videoStreamDimensions?.ratio || 0, | ||
48 | |||
49 | resolution, | ||
50 | fps, | ||
51 | streamType, | ||
52 | |||
53 | videoType: 'vod' as 'vod' | ||
54 | }) | ||
55 | |||
56 | if (!builderResult) { | ||
57 | throw new Error('No available encoder found for stream ' + streamType) | ||
58 | } | ||
59 | |||
60 | commandWrapper.debugLog( | ||
61 | `Apply ffmpeg params from ${builderResult.encoder} for ${streamType} ` + | ||
62 | `stream of input ${input} using ${commandWrapper.getProfile()} profile.`, | ||
63 | { builderResult, resolution, fps } | ||
64 | ) | ||
65 | |||
66 | if (streamType === 'video') { | ||
67 | command.videoCodec(builderResult.encoder) | ||
68 | |||
69 | if (scaleFilterValue) { | ||
70 | command.outputOption(`-vf ${getScaleFilter(builderResult.result)}=${scaleFilterValue}`) | ||
71 | } | ||
72 | } else if (streamType === 'audio') { | ||
73 | command.audioCodec(builderResult.encoder) | ||
74 | } | ||
75 | |||
76 | applyEncoderOptions(command, builderResult.result) | ||
77 | addDefaultEncoderParams({ command, encoder: builderResult.encoder, fps }) | ||
78 | } | ||
79 | } | ||
80 | |||
81 | export function presetCopy (commandWrapper: FFmpegCommandWrapper) { | ||
82 | commandWrapper.getCommand() | ||
83 | .format('mp4') | ||
84 | .videoCodec('copy') | ||
85 | .audioCodec('copy') | ||
86 | } | ||
87 | |||
88 | export function presetOnlyAudio (commandWrapper: FFmpegCommandWrapper) { | ||
89 | commandWrapper.getCommand() | ||
90 | .format('mp4') | ||
91 | .audioCodec('copy') | ||
92 | .noVideo() | ||
93 | } | ||
diff --git a/shared/models/activitypub/activity.ts b/shared/models/activitypub/activity.ts deleted file mode 100644 index 10cf53ead..000000000 --- a/shared/models/activitypub/activity.ts +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | import { ActivityPubActor } from './activitypub-actor' | ||
2 | import { ActivityPubSignature } from './activitypub-signature' | ||
3 | import { | ||
4 | ActivityFlagReasonObject, | ||
5 | ActivityObject, | ||
6 | APObjectId, | ||
7 | CacheFileObject, | ||
8 | PlaylistObject, | ||
9 | VideoCommentObject, | ||
10 | VideoObject, | ||
11 | WatchActionObject | ||
12 | } from './objects' | ||
13 | |||
14 | export type ActivityUpdateObject = | ||
15 | Extract<ActivityObject, VideoObject | CacheFileObject | PlaylistObject | ActivityPubActor | string> | ActivityPubActor | ||
16 | |||
17 | // Cannot Extract from Activity because of circular reference | ||
18 | export type ActivityUndoObject = | ||
19 | ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate<CacheFileObject | string> | ActivityAnnounce | ||
20 | |||
21 | export type ActivityCreateObject = | ||
22 | Extract<ActivityObject, VideoObject | CacheFileObject | WatchActionObject | VideoCommentObject | PlaylistObject | string> | ||
23 | |||
24 | export type Activity = | ||
25 | ActivityCreate<ActivityCreateObject> | | ||
26 | ActivityUpdate<ActivityUpdateObject> | | ||
27 | ActivityDelete | | ||
28 | ActivityFollow | | ||
29 | ActivityAccept | | ||
30 | ActivityAnnounce | | ||
31 | ActivityUndo<ActivityUndoObject> | | ||
32 | ActivityLike | | ||
33 | ActivityReject | | ||
34 | ActivityView | | ||
35 | ActivityDislike | | ||
36 | ActivityFlag | ||
37 | |||
38 | export type ActivityType = | ||
39 | 'Create' | | ||
40 | 'Update' | | ||
41 | 'Delete' | | ||
42 | 'Follow' | | ||
43 | 'Accept' | | ||
44 | 'Announce' | | ||
45 | 'Undo' | | ||
46 | 'Like' | | ||
47 | 'Reject' | | ||
48 | 'View' | | ||
49 | 'Dislike' | | ||
50 | 'Flag' | ||
51 | |||
52 | export interface ActivityAudience { | ||
53 | to: string[] | ||
54 | cc: string[] | ||
55 | } | ||
56 | |||
57 | export interface BaseActivity { | ||
58 | '@context'?: any[] | ||
59 | id: string | ||
60 | to?: string[] | ||
61 | cc?: string[] | ||
62 | actor: string | ActivityPubActor | ||
63 | type: ActivityType | ||
64 | signature?: ActivityPubSignature | ||
65 | } | ||
66 | |||
67 | export interface ActivityCreate <T extends ActivityCreateObject> extends BaseActivity { | ||
68 | type: 'Create' | ||
69 | object: T | ||
70 | } | ||
71 | |||
72 | export interface ActivityUpdate <T extends ActivityUpdateObject> extends BaseActivity { | ||
73 | type: 'Update' | ||
74 | object: T | ||
75 | } | ||
76 | |||
77 | export interface ActivityDelete extends BaseActivity { | ||
78 | type: 'Delete' | ||
79 | object: APObjectId | ||
80 | } | ||
81 | |||
82 | export interface ActivityFollow extends BaseActivity { | ||
83 | type: 'Follow' | ||
84 | object: string | ||
85 | } | ||
86 | |||
87 | export interface ActivityAccept extends BaseActivity { | ||
88 | type: 'Accept' | ||
89 | object: ActivityFollow | ||
90 | } | ||
91 | |||
92 | export interface ActivityReject extends BaseActivity { | ||
93 | type: 'Reject' | ||
94 | object: ActivityFollow | ||
95 | } | ||
96 | |||
97 | export interface ActivityAnnounce extends BaseActivity { | ||
98 | type: 'Announce' | ||
99 | object: APObjectId | ||
100 | } | ||
101 | |||
102 | export interface ActivityUndo <T extends ActivityUndoObject> extends BaseActivity { | ||
103 | type: 'Undo' | ||
104 | object: T | ||
105 | } | ||
106 | |||
107 | export interface ActivityLike extends BaseActivity { | ||
108 | type: 'Like' | ||
109 | object: APObjectId | ||
110 | } | ||
111 | |||
112 | export interface ActivityView extends BaseActivity { | ||
113 | type: 'View' | ||
114 | actor: string | ||
115 | object: APObjectId | ||
116 | |||
117 | // If sending a "viewer" event | ||
118 | expires?: string | ||
119 | } | ||
120 | |||
121 | export interface ActivityDislike extends BaseActivity { | ||
122 | id: string | ||
123 | type: 'Dislike' | ||
124 | actor: string | ||
125 | object: APObjectId | ||
126 | } | ||
127 | |||
128 | export interface ActivityFlag extends BaseActivity { | ||
129 | type: 'Flag' | ||
130 | content: string | ||
131 | object: APObjectId | APObjectId[] | ||
132 | tag?: ActivityFlagReasonObject[] | ||
133 | startAt?: number | ||
134 | endAt?: number | ||
135 | } | ||
diff --git a/shared/models/activitypub/activitypub-actor.ts b/shared/models/activitypub/activitypub-actor.ts deleted file mode 100644 index b86bcb764..000000000 --- a/shared/models/activitypub/activitypub-actor.ts +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | import { ActivityIconObject, ActivityPubAttributedTo } from './objects/common-objects' | ||
2 | |||
3 | export type ActivityPubActorType = 'Person' | 'Application' | 'Group' | 'Service' | 'Organization' | ||
4 | |||
5 | export interface ActivityPubActor { | ||
6 | '@context': any[] | ||
7 | type: ActivityPubActorType | ||
8 | id: string | ||
9 | following: string | ||
10 | followers: string | ||
11 | playlists?: string | ||
12 | inbox: string | ||
13 | outbox: string | ||
14 | preferredUsername: string | ||
15 | url: string | ||
16 | name: string | ||
17 | endpoints: { | ||
18 | sharedInbox: string | ||
19 | } | ||
20 | summary: string | ||
21 | attributedTo: ActivityPubAttributedTo[] | ||
22 | |||
23 | support?: string | ||
24 | publicKey: { | ||
25 | id: string | ||
26 | owner: string | ||
27 | publicKeyPem: string | ||
28 | } | ||
29 | |||
30 | image?: ActivityIconObject | ActivityIconObject[] | ||
31 | icon?: ActivityIconObject | ActivityIconObject[] | ||
32 | |||
33 | published?: string | ||
34 | } | ||
diff --git a/shared/models/activitypub/activitypub-collection.ts b/shared/models/activitypub/activitypub-collection.ts deleted file mode 100644 index 60a6a6b04..000000000 --- a/shared/models/activitypub/activitypub-collection.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | import { Activity } from './activity' | ||
2 | |||
3 | export interface ActivityPubCollection { | ||
4 | '@context': string[] | ||
5 | type: 'Collection' | 'CollectionPage' | ||
6 | totalItems: number | ||
7 | partOf?: string | ||
8 | items: Activity[] | ||
9 | } | ||
diff --git a/shared/models/activitypub/activitypub-ordered-collection.ts b/shared/models/activitypub/activitypub-ordered-collection.ts deleted file mode 100644 index 3de0890bb..000000000 --- a/shared/models/activitypub/activitypub-ordered-collection.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | export interface ActivityPubOrderedCollection<T> { | ||
2 | '@context': string[] | ||
3 | type: 'OrderedCollection' | 'OrderedCollectionPage' | ||
4 | totalItems: number | ||
5 | orderedItems: T[] | ||
6 | |||
7 | partOf?: string | ||
8 | next?: string | ||
9 | first?: string | ||
10 | } | ||
diff --git a/shared/models/activitypub/activitypub-root.ts b/shared/models/activitypub/activitypub-root.ts deleted file mode 100644 index 22dff83a2..000000000 --- a/shared/models/activitypub/activitypub-root.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | import { Activity } from './activity' | ||
2 | import { ActivityPubCollection } from './activitypub-collection' | ||
3 | import { ActivityPubOrderedCollection } from './activitypub-ordered-collection' | ||
4 | |||
5 | export type RootActivity = Activity | ActivityPubCollection | ActivityPubOrderedCollection<Activity> | ||
diff --git a/shared/models/activitypub/activitypub-signature.ts b/shared/models/activitypub/activitypub-signature.ts deleted file mode 100644 index fafdc246d..000000000 --- a/shared/models/activitypub/activitypub-signature.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export interface ActivityPubSignature { | ||
2 | type: string | ||
3 | created: Date | ||
4 | creator: string | ||
5 | signatureValue: string | ||
6 | } | ||
diff --git a/shared/models/activitypub/context.ts b/shared/models/activitypub/context.ts deleted file mode 100644 index e9df38207..000000000 --- a/shared/models/activitypub/context.ts +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | export type ContextType = | ||
2 | 'Video' | | ||
3 | 'Comment' | | ||
4 | 'Playlist' | | ||
5 | 'Follow' | | ||
6 | 'Reject' | | ||
7 | 'Accept' | | ||
8 | 'View' | | ||
9 | 'Announce' | | ||
10 | 'CacheFile' | | ||
11 | 'Delete' | | ||
12 | 'Rate' | | ||
13 | 'Flag' | | ||
14 | 'Actor' | | ||
15 | 'Collection' | | ||
16 | 'WatchAction' | ||
diff --git a/shared/models/activitypub/index.ts b/shared/models/activitypub/index.ts deleted file mode 100644 index fa07b6a64..000000000 --- a/shared/models/activitypub/index.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | export * from './objects' | ||
2 | export * from './activity' | ||
3 | export * from './activitypub-actor' | ||
4 | export * from './activitypub-collection' | ||
5 | export * from './activitypub-ordered-collection' | ||
6 | export * from './activitypub-root' | ||
7 | export * from './activitypub-signature' | ||
8 | export * from './context' | ||
9 | export * from './webfinger' | ||
diff --git a/shared/models/activitypub/objects/abuse-object.ts b/shared/models/activitypub/objects/abuse-object.ts deleted file mode 100644 index d938b8693..000000000 --- a/shared/models/activitypub/objects/abuse-object.ts +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | import { ActivityFlagReasonObject } from './common-objects' | ||
2 | |||
3 | export interface AbuseObject { | ||
4 | type: 'Flag' | ||
5 | |||
6 | content: string | ||
7 | mediaType: 'text/markdown' | ||
8 | |||
9 | object: string | string[] | ||
10 | |||
11 | tag?: ActivityFlagReasonObject[] | ||
12 | |||
13 | startAt?: number | ||
14 | endAt?: number | ||
15 | } | ||
diff --git a/shared/models/activitypub/objects/activitypub-object.ts b/shared/models/activitypub/objects/activitypub-object.ts deleted file mode 100644 index faeac2618..000000000 --- a/shared/models/activitypub/objects/activitypub-object.ts +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | import { AbuseObject } from './abuse-object' | ||
2 | import { CacheFileObject } from './cache-file-object' | ||
3 | import { PlaylistObject } from './playlist-object' | ||
4 | import { VideoCommentObject } from './video-comment-object' | ||
5 | import { VideoObject } from './video-object' | ||
6 | import { WatchActionObject } from './watch-action-object' | ||
7 | |||
8 | export type ActivityObject = | ||
9 | VideoObject | | ||
10 | AbuseObject | | ||
11 | VideoCommentObject | | ||
12 | CacheFileObject | | ||
13 | PlaylistObject | | ||
14 | WatchActionObject | | ||
15 | string | ||
16 | |||
17 | export type APObjectId = string | { id: string } | ||
diff --git a/shared/models/activitypub/objects/cache-file-object.ts b/shared/models/activitypub/objects/cache-file-object.ts deleted file mode 100644 index 19a817582..000000000 --- a/shared/models/activitypub/objects/cache-file-object.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | import { ActivityVideoUrlObject, ActivityPlaylistUrlObject } from './common-objects' | ||
2 | |||
3 | export interface CacheFileObject { | ||
4 | id: string | ||
5 | type: 'CacheFile' | ||
6 | object: string | ||
7 | expires: string | ||
8 | url: ActivityVideoUrlObject | ActivityPlaylistUrlObject | ||
9 | } | ||
diff --git a/shared/models/activitypub/objects/common-objects.ts b/shared/models/activitypub/objects/common-objects.ts deleted file mode 100644 index db9c73658..000000000 --- a/shared/models/activitypub/objects/common-objects.ts +++ /dev/null | |||
@@ -1,130 +0,0 @@ | |||
1 | import { AbusePredefinedReasonsString } from '../../moderation/abuse/abuse-reason.model' | ||
2 | |||
3 | export interface ActivityIdentifierObject { | ||
4 | identifier: string | ||
5 | name: string | ||
6 | url?: string | ||
7 | } | ||
8 | |||
9 | export interface ActivityIconObject { | ||
10 | type: 'Image' | ||
11 | url: string | ||
12 | mediaType: string | ||
13 | width?: number | ||
14 | height?: number | ||
15 | } | ||
16 | |||
17 | export type ActivityVideoUrlObject = { | ||
18 | type: 'Link' | ||
19 | mediaType: 'video/mp4' | 'video/webm' | 'video/ogg' | ||
20 | href: string | ||
21 | height: number | ||
22 | size: number | ||
23 | fps: number | ||
24 | } | ||
25 | |||
26 | export type ActivityPlaylistSegmentHashesObject = { | ||
27 | type: 'Link' | ||
28 | name: 'sha256' | ||
29 | mediaType: 'application/json' | ||
30 | href: string | ||
31 | } | ||
32 | |||
33 | export type ActivityVideoFileMetadataUrlObject = { | ||
34 | type: 'Link' | ||
35 | rel: [ 'metadata', any ] | ||
36 | mediaType: 'application/json' | ||
37 | height: number | ||
38 | href: string | ||
39 | fps: number | ||
40 | } | ||
41 | |||
42 | export type ActivityTrackerUrlObject = { | ||
43 | type: 'Link' | ||
44 | rel: [ 'tracker', 'websocket' | 'http' ] | ||
45 | name: string | ||
46 | href: string | ||
47 | } | ||
48 | |||
49 | export type ActivityStreamingPlaylistInfohashesObject = { | ||
50 | type: 'Infohash' | ||
51 | name: string | ||
52 | } | ||
53 | |||
54 | export type ActivityPlaylistUrlObject = { | ||
55 | type: 'Link' | ||
56 | mediaType: 'application/x-mpegURL' | ||
57 | href: string | ||
58 | tag?: ActivityTagObject[] | ||
59 | } | ||
60 | |||
61 | export type ActivityBitTorrentUrlObject = { | ||
62 | type: 'Link' | ||
63 | mediaType: 'application/x-bittorrent' | 'application/x-bittorrent;x-scheme-handler/magnet' | ||
64 | href: string | ||
65 | height: number | ||
66 | } | ||
67 | |||
68 | export type ActivityMagnetUrlObject = { | ||
69 | type: 'Link' | ||
70 | mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' | ||
71 | href: string | ||
72 | height: number | ||
73 | } | ||
74 | |||
75 | export type ActivityHtmlUrlObject = { | ||
76 | type: 'Link' | ||
77 | mediaType: 'text/html' | ||
78 | href: string | ||
79 | } | ||
80 | |||
81 | export interface ActivityHashTagObject { | ||
82 | type: 'Hashtag' | ||
83 | href?: string | ||
84 | name: string | ||
85 | } | ||
86 | |||
87 | export interface ActivityMentionObject { | ||
88 | type: 'Mention' | ||
89 | href?: string | ||
90 | name: string | ||
91 | } | ||
92 | |||
93 | export interface ActivityFlagReasonObject { | ||
94 | type: 'Hashtag' | ||
95 | name: AbusePredefinedReasonsString | ||
96 | } | ||
97 | |||
98 | export type ActivityTagObject = | ||
99 | ActivityPlaylistSegmentHashesObject | ||
100 | | ActivityStreamingPlaylistInfohashesObject | ||
101 | | ActivityVideoUrlObject | ||
102 | | ActivityHashTagObject | ||
103 | | ActivityMentionObject | ||
104 | | ActivityBitTorrentUrlObject | ||
105 | | ActivityMagnetUrlObject | ||
106 | | ActivityVideoFileMetadataUrlObject | ||
107 | |||
108 | export type ActivityUrlObject = | ||
109 | ActivityVideoUrlObject | ||
110 | | ActivityPlaylistUrlObject | ||
111 | | ActivityBitTorrentUrlObject | ||
112 | | ActivityMagnetUrlObject | ||
113 | | ActivityHtmlUrlObject | ||
114 | | ActivityVideoFileMetadataUrlObject | ||
115 | | ActivityTrackerUrlObject | ||
116 | |||
117 | export type ActivityPubAttributedTo = { type: 'Group' | 'Person', id: string } | string | ||
118 | |||
119 | export interface ActivityTombstoneObject { | ||
120 | '@context'?: any | ||
121 | id: string | ||
122 | url?: string | ||
123 | type: 'Tombstone' | ||
124 | name?: string | ||
125 | formerType?: string | ||
126 | inReplyTo?: string | ||
127 | published: string | ||
128 | updated: string | ||
129 | deleted: string | ||
130 | } | ||
diff --git a/shared/models/activitypub/objects/index.ts b/shared/models/activitypub/objects/index.ts deleted file mode 100644 index 753e02003..000000000 --- a/shared/models/activitypub/objects/index.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | export * from './abuse-object' | ||
2 | export * from './activitypub-object' | ||
3 | export * from './cache-file-object' | ||
4 | export * from './common-objects' | ||
5 | export * from './playlist-element-object' | ||
6 | export * from './playlist-object' | ||
7 | export * from './video-comment-object' | ||
8 | export * from './video-object' | ||
9 | export * from './watch-action-object' | ||
diff --git a/shared/models/activitypub/objects/playlist-element-object.ts b/shared/models/activitypub/objects/playlist-element-object.ts deleted file mode 100644 index b85e4fe19..000000000 --- a/shared/models/activitypub/objects/playlist-element-object.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | export interface PlaylistElementObject { | ||
2 | id: string | ||
3 | type: 'PlaylistElement' | ||
4 | |||
5 | url: string | ||
6 | position: number | ||
7 | |||
8 | startTimestamp?: number | ||
9 | stopTimestamp?: number | ||
10 | } | ||
diff --git a/shared/models/activitypub/objects/playlist-object.ts b/shared/models/activitypub/objects/playlist-object.ts deleted file mode 100644 index 0ccb71828..000000000 --- a/shared/models/activitypub/objects/playlist-object.ts +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | import { ActivityIconObject, ActivityPubAttributedTo } from './common-objects' | ||
2 | |||
3 | export interface PlaylistObject { | ||
4 | id: string | ||
5 | type: 'Playlist' | ||
6 | |||
7 | name: string | ||
8 | |||
9 | content: string | ||
10 | mediaType: 'text/markdown' | ||
11 | |||
12 | uuid: string | ||
13 | |||
14 | totalItems: number | ||
15 | attributedTo: ActivityPubAttributedTo[] | ||
16 | |||
17 | icon?: ActivityIconObject | ||
18 | |||
19 | published: string | ||
20 | updated: string | ||
21 | |||
22 | orderedItems?: string[] | ||
23 | |||
24 | partOf?: string | ||
25 | next?: string | ||
26 | first?: string | ||
27 | |||
28 | to?: string[] | ||
29 | } | ||
diff --git a/shared/models/activitypub/objects/video-comment-object.ts b/shared/models/activitypub/objects/video-comment-object.ts deleted file mode 100644 index fb1e6f8db..000000000 --- a/shared/models/activitypub/objects/video-comment-object.ts +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | import { ActivityPubAttributedTo, ActivityTagObject } from './common-objects' | ||
2 | |||
3 | export interface VideoCommentObject { | ||
4 | type: 'Note' | ||
5 | id: string | ||
6 | |||
7 | content: string | ||
8 | mediaType: 'text/markdown' | ||
9 | |||
10 | inReplyTo: string | ||
11 | published: string | ||
12 | updated: string | ||
13 | url: string | ||
14 | attributedTo: ActivityPubAttributedTo | ||
15 | tag: ActivityTagObject[] | ||
16 | } | ||
diff --git a/shared/models/activitypub/objects/video-object.ts b/shared/models/activitypub/objects/video-object.ts deleted file mode 100644 index 409504f0f..000000000 --- a/shared/models/activitypub/objects/video-object.ts +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | import { | ||
2 | ActivityIconObject, | ||
3 | ActivityIdentifierObject, | ||
4 | ActivityPubAttributedTo, | ||
5 | ActivityTagObject, | ||
6 | ActivityUrlObject | ||
7 | } from './common-objects' | ||
8 | import { LiveVideoLatencyMode, VideoState } from '../../videos' | ||
9 | |||
10 | export interface VideoObject { | ||
11 | type: 'Video' | ||
12 | id: string | ||
13 | name: string | ||
14 | duration: string | ||
15 | uuid: string | ||
16 | tag: ActivityTagObject[] | ||
17 | category: ActivityIdentifierObject | ||
18 | licence: ActivityIdentifierObject | ||
19 | language: ActivityIdentifierObject | ||
20 | subtitleLanguage: ActivityIdentifierObject[] | ||
21 | views: number | ||
22 | |||
23 | sensitive: boolean | ||
24 | |||
25 | isLiveBroadcast: boolean | ||
26 | liveSaveReplay: boolean | ||
27 | permanentLive: boolean | ||
28 | latencyMode: LiveVideoLatencyMode | ||
29 | |||
30 | commentsEnabled: boolean | ||
31 | downloadEnabled: boolean | ||
32 | waitTranscoding: boolean | ||
33 | state: VideoState | ||
34 | |||
35 | published: string | ||
36 | originallyPublishedAt: string | ||
37 | updated: string | ||
38 | uploadDate: string | ||
39 | |||
40 | mediaType: 'text/markdown' | ||
41 | content: string | ||
42 | |||
43 | support: string | ||
44 | |||
45 | icon: ActivityIconObject[] | ||
46 | |||
47 | url: ActivityUrlObject[] | ||
48 | |||
49 | likes: string | ||
50 | dislikes: string | ||
51 | shares: string | ||
52 | comments: string | ||
53 | |||
54 | attributedTo: ActivityPubAttributedTo[] | ||
55 | |||
56 | preview?: ActivityPubStoryboard[] | ||
57 | |||
58 | to?: string[] | ||
59 | cc?: string[] | ||
60 | } | ||
61 | |||
62 | export interface ActivityPubStoryboard { | ||
63 | type: 'Image' | ||
64 | rel: [ 'storyboard' ] | ||
65 | url: { | ||
66 | href: string | ||
67 | mediaType: string | ||
68 | width: number | ||
69 | height: number | ||
70 | tileWidth: number | ||
71 | tileHeight: number | ||
72 | tileDuration: string | ||
73 | }[] | ||
74 | } | ||
diff --git a/shared/models/activitypub/objects/watch-action-object.ts b/shared/models/activitypub/objects/watch-action-object.ts deleted file mode 100644 index ed336602f..000000000 --- a/shared/models/activitypub/objects/watch-action-object.ts +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | export interface WatchActionObject { | ||
2 | id: string | ||
3 | type: 'WatchAction' | ||
4 | |||
5 | startTime: string | ||
6 | endTime: string | ||
7 | |||
8 | location?: { | ||
9 | addressCountry: string | ||
10 | } | ||
11 | |||
12 | uuid: string | ||
13 | object: string | ||
14 | actionStatus: 'CompletedActionStatus' | ||
15 | |||
16 | duration: string | ||
17 | |||
18 | watchSections: { | ||
19 | startTimestamp: number | ||
20 | endTimestamp: number | ||
21 | }[] | ||
22 | } | ||
diff --git a/shared/models/activitypub/webfinger.ts b/shared/models/activitypub/webfinger.ts deleted file mode 100644 index b94baf996..000000000 --- a/shared/models/activitypub/webfinger.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | export interface WebFingerData { | ||
2 | subject: string | ||
3 | aliases: string[] | ||
4 | links: { | ||
5 | rel: 'self' | ||
6 | type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' | ||
7 | href: string | ||
8 | }[] | ||
9 | } | ||
diff --git a/shared/models/actors/account.model.ts b/shared/models/actors/account.model.ts deleted file mode 100644 index 9fbec60ba..000000000 --- a/shared/models/actors/account.model.ts +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | import { ActorImage } from './actor-image.model' | ||
2 | import { Actor } from './actor.model' | ||
3 | |||
4 | export interface Account extends Actor { | ||
5 | displayName: string | ||
6 | description: string | ||
7 | avatars: ActorImage[] | ||
8 | |||
9 | updatedAt: Date | string | ||
10 | |||
11 | userId?: number | ||
12 | } | ||
13 | |||
14 | export interface AccountSummary { | ||
15 | id: number | ||
16 | name: string | ||
17 | displayName: string | ||
18 | url: string | ||
19 | host: string | ||
20 | |||
21 | avatars: ActorImage[] | ||
22 | } | ||
diff --git a/shared/models/actors/actor-image.model.ts b/shared/models/actors/actor-image.model.ts deleted file mode 100644 index cfe44ac15..000000000 --- a/shared/models/actors/actor-image.model.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | export interface ActorImage { | ||
2 | width: number | ||
3 | path: string | ||
4 | |||
5 | url?: string | ||
6 | |||
7 | createdAt: Date | string | ||
8 | updatedAt: Date | string | ||
9 | } | ||
diff --git a/shared/models/actors/actor-image.type.ts b/shared/models/actors/actor-image.type.ts deleted file mode 100644 index ac8eb6bf2..000000000 --- a/shared/models/actors/actor-image.type.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export const enum ActorImageType { | ||
2 | AVATAR = 1, | ||
3 | BANNER = 2 | ||
4 | } | ||
diff --git a/shared/models/actors/actor.model.ts b/shared/models/actors/actor.model.ts deleted file mode 100644 index ab0760263..000000000 --- a/shared/models/actors/actor.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { ActorImage } from './actor-image.model' | ||
2 | |||
3 | export interface Actor { | ||
4 | id: number | ||
5 | url: string | ||
6 | name: string | ||
7 | host: string | ||
8 | followingCount: number | ||
9 | followersCount: number | ||
10 | createdAt: Date | string | ||
11 | |||
12 | avatars: ActorImage[] | ||
13 | } | ||
diff --git a/shared/models/actors/custom-page.model.ts b/shared/models/actors/custom-page.model.ts deleted file mode 100644 index 1e33584c1..000000000 --- a/shared/models/actors/custom-page.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface CustomPage { | ||
2 | content: string | ||
3 | } | ||
diff --git a/shared/models/actors/follow.model.ts b/shared/models/actors/follow.model.ts deleted file mode 100644 index 244d6d97e..000000000 --- a/shared/models/actors/follow.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { Actor } from './actor.model' | ||
2 | |||
3 | export type FollowState = 'pending' | 'accepted' | 'rejected' | ||
4 | |||
5 | export interface ActorFollow { | ||
6 | id: number | ||
7 | follower: Actor & { hostRedundancyAllowed: boolean } | ||
8 | following: Actor & { hostRedundancyAllowed: boolean } | ||
9 | score: number | ||
10 | state: FollowState | ||
11 | createdAt: Date | ||
12 | updatedAt: Date | ||
13 | } | ||
diff --git a/shared/models/actors/index.ts b/shared/models/actors/index.ts deleted file mode 100644 index e03f168cd..000000000 --- a/shared/models/actors/index.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export * from './account.model' | ||
2 | export * from './actor-image.model' | ||
3 | export * from './actor-image.type' | ||
4 | export * from './actor.model' | ||
5 | export * from './custom-page.model' | ||
6 | export * from './follow.model' | ||
diff --git a/shared/models/bulk/bulk-remove-comments-of-body.model.ts b/shared/models/bulk/bulk-remove-comments-of-body.model.ts deleted file mode 100644 index 31e018c2a..000000000 --- a/shared/models/bulk/bulk-remove-comments-of-body.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface BulkRemoveCommentsOfBody { | ||
2 | accountName: string | ||
3 | scope: 'my-videos' | 'instance' | ||
4 | } | ||
diff --git a/shared/models/bulk/index.ts b/shared/models/bulk/index.ts deleted file mode 100644 index 168c8cd48..000000000 --- a/shared/models/bulk/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './bulk-remove-comments-of-body.model' | ||
diff --git a/shared/models/common/index.ts b/shared/models/common/index.ts deleted file mode 100644 index 4db85eff2..000000000 --- a/shared/models/common/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './result-list.model' | ||
diff --git a/shared/models/common/result-list.model.ts b/shared/models/common/result-list.model.ts deleted file mode 100644 index fcafcfb2f..000000000 --- a/shared/models/common/result-list.model.ts +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | export interface ResultList<T> { | ||
2 | total: number | ||
3 | data: T[] | ||
4 | } | ||
5 | |||
6 | export interface ThreadsResultList <T> extends ResultList <T> { | ||
7 | totalNotDeletedComments: number | ||
8 | } | ||
diff --git a/shared/models/custom-markup/custom-markup-data.model.ts b/shared/models/custom-markup/custom-markup-data.model.ts deleted file mode 100644 index 3e396052a..000000000 --- a/shared/models/custom-markup/custom-markup-data.model.ts +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | export type EmbedMarkupData = { | ||
2 | // Video or playlist uuid | ||
3 | uuid: string | ||
4 | } | ||
5 | |||
6 | export type VideoMiniatureMarkupData = { | ||
7 | // Video uuid | ||
8 | uuid: string | ||
9 | |||
10 | onlyDisplayTitle?: string // boolean | ||
11 | } | ||
12 | |||
13 | export type PlaylistMiniatureMarkupData = { | ||
14 | // Playlist uuid | ||
15 | uuid: string | ||
16 | } | ||
17 | |||
18 | export type ChannelMiniatureMarkupData = { | ||
19 | // Channel name (username) | ||
20 | name: string | ||
21 | |||
22 | displayLatestVideo?: string // boolean | ||
23 | displayDescription?: string // boolean | ||
24 | } | ||
25 | |||
26 | export type VideosListMarkupData = { | ||
27 | onlyDisplayTitle?: string // boolean | ||
28 | maxRows?: string // number | ||
29 | |||
30 | sort?: string | ||
31 | count?: string // number | ||
32 | |||
33 | categoryOneOf?: string // coma separated values, number[] | ||
34 | languageOneOf?: string // coma separated values | ||
35 | |||
36 | channelHandle?: string | ||
37 | accountHandle?: string | ||
38 | |||
39 | isLive?: string // number | ||
40 | |||
41 | onlyLocal?: string // boolean | ||
42 | } | ||
43 | |||
44 | export type ButtonMarkupData = { | ||
45 | theme: 'primary' | 'secondary' | ||
46 | href: string | ||
47 | label: string | ||
48 | blankTarget?: string // boolean | ||
49 | } | ||
50 | |||
51 | export type ContainerMarkupData = { | ||
52 | width?: string | ||
53 | title?: string | ||
54 | description?: string | ||
55 | layout?: 'row' | 'column' | ||
56 | |||
57 | justifyContent?: 'space-between' | 'normal' // default to 'space-between' | ||
58 | } | ||
diff --git a/shared/models/custom-markup/index.ts b/shared/models/custom-markup/index.ts deleted file mode 100644 index 2898dfa90..000000000 --- a/shared/models/custom-markup/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './custom-markup-data.model' | ||
diff --git a/shared/models/feeds/feed-format.enum.ts b/shared/models/feeds/feed-format.enum.ts deleted file mode 100644 index d3d574331..000000000 --- a/shared/models/feeds/feed-format.enum.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export const enum FeedFormat { | ||
2 | RSS = 'xml', | ||
3 | ATOM = 'atom', | ||
4 | JSON = 'json' | ||
5 | } | ||
diff --git a/shared/models/feeds/index.ts b/shared/models/feeds/index.ts deleted file mode 100644 index d56c8458c..000000000 --- a/shared/models/feeds/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './feed-format.enum' | ||
diff --git a/shared/models/http/http-error-codes.ts b/shared/models/http/http-error-codes.ts deleted file mode 100644 index 5ebff1cb5..000000000 --- a/shared/models/http/http-error-codes.ts +++ /dev/null | |||
@@ -1,364 +0,0 @@ | |||
1 | /** | ||
2 | * Hypertext Transfer Protocol (HTTP) response status codes. | ||
3 | * @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes} | ||
4 | * | ||
5 | * WebDAV and other codes useless with regards to PeerTube are not listed. | ||
6 | */ | ||
7 | export const enum HttpStatusCode { | ||
8 | |||
9 | /** | ||
10 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1 | ||
11 | * | ||
12 | * The server has received the request headers and the client should proceed to send the request body | ||
13 | * (in the case of a request for which a body needs to be sent; for example, a POST request). | ||
14 | * Sending a large request body to a server after a request has been rejected for inappropriate headers would be inefficient. | ||
15 | * To have a server check the request's headers, a client must send Expect: 100-continue as a header in its initial request | ||
16 | * and receive a 100 Continue status code in response before sending the body. The response 417 Expectation Failed indicates | ||
17 | * the request should not be continued. | ||
18 | */ | ||
19 | CONTINUE_100 = 100, | ||
20 | |||
21 | /** | ||
22 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.2 | ||
23 | * | ||
24 | * This code is sent in response to an Upgrade request header by the client, and indicates the protocol the server is switching too. | ||
25 | */ | ||
26 | SWITCHING_PROTOCOLS_101 = 101, | ||
27 | |||
28 | /** | ||
29 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.1 | ||
30 | * | ||
31 | * Standard response for successful HTTP requests. The actual response will depend on the request method used: | ||
32 | * GET: The resource has been fetched and is transmitted in the message body. | ||
33 | * HEAD: The entity headers are in the message body. | ||
34 | * POST: The resource describing the result of the action is transmitted in the message body. | ||
35 | * TRACE: The message body contains the request message as received by the server | ||
36 | */ | ||
37 | OK_200 = 200, | ||
38 | |||
39 | /** | ||
40 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.2 | ||
41 | * | ||
42 | * The request has been fulfilled, resulting in the creation of a new resource, typically after a PUT. | ||
43 | */ | ||
44 | CREATED_201 = 201, | ||
45 | |||
46 | /** | ||
47 | * The request has been accepted for processing, but the processing has not been completed. | ||
48 | * The request might or might not be eventually acted upon, and may be disallowed when processing occurs. | ||
49 | */ | ||
50 | ACCEPTED_202 = 202, | ||
51 | |||
52 | /** | ||
53 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.5 | ||
54 | * | ||
55 | * There is no content to send for this request, but the headers may be useful. | ||
56 | * The user-agent may update its cached headers for this resource with the new ones. | ||
57 | */ | ||
58 | NO_CONTENT_204 = 204, | ||
59 | |||
60 | /** | ||
61 | * The server successfully processed the request, but is not returning any content. | ||
62 | * Unlike a 204 response, this response requires that the requester reset the document view. | ||
63 | */ | ||
64 | RESET_CONTENT_205 = 205, | ||
65 | |||
66 | /** | ||
67 | * The server is delivering only part of the resource (byte serving) due to a range header sent by the client. | ||
68 | * The range header is used by HTTP clients to enable resuming of interrupted downloads, | ||
69 | * or split a download into multiple simultaneous streams. | ||
70 | */ | ||
71 | PARTIAL_CONTENT_206 = 206, | ||
72 | |||
73 | /** | ||
74 | * Indicates multiple options for the resource from which the client may choose (via agent-driven content negotiation). | ||
75 | * For example, this code could be used to present multiple video format options, | ||
76 | * to list files with different filename extensions, or to suggest word-sense disambiguation. | ||
77 | */ | ||
78 | MULTIPLE_CHOICES_300 = 300, | ||
79 | |||
80 | /** | ||
81 | * This and all future requests should be directed to the given URI. | ||
82 | */ | ||
83 | MOVED_PERMANENTLY_301 = 301, | ||
84 | |||
85 | /** | ||
86 | * This is an example of industry practice contradicting the standard. | ||
87 | * The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect | ||
88 | * (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 | ||
89 | * with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 | ||
90 | * to distinguish between the two behaviours. However, some Web applications and frameworks | ||
91 | * use the 302 status code as if it were the 303. | ||
92 | */ | ||
93 | FOUND_302 = 302, | ||
94 | |||
95 | /** | ||
96 | * SINCE HTTP/1.1 | ||
97 | * The response to the request can be found under another URI using a GET method. | ||
98 | * When received in response to a POST (or PUT/DELETE), the client should presume that | ||
99 | * the server has received the data and should issue a redirect with a separate GET message. | ||
100 | */ | ||
101 | SEE_OTHER_303 = 303, | ||
102 | |||
103 | /** | ||
104 | * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.1 | ||
105 | * | ||
106 | * Indicates that the resource has not been modified since the version specified by the request headers | ||
107 | * `If-Modified-Since` or `If-None-Match`. | ||
108 | * In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy. | ||
109 | */ | ||
110 | NOT_MODIFIED_304 = 304, | ||
111 | |||
112 | /** | ||
113 | * SINCE HTTP/1.1 | ||
114 | * In this case, the request should be repeated with another URI; however, future requests should still use the original URI. | ||
115 | * In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the | ||
116 | * original request. | ||
117 | * For example, a POST request should be repeated using another POST request. | ||
118 | */ | ||
119 | TEMPORARY_REDIRECT_307 = 307, | ||
120 | |||
121 | /** | ||
122 | * The request and all future requests should be repeated using another URI. | ||
123 | * 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change. | ||
124 | * So, for example, submitting a form to a permanently redirected resource may continue smoothly. | ||
125 | */ | ||
126 | PERMANENT_REDIRECT_308 = 308, | ||
127 | |||
128 | /** | ||
129 | * The server cannot or will not process the request due to an apparent client error | ||
130 | * (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing). | ||
131 | */ | ||
132 | BAD_REQUEST_400 = 400, | ||
133 | |||
134 | /** | ||
135 | * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.1 | ||
136 | * | ||
137 | * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet | ||
138 | * been provided. The response must include a `WWW-Authenticate` header field containing a challenge applicable to the | ||
139 | * requested resource. See Basic access authentication and Digest access authentication. 401 semantically means | ||
140 | * "unauthenticated",i.e. the user does not have the necessary credentials. | ||
141 | */ | ||
142 | UNAUTHORIZED_401 = 401, | ||
143 | |||
144 | /** | ||
145 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.2 | ||
146 | * | ||
147 | * Reserved for future use. The original intention was that this code might be used as part of some form of digital | ||
148 | * cash or micro payment scheme, but that has not happened, and this code is not usually used. | ||
149 | * Google Developers API uses this status if a particular developer has exceeded the daily limit on requests. | ||
150 | */ | ||
151 | PAYMENT_REQUIRED_402 = 402, | ||
152 | |||
153 | /** | ||
154 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.3 | ||
155 | * | ||
156 | * The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to | ||
157 | * give proper response. Unlike 401, the client's identity is known to the server. | ||
158 | */ | ||
159 | FORBIDDEN_403 = 403, | ||
160 | |||
161 | /** | ||
162 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2 | ||
163 | * | ||
164 | * The requested resource could not be found but may be available in the future. | ||
165 | * Subsequent requests by the client are permissible. | ||
166 | */ | ||
167 | NOT_FOUND_404 = 404, | ||
168 | |||
169 | /** | ||
170 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.5 | ||
171 | * | ||
172 | * A request method is not supported for the requested resource; | ||
173 | * for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource. | ||
174 | */ | ||
175 | METHOD_NOT_ALLOWED_405 = 405, | ||
176 | |||
177 | /** | ||
178 | * The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request. | ||
179 | */ | ||
180 | NOT_ACCEPTABLE_406 = 406, | ||
181 | |||
182 | /** | ||
183 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.7 | ||
184 | * | ||
185 | * This response is sent on an idle connection by some servers, even without any previous request by the client. | ||
186 | * It means that the server would like to shut down this unused connection. This response is used much more since | ||
187 | * some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also | ||
188 | * note that some servers merely shut down the connection without sending this message. | ||
189 | * | ||
190 | * @ | ||
191 | */ | ||
192 | REQUEST_TIMEOUT_408 = 408, | ||
193 | |||
194 | /** | ||
195 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.8 | ||
196 | * | ||
197 | * Indicates that the request could not be processed because of conflict in the request, | ||
198 | * such as an edit conflict between multiple simultaneous updates. | ||
199 | * | ||
200 | * @see HttpStatusCode.UNPROCESSABLE_ENTITY_422 to denote a disabled feature | ||
201 | */ | ||
202 | CONFLICT_409 = 409, | ||
203 | |||
204 | /** | ||
205 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.9 | ||
206 | * | ||
207 | * Indicates that the resource requested is no longer available and will not be available again. | ||
208 | * This should be used when a resource has been intentionally removed and the resource should be purged. | ||
209 | * Upon receiving a 410 status code, the client should not request the resource in the future. | ||
210 | * Clients such as search engines should remove the resource from their indices. | ||
211 | * Most use cases do not require clients and search engines to purge the resource, and a "404 Not Found" may be used instead. | ||
212 | */ | ||
213 | GONE_410 = 410, | ||
214 | |||
215 | /** | ||
216 | * The request did not specify the length of its content, which is required by the requested resource. | ||
217 | */ | ||
218 | LENGTH_REQUIRED_411 = 411, | ||
219 | |||
220 | /** | ||
221 | * The server does not meet one of the preconditions that the requester put on the request. | ||
222 | */ | ||
223 | PRECONDITION_FAILED_412 = 412, | ||
224 | |||
225 | /** | ||
226 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.11 | ||
227 | * | ||
228 | * The request is larger than the server is willing or able to process ; the server might close the connection | ||
229 | * or return an Retry-After header field. | ||
230 | * Previously called "Request Entity Too Large". | ||
231 | */ | ||
232 | PAYLOAD_TOO_LARGE_413 = 413, | ||
233 | |||
234 | /** | ||
235 | * The URI provided was too long for the server to process. Often the result of too much data being encoded as a | ||
236 | * query-string of a GET request, in which case it should be converted to a POST request. | ||
237 | * Called "Request-URI Too Long" previously. | ||
238 | */ | ||
239 | URI_TOO_LONG_414 = 414, | ||
240 | |||
241 | /** | ||
242 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.13 | ||
243 | * | ||
244 | * The request entity has a media type which the server or resource does not support. | ||
245 | * For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format. | ||
246 | */ | ||
247 | UNSUPPORTED_MEDIA_TYPE_415 = 415, | ||
248 | |||
249 | /** | ||
250 | * The client has asked for a portion of the file (byte serving), but the server cannot supply that portion. | ||
251 | * For example, if the client asked for a part of the file that lies beyond the end of the file. | ||
252 | * Called "Requested Range Not Satisfiable" previously. | ||
253 | */ | ||
254 | RANGE_NOT_SATISFIABLE_416 = 416, | ||
255 | |||
256 | /** | ||
257 | * The server cannot meet the requirements of the `Expect` request-header field. | ||
258 | */ | ||
259 | EXPECTATION_FAILED_417 = 417, | ||
260 | |||
261 | /** | ||
262 | * Official Documentation @ https://tools.ietf.org/html/rfc2324 | ||
263 | * | ||
264 | * This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol, | ||
265 | * and is not expected to be implemented by actual HTTP servers. The RFC specifies this code should be returned by | ||
266 | * teapots requested to brew coffee. This HTTP status is used as an Easter egg in some websites, including PeerTube instances ;-). | ||
267 | */ | ||
268 | I_AM_A_TEAPOT_418 = 418, | ||
269 | |||
270 | /** | ||
271 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.3 | ||
272 | * | ||
273 | * The request was well-formed but was unable to be followed due to semantic errors. | ||
274 | * The server understands the content type of the request entity (hence a 415 (Unsupported Media Type) status code is inappropriate), | ||
275 | * and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process | ||
276 | * the contained instructions. For example, this error condition may occur if an JSON request body contains well-formed (i.e., | ||
277 | * syntactically correct), but semantically erroneous, JSON instructions. | ||
278 | * | ||
279 | * Can also be used to denote disabled features (akin to disabled syntax). | ||
280 | * | ||
281 | * @see HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 if the `Content-Type` was not supported. | ||
282 | * @see HttpStatusCode.BAD_REQUEST_400 if the request was not parsable (broken JSON, XML) | ||
283 | */ | ||
284 | UNPROCESSABLE_ENTITY_422 = 422, | ||
285 | |||
286 | /** | ||
287 | * Official Documentation @ https://tools.ietf.org/html/rfc4918#section-11.3 | ||
288 | * | ||
289 | * The resource that is being accessed is locked. WebDAV-specific but used by some HTTP services. | ||
290 | * | ||
291 | * @deprecated use `If-Match` / `If-None-Match` instead | ||
292 | * @see {@link https://evertpot.com/http/423-locked} | ||
293 | */ | ||
294 | LOCKED_423 = 423, | ||
295 | |||
296 | /** | ||
297 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-4 | ||
298 | * | ||
299 | * The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes. | ||
300 | */ | ||
301 | TOO_MANY_REQUESTS_429 = 429, | ||
302 | |||
303 | /** | ||
304 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-5 | ||
305 | * | ||
306 | * The server is unwilling to process the request because either an individual header field, | ||
307 | * or all the header fields collectively, are too large. | ||
308 | */ | ||
309 | REQUEST_HEADER_FIELDS_TOO_LARGE_431 = 431, | ||
310 | |||
311 | /** | ||
312 | * Official Documentation @ https://tools.ietf.org/html/rfc7725 | ||
313 | * | ||
314 | * A server operator has received a legal demand to deny access to a resource or to a set of resources | ||
315 | * that includes the requested resource. The code 451 was chosen as a reference to the novel Fahrenheit 451. | ||
316 | */ | ||
317 | UNAVAILABLE_FOR_LEGAL_REASONS_451 = 451, | ||
318 | |||
319 | /** | ||
320 | * A generic error message, given when an unexpected condition was encountered and no more specific message is suitable. | ||
321 | */ | ||
322 | INTERNAL_SERVER_ERROR_500 = 500, | ||
323 | |||
324 | /** | ||
325 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2 | ||
326 | * | ||
327 | * The server either does not recognize the request method, or it lacks the ability to fulfill the request. | ||
328 | * Usually this implies future availability (e.g., a new feature of a web-service API). | ||
329 | */ | ||
330 | NOT_IMPLEMENTED_501 = 501, | ||
331 | |||
332 | /** | ||
333 | * The server was acting as a gateway or proxy and received an invalid response from the upstream server. | ||
334 | */ | ||
335 | BAD_GATEWAY_502 = 502, | ||
336 | |||
337 | /** | ||
338 | * The server is currently unavailable (because it is overloaded or down for maintenance). | ||
339 | * Generally, this is a temporary state. | ||
340 | */ | ||
341 | SERVICE_UNAVAILABLE_503 = 503, | ||
342 | |||
343 | /** | ||
344 | * The server was acting as a gateway or proxy and did not receive a timely response from the upstream server. | ||
345 | */ | ||
346 | GATEWAY_TIMEOUT_504 = 504, | ||
347 | |||
348 | /** | ||
349 | * The server does not support the HTTP protocol version used in the request | ||
350 | */ | ||
351 | HTTP_VERSION_NOT_SUPPORTED_505 = 505, | ||
352 | |||
353 | /** | ||
354 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6 | ||
355 | * | ||
356 | * The 507 (Insufficient Storage) status code means the method could not be performed on the resource because the | ||
357 | * server is unable to store the representation needed to successfully complete the request. This condition is | ||
358 | * considered to be temporary. If the request which received this status code was the result of a user action, | ||
359 | * the request MUST NOT be repeated until it is requested by a separate user action. | ||
360 | * | ||
361 | * @see HttpStatusCode.PAYLOAD_TOO_LARGE_413 for quota errors | ||
362 | */ | ||
363 | INSUFFICIENT_STORAGE_507 = 507, | ||
364 | } | ||
diff --git a/shared/models/http/http-methods.ts b/shared/models/http/http-methods.ts deleted file mode 100644 index 3f4adafe2..000000000 --- a/shared/models/http/http-methods.ts +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | /** HTTP request method to indicate the desired action to be performed for a given resource. */ | ||
2 | export const enum HttpMethod { | ||
3 | /** The CONNECT method establishes a tunnel to the server identified by the target resource. */ | ||
4 | CONNECT = 'CONNECT', | ||
5 | /** The DELETE method deletes the specified resource. */ | ||
6 | DELETE = 'DELETE', | ||
7 | /** The GET method requests a representation of the specified resource. Requests using GET should only retrieve data. */ | ||
8 | GET = 'GET', | ||
9 | /** The HEAD method asks for a response identical to that of a GET request, but without the response body. */ | ||
10 | HEAD = 'HEAD', | ||
11 | /** The OPTIONS method is used to describe the communication options for the target resource. */ | ||
12 | OPTIONS = 'OPTIONS', | ||
13 | /** The PATCH method is used to apply partial modifications to a resource. */ | ||
14 | PATCH = 'PATCH', | ||
15 | /** The POST method is used to submit an entity to the specified resource */ | ||
16 | POST = 'POST', | ||
17 | /** The PUT method replaces all current representations of the target resource with the request payload. */ | ||
18 | PUT = 'PUT', | ||
19 | /** The TRACE method performs a message loop-back test along the path to the target resource. */ | ||
20 | TRACE = 'TRACE' | ||
21 | } | ||
diff --git a/shared/models/http/index.ts b/shared/models/http/index.ts deleted file mode 100644 index ec991afe0..000000000 --- a/shared/models/http/index.ts +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | export * from './http-error-codes' | ||
2 | export * from './http-methods' | ||
diff --git a/shared/models/index.ts b/shared/models/index.ts deleted file mode 100644 index 78f6e73e3..000000000 --- a/shared/models/index.ts +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | export * from './activitypub' | ||
2 | export * from './actors' | ||
3 | export * from './bulk' | ||
4 | export * from './common' | ||
5 | export * from './custom-markup' | ||
6 | export * from './feeds' | ||
7 | export * from './http' | ||
8 | export * from './joinpeertube' | ||
9 | export * from './metrics' | ||
10 | export * from './moderation' | ||
11 | export * from './overviews' | ||
12 | export * from './plugins' | ||
13 | export * from './redundancy' | ||
14 | export * from './runners' | ||
15 | export * from './search' | ||
16 | export * from './server' | ||
17 | export * from './tokens' | ||
18 | export * from './users' | ||
19 | export * from './videos' | ||
diff --git a/shared/models/joinpeertube/index.ts b/shared/models/joinpeertube/index.ts deleted file mode 100644 index 9681c35ad..000000000 --- a/shared/models/joinpeertube/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './versions.model' | ||
diff --git a/shared/models/joinpeertube/versions.model.ts b/shared/models/joinpeertube/versions.model.ts deleted file mode 100644 index 60a769150..000000000 --- a/shared/models/joinpeertube/versions.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface JoinPeerTubeVersions { | ||
2 | peertube: { | ||
3 | latestVersion: string | ||
4 | } | ||
5 | } | ||
diff --git a/shared/models/metrics/index.ts b/shared/models/metrics/index.ts deleted file mode 100644 index 24194cce3..000000000 --- a/shared/models/metrics/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './playback-metric-create.model' | ||
diff --git a/shared/models/metrics/playback-metric-create.model.ts b/shared/models/metrics/playback-metric-create.model.ts deleted file mode 100644 index 1d47421c3..000000000 --- a/shared/models/metrics/playback-metric-create.model.ts +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | import { VideoResolution } from '../videos' | ||
2 | |||
3 | export interface PlaybackMetricCreate { | ||
4 | playerMode: 'p2p-media-loader' | 'webtorrent' | 'web-video' // FIXME: remove webtorrent player mode not used anymore in PeerTube v6 | ||
5 | |||
6 | resolution?: VideoResolution | ||
7 | fps?: number | ||
8 | |||
9 | p2pEnabled: boolean | ||
10 | p2pPeers?: number | ||
11 | |||
12 | resolutionChanges: number | ||
13 | |||
14 | errors: number | ||
15 | |||
16 | downloadedBytesP2P: number | ||
17 | downloadedBytesHTTP: number | ||
18 | |||
19 | uploadedBytesP2P: number | ||
20 | |||
21 | videoId: number | string | ||
22 | } | ||
diff --git a/shared/models/moderation/abuse/abuse-create.model.ts b/shared/models/moderation/abuse/abuse-create.model.ts deleted file mode 100644 index 7d35555c3..000000000 --- a/shared/models/moderation/abuse/abuse-create.model.ts +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | import { AbusePredefinedReasonsString } from './abuse-reason.model' | ||
2 | |||
3 | export interface AbuseCreate { | ||
4 | reason: string | ||
5 | |||
6 | predefinedReasons?: AbusePredefinedReasonsString[] | ||
7 | |||
8 | account?: { | ||
9 | id: number | ||
10 | } | ||
11 | |||
12 | video?: { | ||
13 | id: number | string | ||
14 | startAt?: number | ||
15 | endAt?: number | ||
16 | } | ||
17 | |||
18 | comment?: { | ||
19 | id: number | ||
20 | } | ||
21 | } | ||
diff --git a/shared/models/moderation/abuse/abuse-filter.type.ts b/shared/models/moderation/abuse/abuse-filter.type.ts deleted file mode 100644 index 7dafc6d77..000000000 --- a/shared/models/moderation/abuse/abuse-filter.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type AbuseFilter = 'video' | 'comment' | 'account' | ||
diff --git a/shared/models/moderation/abuse/abuse-message.model.ts b/shared/models/moderation/abuse/abuse-message.model.ts deleted file mode 100644 index 9edd9daff..000000000 --- a/shared/models/moderation/abuse/abuse-message.model.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | import { AccountSummary } from '../../actors/account.model' | ||
2 | |||
3 | export interface AbuseMessage { | ||
4 | id: number | ||
5 | message: string | ||
6 | byModerator: boolean | ||
7 | createdAt: Date | string | ||
8 | |||
9 | account: AccountSummary | ||
10 | } | ||
diff --git a/shared/models/moderation/abuse/abuse-reason.model.ts b/shared/models/moderation/abuse/abuse-reason.model.ts deleted file mode 100644 index 57359aef6..000000000 --- a/shared/models/moderation/abuse/abuse-reason.model.ts +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | export const enum AbusePredefinedReasons { | ||
2 | VIOLENT_OR_REPULSIVE = 1, | ||
3 | HATEFUL_OR_ABUSIVE, | ||
4 | SPAM_OR_MISLEADING, | ||
5 | PRIVACY, | ||
6 | RIGHTS, | ||
7 | SERVER_RULES, | ||
8 | THUMBNAILS, | ||
9 | CAPTIONS | ||
10 | } | ||
11 | |||
12 | export type AbusePredefinedReasonsString = | ||
13 | 'violentOrRepulsive' | | ||
14 | 'hatefulOrAbusive' | | ||
15 | 'spamOrMisleading' | | ||
16 | 'privacy' | | ||
17 | 'rights' | | ||
18 | 'serverRules' | | ||
19 | 'thumbnails' | | ||
20 | 'captions' | ||
diff --git a/shared/models/moderation/abuse/abuse-state.model.ts b/shared/models/moderation/abuse/abuse-state.model.ts deleted file mode 100644 index 8ef6fdada..000000000 --- a/shared/models/moderation/abuse/abuse-state.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export const enum AbuseState { | ||
2 | PENDING = 1, | ||
3 | REJECTED = 2, | ||
4 | ACCEPTED = 3 | ||
5 | } | ||
diff --git a/shared/models/moderation/abuse/abuse-update.model.ts b/shared/models/moderation/abuse/abuse-update.model.ts deleted file mode 100644 index 4360fe7ac..000000000 --- a/shared/models/moderation/abuse/abuse-update.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | import { AbuseState } from './abuse-state.model' | ||
2 | |||
3 | export interface AbuseUpdate { | ||
4 | moderationComment?: string | ||
5 | |||
6 | state?: AbuseState | ||
7 | } | ||
diff --git a/shared/models/moderation/abuse/abuse-video-is.type.ts b/shared/models/moderation/abuse/abuse-video-is.type.ts deleted file mode 100644 index 74937f3b9..000000000 --- a/shared/models/moderation/abuse/abuse-video-is.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type AbuseVideoIs = 'deleted' | 'blacklisted' | ||
diff --git a/shared/models/moderation/abuse/abuse.model.ts b/shared/models/moderation/abuse/abuse.model.ts deleted file mode 100644 index 6048777ff..000000000 --- a/shared/models/moderation/abuse/abuse.model.ts +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | import { Account } from '../../actors/account.model' | ||
2 | import { AbuseState } from './abuse-state.model' | ||
3 | import { AbusePredefinedReasonsString } from './abuse-reason.model' | ||
4 | import { VideoConstant } from '../../videos/video-constant.model' | ||
5 | import { VideoChannel } from '../../videos/channel/video-channel.model' | ||
6 | |||
7 | export interface AdminVideoAbuse { | ||
8 | id: number | ||
9 | name: string | ||
10 | uuid: string | ||
11 | nsfw: boolean | ||
12 | |||
13 | deleted: boolean | ||
14 | blacklisted: boolean | ||
15 | |||
16 | startAt: number | null | ||
17 | endAt: number | null | ||
18 | |||
19 | thumbnailPath?: string | ||
20 | channel?: VideoChannel | ||
21 | |||
22 | countReports: number | ||
23 | nthReport: number | ||
24 | } | ||
25 | |||
26 | export interface AdminVideoCommentAbuse { | ||
27 | id: number | ||
28 | threadId: number | ||
29 | |||
30 | video: { | ||
31 | id: number | ||
32 | name: string | ||
33 | uuid: string | ||
34 | } | ||
35 | |||
36 | text: string | ||
37 | |||
38 | deleted: boolean | ||
39 | } | ||
40 | |||
41 | export interface AdminAbuse { | ||
42 | id: number | ||
43 | |||
44 | reason: string | ||
45 | predefinedReasons?: AbusePredefinedReasonsString[] | ||
46 | |||
47 | reporterAccount: Account | ||
48 | flaggedAccount: Account | ||
49 | |||
50 | state: VideoConstant<AbuseState> | ||
51 | moderationComment?: string | ||
52 | |||
53 | video?: AdminVideoAbuse | ||
54 | comment?: AdminVideoCommentAbuse | ||
55 | |||
56 | createdAt: Date | ||
57 | updatedAt: Date | ||
58 | |||
59 | countReportsForReporter?: number | ||
60 | countReportsForReportee?: number | ||
61 | |||
62 | countMessages: number | ||
63 | } | ||
64 | |||
65 | export type UserVideoAbuse = Omit<AdminVideoAbuse, 'countReports' | 'nthReport'> | ||
66 | |||
67 | export type UserVideoCommentAbuse = AdminVideoCommentAbuse | ||
68 | |||
69 | export type UserAbuse = Omit<AdminAbuse, 'reporterAccount' | 'countReportsForReportee' | 'countReportsForReporter' | 'startAt' | 'endAt' | ||
70 | | 'count' | 'nth' | 'moderationComment'> | ||
diff --git a/shared/models/moderation/abuse/index.ts b/shared/models/moderation/abuse/index.ts deleted file mode 100644 index b518517a6..000000000 --- a/shared/models/moderation/abuse/index.ts +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | export * from './abuse-create.model' | ||
2 | export * from './abuse-filter.type' | ||
3 | export * from './abuse-message.model' | ||
4 | export * from './abuse-reason.model' | ||
5 | export * from './abuse-state.model' | ||
6 | export * from './abuse-update.model' | ||
7 | export * from './abuse-video-is.type' | ||
8 | export * from './abuse.model' | ||
diff --git a/shared/models/moderation/account-block.model.ts b/shared/models/moderation/account-block.model.ts deleted file mode 100644 index a942ed614..000000000 --- a/shared/models/moderation/account-block.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | import { Account } from '../actors' | ||
2 | |||
3 | export interface AccountBlock { | ||
4 | byAccount: Account | ||
5 | blockedAccount: Account | ||
6 | createdAt: Date | string | ||
7 | } | ||
diff --git a/shared/models/moderation/block-status.model.ts b/shared/models/moderation/block-status.model.ts deleted file mode 100644 index 597312757..000000000 --- a/shared/models/moderation/block-status.model.ts +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | export interface BlockStatus { | ||
2 | accounts: { | ||
3 | [ handle: string ]: { | ||
4 | blockedByServer: boolean | ||
5 | blockedByUser?: boolean | ||
6 | } | ||
7 | } | ||
8 | |||
9 | hosts: { | ||
10 | [ host: string ]: { | ||
11 | blockedByServer: boolean | ||
12 | blockedByUser?: boolean | ||
13 | } | ||
14 | } | ||
15 | } | ||
diff --git a/shared/models/moderation/index.ts b/shared/models/moderation/index.ts deleted file mode 100644 index f8e6d351c..000000000 --- a/shared/models/moderation/index.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export * from './abuse' | ||
2 | export * from './block-status.model' | ||
3 | export * from './account-block.model' | ||
4 | export * from './server-block.model' | ||
diff --git a/shared/models/moderation/server-block.model.ts b/shared/models/moderation/server-block.model.ts deleted file mode 100644 index a8b8af0b7..000000000 --- a/shared/models/moderation/server-block.model.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | import { Account } from '../actors' | ||
2 | |||
3 | export interface ServerBlock { | ||
4 | byAccount: Account | ||
5 | blockedServer: { | ||
6 | host: string | ||
7 | } | ||
8 | createdAt: Date | string | ||
9 | } | ||
diff --git a/shared/models/nodeinfo/index.ts b/shared/models/nodeinfo/index.ts deleted file mode 100644 index faa64302a..000000000 --- a/shared/models/nodeinfo/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './nodeinfo.model' | ||
diff --git a/shared/models/nodeinfo/nodeinfo.model.ts b/shared/models/nodeinfo/nodeinfo.model.ts deleted file mode 100644 index 336cb66d2..000000000 --- a/shared/models/nodeinfo/nodeinfo.model.ts +++ /dev/null | |||
@@ -1,117 +0,0 @@ | |||
1 | /** | ||
2 | * NodeInfo schema version 2.0. | ||
3 | */ | ||
4 | export interface HttpNodeinfoDiasporaSoftwareNsSchema20 { | ||
5 | /** | ||
6 | * The schema version, must be 2.0. | ||
7 | */ | ||
8 | version: '2.0' | ||
9 | /** | ||
10 | * Metadata about server software in use. | ||
11 | */ | ||
12 | software: { | ||
13 | /** | ||
14 | * The canonical name of this server software. | ||
15 | */ | ||
16 | name: string | ||
17 | /** | ||
18 | * The version of this server software. | ||
19 | */ | ||
20 | version: string | ||
21 | } | ||
22 | /** | ||
23 | * The protocols supported on this server. | ||
24 | */ | ||
25 | protocols: ( | ||
26 | | 'activitypub' | ||
27 | | 'buddycloud' | ||
28 | | 'dfrn' | ||
29 | | 'diaspora' | ||
30 | | 'libertree' | ||
31 | | 'ostatus' | ||
32 | | 'pumpio' | ||
33 | | 'tent' | ||
34 | | 'xmpp' | ||
35 | | 'zot')[] | ||
36 | /** | ||
37 | * The third party sites this server can connect to via their application API. | ||
38 | */ | ||
39 | services: { | ||
40 | /** | ||
41 | * The third party sites this server can retrieve messages from for combined display with regular traffic. | ||
42 | */ | ||
43 | inbound: ('atom1.0' | 'gnusocial' | 'imap' | 'pnut' | 'pop3' | 'pumpio' | 'rss2.0' | 'twitter')[] | ||
44 | /** | ||
45 | * The third party sites this server can publish messages to on the behalf of a user. | ||
46 | */ | ||
47 | outbound: ( | ||
48 | | 'atom1.0' | ||
49 | | 'blogger' | ||
50 | | 'buddycloud' | ||
51 | | 'diaspora' | ||
52 | | 'dreamwidth' | ||
53 | | 'drupal' | ||
54 | | 'facebook' | ||
55 | | 'friendica' | ||
56 | | 'gnusocial' | ||
57 | | 'google' | ||
58 | | 'insanejournal' | ||
59 | | 'libertree' | ||
60 | | 'linkedin' | ||
61 | | 'livejournal' | ||
62 | | 'mediagoblin' | ||
63 | | 'myspace' | ||
64 | | 'pinterest' | ||
65 | | 'pnut' | ||
66 | | 'posterous' | ||
67 | | 'pumpio' | ||
68 | | 'redmatrix' | ||
69 | | 'rss2.0' | ||
70 | | 'smtp' | ||
71 | | 'tent' | ||
72 | | 'tumblr' | ||
73 | | 'twitter' | ||
74 | | 'wordpress' | ||
75 | | 'xmpp')[] | ||
76 | } | ||
77 | /** | ||
78 | * Whether this server allows open self-registration. | ||
79 | */ | ||
80 | openRegistrations: boolean | ||
81 | /** | ||
82 | * Usage statistics for this server. | ||
83 | */ | ||
84 | usage: { | ||
85 | /** | ||
86 | * statistics about the users of this server. | ||
87 | */ | ||
88 | users: { | ||
89 | /** | ||
90 | * The total amount of on this server registered users. | ||
91 | */ | ||
92 | total?: number | ||
93 | /** | ||
94 | * The amount of users that signed in at least once in the last 180 days. | ||
95 | */ | ||
96 | activeHalfyear?: number | ||
97 | /** | ||
98 | * The amount of users that signed in at least once in the last 30 days. | ||
99 | */ | ||
100 | activeMonth?: number | ||
101 | } | ||
102 | /** | ||
103 | * The amount of posts that were made by users that are registered on this server. | ||
104 | */ | ||
105 | localPosts?: number | ||
106 | /** | ||
107 | * The amount of comments that were made by users that are registered on this server. | ||
108 | */ | ||
109 | localComments?: number | ||
110 | } | ||
111 | /** | ||
112 | * Free form key value pairs for software specific values. Clients should not rely on any specific key present. | ||
113 | */ | ||
114 | metadata: { | ||
115 | [k: string]: any | ||
116 | } | ||
117 | } | ||
diff --git a/shared/models/overviews/index.ts b/shared/models/overviews/index.ts deleted file mode 100644 index 468507c6b..000000000 --- a/shared/models/overviews/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './videos-overview.model' | ||
diff --git a/shared/models/overviews/videos-overview.model.ts b/shared/models/overviews/videos-overview.model.ts deleted file mode 100644 index 0f3cb4a52..000000000 --- a/shared/models/overviews/videos-overview.model.ts +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | import { Video, VideoChannelSummary, VideoConstant } from '../videos' | ||
2 | |||
3 | export interface ChannelOverview { | ||
4 | channel: VideoChannelSummary | ||
5 | videos: Video[] | ||
6 | } | ||
7 | |||
8 | export interface CategoryOverview { | ||
9 | category: VideoConstant<number> | ||
10 | videos: Video[] | ||
11 | } | ||
12 | |||
13 | export interface TagOverview { | ||
14 | tag: string | ||
15 | videos: Video[] | ||
16 | } | ||
17 | |||
18 | export interface VideosOverview { | ||
19 | channels: ChannelOverview[] | ||
20 | |||
21 | categories: CategoryOverview[] | ||
22 | |||
23 | tags: TagOverview[] | ||
24 | } | ||
diff --git a/shared/models/plugins/client/client-hook.model.ts b/shared/models/plugins/client/client-hook.model.ts deleted file mode 100644 index 4a0818c99..000000000 --- a/shared/models/plugins/client/client-hook.model.ts +++ /dev/null | |||
@@ -1,195 +0,0 @@ | |||
1 | // Data from API hooks: {hookType}:api.{location}.{elementType}.{actionType}.{target} | ||
2 | // Data in internal functions: {hookType}:{location}.{elementType}.{actionType}.{target} | ||
3 | |||
4 | export const clientFilterHookObject = { | ||
5 | // Filter params/result of the function that fetch videos of the trending page | ||
6 | 'filter:api.trending-videos.videos.list.params': true, | ||
7 | 'filter:api.trending-videos.videos.list.result': true, | ||
8 | |||
9 | // Filter params/result of the function that fetch videos of the trending page | ||
10 | 'filter:api.most-liked-videos.videos.list.params': true, | ||
11 | 'filter:api.most-liked-videos.videos.list.result': true, | ||
12 | |||
13 | // Filter params/result of the function that fetch videos of the local page | ||
14 | 'filter:api.local-videos.videos.list.params': true, | ||
15 | 'filter:api.local-videos.videos.list.result': true, | ||
16 | |||
17 | // Filter params/result of the function that fetch videos of the recently-added page | ||
18 | 'filter:api.recently-added-videos.videos.list.params': true, | ||
19 | 'filter:api.recently-added-videos.videos.list.result': true, | ||
20 | |||
21 | // Filter params/result of the function that fetch videos of the user subscription page | ||
22 | 'filter:api.user-subscriptions-videos.videos.list.params': true, | ||
23 | 'filter:api.user-subscriptions-videos.videos.list.result': true, | ||
24 | |||
25 | // Filter params/result of the function that fetch the video of the video-watch page | ||
26 | 'filter:api.video-watch.video.get.params': true, | ||
27 | 'filter:api.video-watch.video.get.result': true, | ||
28 | |||
29 | // Filter params/result of the function that fetch video playlist elements of the video-watch page | ||
30 | 'filter:api.video-watch.video-playlist-elements.get.params': true, | ||
31 | 'filter:api.video-watch.video-playlist-elements.get.result': true, | ||
32 | |||
33 | // Filter params/result of the function that fetch the threads of the video-watch page | ||
34 | 'filter:api.video-watch.video-threads.list.params': true, | ||
35 | 'filter:api.video-watch.video-threads.list.result': true, | ||
36 | |||
37 | // Filter params/result of the function that fetch the replies of a thread in the video-watch page | ||
38 | 'filter:api.video-watch.video-thread-replies.list.params': true, | ||
39 | 'filter:api.video-watch.video-thread-replies.list.result': true, | ||
40 | |||
41 | // Filter params/result of the function that fetch videos according to the user search | ||
42 | 'filter:api.search.videos.list.params': true, | ||
43 | 'filter:api.search.videos.list.result': true, | ||
44 | // Filter params/result of the function that fetch video channels according to the user search | ||
45 | 'filter:api.search.video-channels.list.params': true, | ||
46 | 'filter:api.search.video-channels.list.result': true, | ||
47 | // Filter params/result of the function that fetch video playlists according to the user search | ||
48 | 'filter:api.search.video-playlists.list.params': true, | ||
49 | 'filter:api.search.video-playlists.list.result': true, | ||
50 | |||
51 | // Filter form | ||
52 | 'filter:api.signup.registration.create.params': true, | ||
53 | |||
54 | // Filter params/result of the function that fetch video playlist elements of the my-library page | ||
55 | 'filter:api.my-library.video-playlist-elements.list.params': true, | ||
56 | 'filter:api.my-library.video-playlist-elements.list.result': true, | ||
57 | |||
58 | // Filter the options to create our player | ||
59 | 'filter:internal.video-watch.player.build-options.params': true, | ||
60 | 'filter:internal.video-watch.player.build-options.result': true, | ||
61 | |||
62 | // Filter the options to load a new video in our player | ||
63 | 'filter:internal.video-watch.player.load-options.params': true, | ||
64 | 'filter:internal.video-watch.player.load-options.result': true, | ||
65 | |||
66 | // Filter our SVG icons content | ||
67 | 'filter:internal.common.svg-icons.get-content.params': true, | ||
68 | 'filter:internal.common.svg-icons.get-content.result': true, | ||
69 | |||
70 | // Filter left menu links | ||
71 | 'filter:left-menu.links.create.result': true, | ||
72 | |||
73 | // Filter upload page alert messages | ||
74 | 'filter:upload.messages.create.result': true, | ||
75 | |||
76 | 'filter:login.instance-about-plugin-panels.create.result': true, | ||
77 | 'filter:signup.instance-about-plugin-panels.create.result': true, | ||
78 | |||
79 | 'filter:share.video-embed-code.build.params': true, | ||
80 | 'filter:share.video-embed-code.build.result': true, | ||
81 | 'filter:share.video-playlist-embed-code.build.params': true, | ||
82 | 'filter:share.video-playlist-embed-code.build.result': true, | ||
83 | |||
84 | 'filter:share.video-embed-url.build.params': true, | ||
85 | 'filter:share.video-embed-url.build.result': true, | ||
86 | 'filter:share.video-playlist-embed-url.build.params': true, | ||
87 | 'filter:share.video-playlist-embed-url.build.result': true, | ||
88 | |||
89 | 'filter:share.video-url.build.params': true, | ||
90 | 'filter:share.video-url.build.result': true, | ||
91 | 'filter:share.video-playlist-url.build.params': true, | ||
92 | 'filter:share.video-playlist-url.build.result': true, | ||
93 | |||
94 | 'filter:video-watch.video-plugin-metadata.result': true, | ||
95 | |||
96 | // Filter videojs options built for PeerTube player | ||
97 | 'filter:internal.player.videojs.options.result': true, | ||
98 | |||
99 | // Filter p2p media loader options built for PeerTube player | ||
100 | 'filter:internal.player.p2p-media-loader.options.result': true | ||
101 | } | ||
102 | |||
103 | export type ClientFilterHookName = keyof typeof clientFilterHookObject | ||
104 | |||
105 | export const clientActionHookObject = { | ||
106 | // Fired when the application is being initialized | ||
107 | 'action:application.init': true, | ||
108 | |||
109 | // Fired when the video watch page is being initialized | ||
110 | 'action:video-watch.init': true, | ||
111 | // Fired when the video watch page loaded the video | ||
112 | 'action:video-watch.video.loaded': true, | ||
113 | // Fired when the player finished loading | ||
114 | 'action:video-watch.player.loaded': true, | ||
115 | // Fired when the video watch page comments(threads) are loaded and load more comments on scroll | ||
116 | 'action:video-watch.video-threads.loaded': true, | ||
117 | // Fired when a user click on 'View x replies' and they're loaded | ||
118 | 'action:video-watch.video-thread-replies.loaded': true, | ||
119 | |||
120 | // Fired when the video channel creation page is being initialized | ||
121 | 'action:video-channel-create.init': true, | ||
122 | |||
123 | // Fired when the video channel update page is being initialized | ||
124 | 'action:video-channel-update.init': true, | ||
125 | 'action:video-channel-update.video-channel.loaded': true, | ||
126 | |||
127 | // Fired when the page that list video channel videos is being initialized | ||
128 | 'action:video-channel-videos.init': true, | ||
129 | 'action:video-channel-videos.video-channel.loaded': true, | ||
130 | 'action:video-channel-videos.videos.loaded': true, | ||
131 | |||
132 | // Fired when the page that list video channel playlists is being initialized | ||
133 | 'action:video-channel-playlists.init': true, | ||
134 | 'action:video-channel-playlists.video-channel.loaded': true, | ||
135 | 'action:video-channel-playlists.playlists.loaded': true, | ||
136 | |||
137 | // Fired when the video edit page (upload, URL/torrent import, update) is being initialized | ||
138 | // Contains a `type` and `updateForm` object attributes | ||
139 | 'action:video-edit.init': true, | ||
140 | |||
141 | // Fired when values of the video edit form changed | ||
142 | 'action:video-edit.form.updated': true, | ||
143 | |||
144 | // Fired when the login page is being initialized | ||
145 | 'action:login.init': true, | ||
146 | |||
147 | // Fired when the search page is being initialized | ||
148 | 'action:search.init': true, | ||
149 | |||
150 | // Fired every time Angular URL changes | ||
151 | 'action:router.navigation-end': true, | ||
152 | |||
153 | // Fired when the registration page is being initialized | ||
154 | 'action:signup.register.init': true, | ||
155 | |||
156 | // PeerTube >= 3.2 | ||
157 | // Fired when the admin plugin settings page is being initialized | ||
158 | 'action:admin-plugin-settings.init': true, | ||
159 | |||
160 | // Fired when the video upload page is being initialized | ||
161 | 'action:video-upload.init': true, | ||
162 | // Fired when the video import by URL page is being initialized | ||
163 | 'action:video-url-import.init': true, | ||
164 | // Fired when the video import by torrent/magnet URI page is being initialized | ||
165 | 'action:video-torrent-import.init': true, | ||
166 | // Fired when the "Go Live" page is being initialized | ||
167 | 'action:go-live.init': true, | ||
168 | |||
169 | // Fired when the user explicitly logged in/logged out | ||
170 | 'action:auth-user.logged-in': true, | ||
171 | 'action:auth-user.logged-out': true, | ||
172 | // Fired when the application loaded user information (using tokens from the local storage or after a successful login) | ||
173 | 'action:auth-user.information-loaded': true, | ||
174 | |||
175 | // Fired when the modal to download a video/caption is shown | ||
176 | 'action:modal.video-download.shown': true, | ||
177 | // Fired when the modal to share a video/playlist is shown | ||
178 | 'action:modal.share.shown': true, | ||
179 | |||
180 | // ####### Embed hooks ####### | ||
181 | // /!\ In embed scope, peertube helpers are not available | ||
182 | // ########################### | ||
183 | |||
184 | // Fired when the embed loaded the player | ||
185 | 'action:embed.player.loaded': true | ||
186 | } | ||
187 | |||
188 | export type ClientActionHookName = keyof typeof clientActionHookObject | ||
189 | |||
190 | export const clientHookObject = Object.assign({}, clientFilterHookObject, clientActionHookObject) | ||
191 | export type ClientHookName = keyof typeof clientHookObject | ||
192 | |||
193 | export interface ClientHook { | ||
194 | runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> | ||
195 | } | ||
diff --git a/shared/models/plugins/client/index.ts b/shared/models/plugins/client/index.ts deleted file mode 100644 index f3e3fcbcf..000000000 --- a/shared/models/plugins/client/index.ts +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | export * from './client-hook.model' | ||
2 | export * from './plugin-client-scope.type' | ||
3 | export * from './plugin-element-placeholder.type' | ||
4 | export * from './plugin-selector-id.type' | ||
5 | export * from './register-client-form-field.model' | ||
6 | export * from './register-client-hook.model' | ||
7 | export * from './register-client-route.model' | ||
8 | export * from './register-client-settings-script.model' | ||
diff --git a/shared/models/plugins/client/plugin-client-scope.type.ts b/shared/models/plugins/client/plugin-client-scope.type.ts deleted file mode 100644 index c09a453b8..000000000 --- a/shared/models/plugins/client/plugin-client-scope.type.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | export type PluginClientScope = | ||
2 | 'common' | | ||
3 | 'video-watch' | | ||
4 | 'search' | | ||
5 | 'signup' | | ||
6 | 'login' | | ||
7 | 'embed' | | ||
8 | 'video-edit' | | ||
9 | 'admin-plugin' | | ||
10 | 'my-library' | | ||
11 | 'video-channel' | ||
diff --git a/shared/models/plugins/client/plugin-element-placeholder.type.ts b/shared/models/plugins/client/plugin-element-placeholder.type.ts deleted file mode 100644 index 7b8a2605b..000000000 --- a/shared/models/plugins/client/plugin-element-placeholder.type.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export type PluginElementPlaceholder = | ||
2 | 'player-next' | | ||
3 | 'share-modal-playlist-settings' | | ||
4 | 'share-modal-video-settings' | ||
diff --git a/shared/models/plugins/client/plugin-selector-id.type.ts b/shared/models/plugins/client/plugin-selector-id.type.ts deleted file mode 100644 index 8d23314b5..000000000 --- a/shared/models/plugins/client/plugin-selector-id.type.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | export type PluginSelectorId = | ||
2 | 'login-form' | | ||
3 | 'menu-user-dropdown-language-item' | | ||
4 | 'about-instance-features' | | ||
5 | 'about-instance-statistics' | | ||
6 | 'about-instance-moderation' | | ||
7 | 'about-menu-instance' | | ||
8 | 'about-menu-peertube' | | ||
9 | 'about-menu-network' | | ||
10 | 'about-instance-other-information' | ||
diff --git a/shared/models/plugins/client/register-client-form-field.model.ts b/shared/models/plugins/client/register-client-form-field.model.ts deleted file mode 100644 index 153c4a6ea..000000000 --- a/shared/models/plugins/client/register-client-form-field.model.ts +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | export type RegisterClientFormFieldOptions = { | ||
2 | name?: string | ||
3 | label?: string | ||
4 | type: 'input' | 'input-checkbox' | 'input-password' | 'input-textarea' | 'markdown-text' | 'markdown-enhanced' | 'select' | 'html' | ||
5 | |||
6 | // For select type | ||
7 | options?: { value: string, label: string }[] | ||
8 | |||
9 | // For html type | ||
10 | html?: string | ||
11 | |||
12 | descriptionHTML?: string | ||
13 | |||
14 | // Default setting value | ||
15 | default?: string | boolean | ||
16 | |||
17 | // Not supported by plugin setting registration, use registerSettingsScript instead | ||
18 | hidden?: (options: any) => boolean | ||
19 | |||
20 | // Return undefined | null if there is no error or return a string with the detailed error | ||
21 | // Not supported by plugin setting registration | ||
22 | error?: (options: any) => Promise<{ error: boolean, text?: string }> | ||
23 | } | ||
24 | |||
25 | export interface RegisterClientVideoFieldOptions { | ||
26 | type: 'update' | 'upload' | 'import-url' | 'import-torrent' | 'go-live' | ||
27 | |||
28 | // Default to 'plugin-settings' | ||
29 | tab?: 'main' | 'plugin-settings' | ||
30 | } | ||
diff --git a/shared/models/plugins/client/register-client-hook.model.ts b/shared/models/plugins/client/register-client-hook.model.ts deleted file mode 100644 index 81047b21d..000000000 --- a/shared/models/plugins/client/register-client-hook.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | import { ClientHookName } from './client-hook.model' | ||
2 | |||
3 | export interface RegisterClientHookOptions { | ||
4 | target: ClientHookName | ||
5 | handler: Function | ||
6 | priority?: number | ||
7 | } | ||
diff --git a/shared/models/plugins/client/register-client-route.model.ts b/shared/models/plugins/client/register-client-route.model.ts deleted file mode 100644 index 271b67834..000000000 --- a/shared/models/plugins/client/register-client-route.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | export interface RegisterClientRouteOptions { | ||
2 | route: string | ||
3 | |||
4 | onMount (options: { | ||
5 | rootEl: HTMLElement | ||
6 | }): void | ||
7 | } | ||
diff --git a/shared/models/plugins/client/register-client-settings-script.model.ts b/shared/models/plugins/client/register-client-settings-script.model.ts deleted file mode 100644 index 117ca4739..000000000 --- a/shared/models/plugins/client/register-client-settings-script.model.ts +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | import { RegisterServerSettingOptions } from '../server' | ||
2 | |||
3 | export interface RegisterClientSettingsScriptOptions { | ||
4 | isSettingHidden (options: { | ||
5 | setting: RegisterServerSettingOptions | ||
6 | formValues: { [name: string]: any } | ||
7 | }): boolean | ||
8 | } | ||
diff --git a/shared/models/plugins/hook-type.enum.ts b/shared/models/plugins/hook-type.enum.ts deleted file mode 100644 index a96c943f1..000000000 --- a/shared/models/plugins/hook-type.enum.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export const enum HookType { | ||
2 | STATIC = 1, | ||
3 | ACTION = 2, | ||
4 | FILTER = 3 | ||
5 | } | ||
diff --git a/shared/models/plugins/index.ts b/shared/models/plugins/index.ts deleted file mode 100644 index cbbe4916e..000000000 --- a/shared/models/plugins/index.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export * from './client' | ||
2 | export * from './plugin-index' | ||
3 | export * from './server' | ||
4 | export * from './hook-type.enum' | ||
5 | export * from './plugin-package-json.model' | ||
6 | export * from './plugin.type' | ||
diff --git a/shared/models/plugins/plugin-index/index.ts b/shared/models/plugins/plugin-index/index.ts deleted file mode 100644 index 913846638..000000000 --- a/shared/models/plugins/plugin-index/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './peertube-plugin-index-list.model' | ||
2 | export * from './peertube-plugin-index.model' | ||
3 | export * from './peertube-plugin-latest-version.model' | ||
diff --git a/shared/models/plugins/plugin-index/peertube-plugin-index-list.model.ts b/shared/models/plugins/plugin-index/peertube-plugin-index-list.model.ts deleted file mode 100644 index ecb46482e..000000000 --- a/shared/models/plugins/plugin-index/peertube-plugin-index-list.model.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | import { PluginType } from '../plugin.type' | ||
2 | |||
3 | export interface PeertubePluginIndexList { | ||
4 | start: number | ||
5 | count: number | ||
6 | sort: string | ||
7 | pluginType?: PluginType | ||
8 | currentPeerTubeEngine?: string | ||
9 | search?: string | ||
10 | } | ||
diff --git a/shared/models/plugins/plugin-index/peertube-plugin-index.model.ts b/shared/models/plugins/plugin-index/peertube-plugin-index.model.ts deleted file mode 100644 index 36dfef943..000000000 --- a/shared/models/plugins/plugin-index/peertube-plugin-index.model.ts +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | export interface PeerTubePluginIndex { | ||
2 | npmName: string | ||
3 | description: string | ||
4 | homepage: string | ||
5 | createdAt: Date | ||
6 | updatedAt: Date | ||
7 | |||
8 | popularity: number | ||
9 | |||
10 | latestVersion: string | ||
11 | |||
12 | official: boolean | ||
13 | |||
14 | name?: string | ||
15 | installed?: boolean | ||
16 | } | ||
diff --git a/shared/models/plugins/plugin-index/peertube-plugin-latest-version.model.ts b/shared/models/plugins/plugin-index/peertube-plugin-latest-version.model.ts deleted file mode 100644 index 811a64429..000000000 --- a/shared/models/plugins/plugin-index/peertube-plugin-latest-version.model.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | export interface PeertubePluginLatestVersionRequest { | ||
2 | currentPeerTubeEngine?: string | ||
3 | |||
4 | npmNames: string[] | ||
5 | } | ||
6 | |||
7 | export type PeertubePluginLatestVersionResponse = { | ||
8 | npmName: string | ||
9 | latestVersion: string | null | ||
10 | }[] | ||
diff --git a/shared/models/plugins/plugin-package-json.model.ts b/shared/models/plugins/plugin-package-json.model.ts deleted file mode 100644 index 7ce968ff2..000000000 --- a/shared/models/plugins/plugin-package-json.model.ts +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | import { PluginClientScope } from './client/plugin-client-scope.type' | ||
2 | |||
3 | export type PluginTranslationPathsJSON = { | ||
4 | [ locale: string ]: string | ||
5 | } | ||
6 | |||
7 | export type ClientScriptJSON = { | ||
8 | script: string | ||
9 | scopes: PluginClientScope[] | ||
10 | } | ||
11 | |||
12 | export type PluginPackageJSON = { | ||
13 | name: string | ||
14 | version: string | ||
15 | description: string | ||
16 | engine: { peertube: string } | ||
17 | |||
18 | homepage: string | ||
19 | author: string | ||
20 | bugs: string | ||
21 | library: string | ||
22 | |||
23 | staticDirs: { [ name: string ]: string } | ||
24 | css: string[] | ||
25 | |||
26 | clientScripts: ClientScriptJSON[] | ||
27 | |||
28 | translations: PluginTranslationPathsJSON | ||
29 | } | ||
diff --git a/shared/models/plugins/plugin.type.ts b/shared/models/plugins/plugin.type.ts deleted file mode 100644 index 016219ceb..000000000 --- a/shared/models/plugins/plugin.type.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export const enum PluginType { | ||
2 | PLUGIN = 1, | ||
3 | THEME = 2 | ||
4 | } | ||
diff --git a/shared/models/plugins/server/api/index.ts b/shared/models/plugins/server/api/index.ts deleted file mode 100644 index eb59a03f0..000000000 --- a/shared/models/plugins/server/api/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './install-plugin.model' | ||
2 | export * from './manage-plugin.model' | ||
3 | export * from './peertube-plugin.model' | ||
diff --git a/shared/models/plugins/server/api/install-plugin.model.ts b/shared/models/plugins/server/api/install-plugin.model.ts deleted file mode 100644 index a1d009a00..000000000 --- a/shared/models/plugins/server/api/install-plugin.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface InstallOrUpdatePlugin { | ||
2 | npmName?: string | ||
3 | pluginVersion?: string | ||
4 | path?: string | ||
5 | } | ||
diff --git a/shared/models/plugins/server/api/manage-plugin.model.ts b/shared/models/plugins/server/api/manage-plugin.model.ts deleted file mode 100644 index 612b3056c..000000000 --- a/shared/models/plugins/server/api/manage-plugin.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface ManagePlugin { | ||
2 | npmName: string | ||
3 | } | ||
diff --git a/shared/models/plugins/server/api/peertube-plugin.model.ts b/shared/models/plugins/server/api/peertube-plugin.model.ts deleted file mode 100644 index 54c383f57..000000000 --- a/shared/models/plugins/server/api/peertube-plugin.model.ts +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | import { PluginType } from '../../plugin.type' | ||
2 | |||
3 | export interface PeerTubePlugin { | ||
4 | name: string | ||
5 | type: PluginType | ||
6 | latestVersion: string | ||
7 | version: string | ||
8 | enabled: boolean | ||
9 | uninstalled: boolean | ||
10 | peertubeEngine: string | ||
11 | description: string | ||
12 | homepage: string | ||
13 | settings: { [ name: string ]: string } | ||
14 | createdAt: Date | ||
15 | updatedAt: Date | ||
16 | } | ||
diff --git a/shared/models/plugins/server/index.ts b/shared/models/plugins/server/index.ts deleted file mode 100644 index d3ff49d3b..000000000 --- a/shared/models/plugins/server/index.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export * from './api' | ||
2 | export * from './managers' | ||
3 | export * from './settings' | ||
4 | export * from './plugin-translation.model' | ||
5 | export * from './register-server-hook.model' | ||
6 | export * from './server-hook.model' | ||
diff --git a/shared/models/plugins/server/managers/index.ts b/shared/models/plugins/server/managers/index.ts deleted file mode 100644 index 49365a854..000000000 --- a/shared/models/plugins/server/managers/index.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | |||
2 | export * from './plugin-playlist-privacy-manager.model' | ||
3 | export * from './plugin-settings-manager.model' | ||
4 | export * from './plugin-storage-manager.model' | ||
5 | export * from './plugin-transcoding-manager.model' | ||
6 | export * from './plugin-video-category-manager.model' | ||
7 | export * from './plugin-video-language-manager.model' | ||
8 | export * from './plugin-video-licence-manager.model' | ||
9 | export * from './plugin-video-privacy-manager.model' | ||
diff --git a/shared/models/plugins/server/managers/plugin-playlist-privacy-manager.model.ts b/shared/models/plugins/server/managers/plugin-playlist-privacy-manager.model.ts deleted file mode 100644 index 35247c1e3..000000000 --- a/shared/models/plugins/server/managers/plugin-playlist-privacy-manager.model.ts +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | import { VideoPlaylistPrivacy } from '../../../videos/playlist/video-playlist-privacy.model' | ||
2 | import { ConstantManager } from '../plugin-constant-manager.model' | ||
3 | |||
4 | export interface PluginPlaylistPrivacyManager extends ConstantManager<VideoPlaylistPrivacy> { | ||
5 | /** | ||
6 | * PUBLIC = 1, | ||
7 | * UNLISTED = 2, | ||
8 | * PRIVATE = 3 | ||
9 | * @deprecated use `deleteConstant` instead | ||
10 | */ | ||
11 | deletePlaylistPrivacy: (privacyKey: VideoPlaylistPrivacy) => boolean | ||
12 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-settings-manager.model.ts b/shared/models/plugins/server/managers/plugin-settings-manager.model.ts deleted file mode 100644 index b628718dd..000000000 --- a/shared/models/plugins/server/managers/plugin-settings-manager.model.ts +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | export type SettingValue = string | boolean | ||
2 | |||
3 | export interface SettingEntries { | ||
4 | [settingName: string]: SettingValue | ||
5 | } | ||
6 | |||
7 | export type SettingsChangeCallback = (settings: SettingEntries) => Promise<any> | ||
8 | |||
9 | export interface PluginSettingsManager { | ||
10 | getSetting: (name: string) => Promise<SettingValue> | ||
11 | |||
12 | getSettings: (names: string[]) => Promise<SettingEntries> | ||
13 | |||
14 | setSetting: (name: string, value: SettingValue) => Promise<any> | ||
15 | |||
16 | onSettingsChange: (cb: SettingsChangeCallback) => void | ||
17 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-storage-manager.model.ts b/shared/models/plugins/server/managers/plugin-storage-manager.model.ts deleted file mode 100644 index 51567044a..000000000 --- a/shared/models/plugins/server/managers/plugin-storage-manager.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface PluginStorageManager { | ||
2 | getData: (key: string) => Promise<string> | ||
3 | |||
4 | storeData: (key: string, data: any) => Promise<any> | ||
5 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-transcoding-manager.model.ts b/shared/models/plugins/server/managers/plugin-transcoding-manager.model.ts deleted file mode 100644 index b6fb46ba0..000000000 --- a/shared/models/plugins/server/managers/plugin-transcoding-manager.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { EncoderOptionsBuilder } from '../../../videos/transcoding' | ||
2 | |||
3 | export interface PluginTranscodingManager { | ||
4 | addLiveProfile (encoder: string, profile: string, builder: EncoderOptionsBuilder): boolean | ||
5 | |||
6 | addVODProfile (encoder: string, profile: string, builder: EncoderOptionsBuilder): boolean | ||
7 | |||
8 | addLiveEncoderPriority (streamType: 'audio' | 'video', encoder: string, priority: number): void | ||
9 | |||
10 | addVODEncoderPriority (streamType: 'audio' | 'video', encoder: string, priority: number): void | ||
11 | |||
12 | removeAllProfilesAndEncoderPriorities(): void | ||
13 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-video-category-manager.model.ts b/shared/models/plugins/server/managers/plugin-video-category-manager.model.ts deleted file mode 100644 index cf3d828fe..000000000 --- a/shared/models/plugins/server/managers/plugin-video-category-manager.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { ConstantManager } from '../plugin-constant-manager.model' | ||
2 | |||
3 | export interface PluginVideoCategoryManager extends ConstantManager<number> { | ||
4 | /** | ||
5 | * @deprecated use `addConstant` instead | ||
6 | */ | ||
7 | addCategory: (categoryKey: number, categoryLabel: string) => boolean | ||
8 | |||
9 | /** | ||
10 | * @deprecated use `deleteConstant` instead | ||
11 | */ | ||
12 | deleteCategory: (categoryKey: number) => boolean | ||
13 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-video-language-manager.model.ts b/shared/models/plugins/server/managers/plugin-video-language-manager.model.ts deleted file mode 100644 index 69fc8e503..000000000 --- a/shared/models/plugins/server/managers/plugin-video-language-manager.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { ConstantManager } from '../plugin-constant-manager.model' | ||
2 | |||
3 | export interface PluginVideoLanguageManager extends ConstantManager<string> { | ||
4 | /** | ||
5 | * @deprecated use `addConstant` instead | ||
6 | */ | ||
7 | addLanguage: (languageKey: string, languageLabel: string) => boolean | ||
8 | |||
9 | /** | ||
10 | * @deprecated use `deleteConstant` instead | ||
11 | */ | ||
12 | deleteLanguage: (languageKey: string) => boolean | ||
13 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-video-licence-manager.model.ts b/shared/models/plugins/server/managers/plugin-video-licence-manager.model.ts deleted file mode 100644 index 21b422270..000000000 --- a/shared/models/plugins/server/managers/plugin-video-licence-manager.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { ConstantManager } from '../plugin-constant-manager.model' | ||
2 | |||
3 | export interface PluginVideoLicenceManager extends ConstantManager<number> { | ||
4 | /** | ||
5 | * @deprecated use `addConstant` instead | ||
6 | */ | ||
7 | addLicence: (licenceKey: number, licenceLabel: string) => boolean | ||
8 | |||
9 | /** | ||
10 | * @deprecated use `deleteConstant` instead | ||
11 | */ | ||
12 | deleteLicence: (licenceKey: number) => boolean | ||
13 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-video-privacy-manager.model.ts b/shared/models/plugins/server/managers/plugin-video-privacy-manager.model.ts deleted file mode 100644 index a237037db..000000000 --- a/shared/models/plugins/server/managers/plugin-video-privacy-manager.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { VideoPrivacy } from '../../../videos/video-privacy.enum' | ||
2 | import { ConstantManager } from '../plugin-constant-manager.model' | ||
3 | |||
4 | export interface PluginVideoPrivacyManager extends ConstantManager<VideoPrivacy> { | ||
5 | /** | ||
6 | * PUBLIC = 1, | ||
7 | * UNLISTED = 2, | ||
8 | * PRIVATE = 3 | ||
9 | * INTERNAL = 4 | ||
10 | * @deprecated use `deleteConstant` instead | ||
11 | */ | ||
12 | deletePrivacy: (privacyKey: VideoPrivacy) => boolean | ||
13 | } | ||
diff --git a/shared/models/plugins/server/plugin-constant-manager.model.ts b/shared/models/plugins/server/plugin-constant-manager.model.ts deleted file mode 100644 index 4de3ce38f..000000000 --- a/shared/models/plugins/server/plugin-constant-manager.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | export interface ConstantManager <K extends string | number> { | ||
2 | addConstant: (key: K, label: string) => boolean | ||
3 | deleteConstant: (key: K) => boolean | ||
4 | getConstantValue: (key: K) => string | ||
5 | getConstants: () => Record<K, string> | ||
6 | resetConstants: () => void | ||
7 | } | ||
diff --git a/shared/models/plugins/server/plugin-translation.model.ts b/shared/models/plugins/server/plugin-translation.model.ts deleted file mode 100644 index a2dd8e560..000000000 --- a/shared/models/plugins/server/plugin-translation.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export type PluginTranslation = { | ||
2 | [ npmName: string ]: { | ||
3 | [ key: string ]: string | ||
4 | } | ||
5 | } | ||
diff --git a/shared/models/plugins/server/register-server-hook.model.ts b/shared/models/plugins/server/register-server-hook.model.ts deleted file mode 100644 index 746fdc329..000000000 --- a/shared/models/plugins/server/register-server-hook.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | import { ServerHookName } from './server-hook.model' | ||
2 | |||
3 | export interface RegisterServerHookOptions { | ||
4 | target: ServerHookName | ||
5 | handler: Function | ||
6 | priority?: number | ||
7 | } | ||
diff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.ts deleted file mode 100644 index cf387ffd7..000000000 --- a/shared/models/plugins/server/server-hook.model.ts +++ /dev/null | |||
@@ -1,221 +0,0 @@ | |||
1 | // {hookType}:{root}.{location}.{subLocation?}.{actionType}.{target} | ||
2 | |||
3 | export const serverFilterHookObject = { | ||
4 | // Filter params/result used to list videos for the REST API | ||
5 | // (used by the trending page, recently-added page, local page etc) | ||
6 | 'filter:api.videos.list.params': true, | ||
7 | 'filter:api.videos.list.result': true, | ||
8 | |||
9 | // Filter params/result used to list a video playlists videos | ||
10 | // for the REST API | ||
11 | 'filter:api.video-playlist.videos.list.params': true, | ||
12 | 'filter:api.video-playlist.videos.list.result': true, | ||
13 | |||
14 | // Filter params/result used to list account videos for the REST API | ||
15 | 'filter:api.accounts.videos.list.params': true, | ||
16 | 'filter:api.accounts.videos.list.result': true, | ||
17 | |||
18 | // Filter params/result used to list channel videos for the REST API | ||
19 | 'filter:api.video-channels.videos.list.params': true, | ||
20 | 'filter:api.video-channels.videos.list.result': true, | ||
21 | |||
22 | // Filter params/result used to list my user videos for the REST API | ||
23 | 'filter:api.user.me.videos.list.params': true, | ||
24 | 'filter:api.user.me.videos.list.result': true, | ||
25 | |||
26 | // Filter params/result used to list overview videos for the REST API | ||
27 | 'filter:api.overviews.videos.list.params': true, | ||
28 | 'filter:api.overviews.videos.list.result': true, | ||
29 | |||
30 | // Filter params/result used to list subscription videos for the REST API | ||
31 | 'filter:api.user.me.subscription-videos.list.params': true, | ||
32 | 'filter:api.user.me.subscription-videos.list.result': true, | ||
33 | |||
34 | // Filter params/results to search videos/channels in the DB or on the remote index | ||
35 | 'filter:api.search.videos.local.list.params': true, | ||
36 | 'filter:api.search.videos.local.list.result': true, | ||
37 | 'filter:api.search.videos.index.list.params': true, | ||
38 | 'filter:api.search.videos.index.list.result': true, | ||
39 | 'filter:api.search.video-channels.local.list.params': true, | ||
40 | 'filter:api.search.video-channels.local.list.result': true, | ||
41 | 'filter:api.search.video-channels.index.list.params': true, | ||
42 | 'filter:api.search.video-channels.index.list.result': true, | ||
43 | 'filter:api.search.video-playlists.local.list.params': true, | ||
44 | 'filter:api.search.video-playlists.local.list.result': true, | ||
45 | 'filter:api.search.video-playlists.index.list.params': true, | ||
46 | 'filter:api.search.video-playlists.index.list.result': true, | ||
47 | |||
48 | // Filter the result of the get function | ||
49 | // Used to get detailed video information (video watch page for example) | ||
50 | 'filter:api.video.get.result': true, | ||
51 | |||
52 | // Filter params/results when listing video channels | ||
53 | 'filter:api.video-channels.list.params': true, | ||
54 | 'filter:api.video-channels.list.result': true, | ||
55 | |||
56 | // Filter the result when getting a video channel | ||
57 | 'filter:api.video-channel.get.result': true, | ||
58 | |||
59 | // Filter the result of the accept upload/live, import via torrent/url functions | ||
60 | // If this function returns false then the upload is aborted with an error | ||
61 | 'filter:api.video.upload.accept.result': true, | ||
62 | 'filter:api.live-video.create.accept.result': true, | ||
63 | 'filter:api.video.pre-import-url.accept.result': true, | ||
64 | 'filter:api.video.pre-import-torrent.accept.result': true, | ||
65 | 'filter:api.video.post-import-url.accept.result': true, | ||
66 | 'filter:api.video.post-import-torrent.accept.result': true, | ||
67 | 'filter:api.video.update-file.accept.result': true, | ||
68 | // Filter the result of the accept comment (thread or reply) functions | ||
69 | // If the functions return false then the user cannot post its comment | ||
70 | 'filter:api.video-thread.create.accept.result': true, | ||
71 | 'filter:api.video-comment-reply.create.accept.result': true, | ||
72 | |||
73 | // Filter attributes when creating video object | ||
74 | 'filter:api.video.upload.video-attribute.result': true, | ||
75 | 'filter:api.video.import-url.video-attribute.result': true, | ||
76 | 'filter:api.video.import-torrent.video-attribute.result': true, | ||
77 | 'filter:api.video.live.video-attribute.result': true, | ||
78 | |||
79 | // Filter params/result used to list threads of a specific video | ||
80 | // (used by the video watch page) | ||
81 | 'filter:api.video-threads.list.params': true, | ||
82 | 'filter:api.video-threads.list.result': true, | ||
83 | |||
84 | // Filter params/result used to list replies of a specific thread | ||
85 | // (used by the video watch page when we click on the "View replies" button) | ||
86 | 'filter:api.video-thread-comments.list.params': true, | ||
87 | 'filter:api.video-thread-comments.list.result': true, | ||
88 | |||
89 | // Filter get stats result | ||
90 | 'filter:api.server.stats.get.result': true, | ||
91 | |||
92 | // Filter result used to check if we need to auto blacklist a video | ||
93 | // (fired when a local or remote video is created or updated) | ||
94 | 'filter:video.auto-blacklist.result': true, | ||
95 | |||
96 | // Filter result used to check if a user can register on the instance | ||
97 | 'filter:api.user.signup.allowed.result': true, | ||
98 | |||
99 | // Filter result used to check if a user can send a registration request on the instance | ||
100 | // PeerTube >= 5.1 | ||
101 | 'filter:api.user.request-signup.allowed.result': true, | ||
102 | |||
103 | // Filter result used to check if video/torrent download is allowed | ||
104 | 'filter:api.download.video.allowed.result': true, | ||
105 | 'filter:api.download.torrent.allowed.result': true, | ||
106 | |||
107 | // Filter result to check if the embed is allowed for a particular request | ||
108 | 'filter:html.embed.video.allowed.result': true, | ||
109 | 'filter:html.embed.video-playlist.allowed.result': true, | ||
110 | |||
111 | // Peertube >= 5.2 | ||
112 | 'filter:html.client.json-ld.result': true, | ||
113 | |||
114 | 'filter:job-queue.process.params': true, | ||
115 | 'filter:job-queue.process.result': true, | ||
116 | |||
117 | 'filter:transcoding.manual.resolutions-to-transcode.result': true, | ||
118 | 'filter:transcoding.auto.resolutions-to-transcode.result': true, | ||
119 | |||
120 | 'filter:activity-pub.remote-video-comment.create.accept.result': true, | ||
121 | |||
122 | 'filter:activity-pub.activity.context.build.result': true, | ||
123 | |||
124 | // Filter the result of video JSON LD builder | ||
125 | // You may also need to use filter:activity-pub.activity.context.build.result to also update JSON LD context | ||
126 | 'filter:activity-pub.video.json-ld.build.result': true, | ||
127 | |||
128 | // Filter result to allow custom XMLNS definitions in podcast RSS feeds | ||
129 | // Peertube >= 5.2 | ||
130 | 'filter:feed.podcast.rss.create-custom-xmlns.result': true, | ||
131 | |||
132 | // Filter result to allow custom tags in podcast RSS feeds | ||
133 | // Peertube >= 5.2 | ||
134 | 'filter:feed.podcast.channel.create-custom-tags.result': true, | ||
135 | // Peertube >= 5.2 | ||
136 | 'filter:feed.podcast.video.create-custom-tags.result': true | ||
137 | } | ||
138 | |||
139 | export type ServerFilterHookName = keyof typeof serverFilterHookObject | ||
140 | |||
141 | export const serverActionHookObject = { | ||
142 | // Fired when the application has been loaded and is listening HTTP requests | ||
143 | 'action:application.listening': true, | ||
144 | |||
145 | // Fired when a new notification is created | ||
146 | 'action:notifier.notification.created': true, | ||
147 | |||
148 | // API actions hooks give access to the original express `req` and `res` parameters | ||
149 | |||
150 | // Fired when a local video is updated | ||
151 | 'action:api.video.updated': true, | ||
152 | // Fired when a local video is deleted | ||
153 | 'action:api.video.deleted': true, | ||
154 | // Fired when a local video is uploaded | ||
155 | 'action:api.video.uploaded': true, | ||
156 | // Fired when a local video is viewed | ||
157 | 'action:api.video.viewed': true, | ||
158 | |||
159 | // Fired when a local video file has been replaced by a new one | ||
160 | 'action:api.video.file-updated': true, | ||
161 | |||
162 | // Fired when a video channel is created | ||
163 | 'action:api.video-channel.created': true, | ||
164 | // Fired when a video channel is updated | ||
165 | 'action:api.video-channel.updated': true, | ||
166 | // Fired when a video channel is deleted | ||
167 | 'action:api.video-channel.deleted': true, | ||
168 | |||
169 | // Fired when a live video is created | ||
170 | 'action:api.live-video.created': true, | ||
171 | // Fired when a live video starts or ends | ||
172 | // Peertube >= 5.2 | ||
173 | 'action:live.video.state.updated': true, | ||
174 | |||
175 | // Fired when a thread is created | ||
176 | 'action:api.video-thread.created': true, | ||
177 | // Fired when a reply to a thread is created | ||
178 | 'action:api.video-comment-reply.created': true, | ||
179 | // Fired when a comment (thread or reply) is deleted | ||
180 | 'action:api.video-comment.deleted': true, | ||
181 | |||
182 | // Fired when a caption is created | ||
183 | 'action:api.video-caption.created': true, | ||
184 | // Fired when a caption is deleted | ||
185 | 'action:api.video-caption.deleted': true, | ||
186 | |||
187 | // Fired when a user is blocked (banned) | ||
188 | 'action:api.user.blocked': true, | ||
189 | // Fired when a user is unblocked (unbanned) | ||
190 | 'action:api.user.unblocked': true, | ||
191 | // Fired when a user registered on the instance | ||
192 | 'action:api.user.registered': true, | ||
193 | // Fired when a user requested registration on the instance | ||
194 | // PeerTube >= 5.1 | ||
195 | 'action:api.user.requested-registration': true, | ||
196 | // Fired when an admin/moderator created a user | ||
197 | 'action:api.user.created': true, | ||
198 | // Fired when a user is removed by an admin/moderator | ||
199 | 'action:api.user.deleted': true, | ||
200 | // Fired when a user is updated by an admin/moderator | ||
201 | 'action:api.user.updated': true, | ||
202 | |||
203 | // Fired when a user got a new oauth2 token | ||
204 | 'action:api.user.oauth2-got-token': true, | ||
205 | |||
206 | // Fired when a video is added to a playlist | ||
207 | 'action:api.video-playlist-element.created': true, | ||
208 | |||
209 | // Fired when a remote video has been created/updated | ||
210 | 'action:activity-pub.remote-video.created': true, | ||
211 | 'action:activity-pub.remote-video.updated': true | ||
212 | } | ||
213 | |||
214 | export type ServerActionHookName = keyof typeof serverActionHookObject | ||
215 | |||
216 | export const serverHookObject = Object.assign({}, serverFilterHookObject, serverActionHookObject) | ||
217 | export type ServerHookName = keyof typeof serverHookObject | ||
218 | |||
219 | export interface ServerHook { | ||
220 | runHook <T> (hookName: ServerHookName, result?: T, params?: any): Promise<T> | ||
221 | } | ||
diff --git a/shared/models/plugins/server/settings/index.ts b/shared/models/plugins/server/settings/index.ts deleted file mode 100644 index b456de019..000000000 --- a/shared/models/plugins/server/settings/index.ts +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | export * from './public-server.setting' | ||
2 | export * from './register-server-setting.model' | ||
diff --git a/shared/models/plugins/server/settings/public-server.setting.ts b/shared/models/plugins/server/settings/public-server.setting.ts deleted file mode 100644 index d38e5424a..000000000 --- a/shared/models/plugins/server/settings/public-server.setting.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | import { SettingEntries } from '../managers/plugin-settings-manager.model' | ||
2 | |||
3 | export interface PublicServerSetting { | ||
4 | publicSettings: SettingEntries | ||
5 | } | ||
diff --git a/shared/models/plugins/server/settings/register-server-setting.model.ts b/shared/models/plugins/server/settings/register-server-setting.model.ts deleted file mode 100644 index d9a798cac..000000000 --- a/shared/models/plugins/server/settings/register-server-setting.model.ts +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | import { RegisterClientFormFieldOptions } from '../../client' | ||
2 | |||
3 | export type RegisterServerSettingOptions = RegisterClientFormFieldOptions & { | ||
4 | // If the setting is not private, anyone can view its value (client code included) | ||
5 | // If the setting is private, only server-side hooks can access it | ||
6 | // Mainly used by the PeerTube client to get admin config | ||
7 | private: boolean | ||
8 | } | ||
9 | |||
10 | export interface RegisteredServerSettings { | ||
11 | registeredSettings: RegisterServerSettingOptions[] | ||
12 | } | ||
diff --git a/shared/models/redundancy/index.ts b/shared/models/redundancy/index.ts deleted file mode 100644 index 641a5d625..000000000 --- a/shared/models/redundancy/index.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export * from './video-redundancies-filters.model' | ||
2 | export * from './video-redundancy-config-filter.type' | ||
3 | export * from './video-redundancy.model' | ||
4 | export * from './videos-redundancy-strategy.model' | ||
diff --git a/shared/models/redundancy/video-redundancies-filters.model.ts b/shared/models/redundancy/video-redundancies-filters.model.ts deleted file mode 100644 index 05ba7dfd3..000000000 --- a/shared/models/redundancy/video-redundancies-filters.model.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type VideoRedundanciesTarget = 'my-videos' | 'remote-videos' | ||
diff --git a/shared/models/redundancy/video-redundancy-config-filter.type.ts b/shared/models/redundancy/video-redundancy-config-filter.type.ts deleted file mode 100644 index bb1ae701c..000000000 --- a/shared/models/redundancy/video-redundancy-config-filter.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type VideoRedundancyConfigFilter = 'nobody' | 'anybody' | 'followings' | ||
diff --git a/shared/models/redundancy/video-redundancy.model.ts b/shared/models/redundancy/video-redundancy.model.ts deleted file mode 100644 index fa6e05832..000000000 --- a/shared/models/redundancy/video-redundancy.model.ts +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | export interface VideoRedundancy { | ||
2 | id: number | ||
3 | name: string | ||
4 | url: string | ||
5 | uuid: string | ||
6 | |||
7 | redundancies: { | ||
8 | files: FileRedundancyInformation[] | ||
9 | |||
10 | streamingPlaylists: StreamingPlaylistRedundancyInformation[] | ||
11 | } | ||
12 | } | ||
13 | |||
14 | interface RedundancyInformation { | ||
15 | id: number | ||
16 | fileUrl: string | ||
17 | strategy: string | ||
18 | |||
19 | createdAt: Date | string | ||
20 | updatedAt: Date | string | ||
21 | |||
22 | expiresOn: Date | string | ||
23 | |||
24 | size: number | ||
25 | } | ||
26 | |||
27 | // eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
28 | export interface FileRedundancyInformation extends RedundancyInformation { | ||
29 | |||
30 | } | ||
31 | |||
32 | // eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
33 | export interface StreamingPlaylistRedundancyInformation extends RedundancyInformation { | ||
34 | |||
35 | } | ||
diff --git a/shared/models/redundancy/videos-redundancy-strategy.model.ts b/shared/models/redundancy/videos-redundancy-strategy.model.ts deleted file mode 100644 index 15409abf0..000000000 --- a/shared/models/redundancy/videos-redundancy-strategy.model.ts +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | export type VideoRedundancyStrategy = 'most-views' | 'trending' | 'recently-added' | ||
2 | export type VideoRedundancyStrategyWithManual = VideoRedundancyStrategy | 'manual' | ||
3 | |||
4 | export type MostViewsRedundancyStrategy = { | ||
5 | strategy: 'most-views' | ||
6 | size: number | ||
7 | minLifetime: number | ||
8 | } | ||
9 | |||
10 | export type TrendingRedundancyStrategy = { | ||
11 | strategy: 'trending' | ||
12 | size: number | ||
13 | minLifetime: number | ||
14 | } | ||
15 | |||
16 | export type RecentlyAddedStrategy = { | ||
17 | strategy: 'recently-added' | ||
18 | size: number | ||
19 | minViews: number | ||
20 | minLifetime: number | ||
21 | } | ||
22 | |||
23 | export type VideosRedundancyStrategy = MostViewsRedundancyStrategy | TrendingRedundancyStrategy | RecentlyAddedStrategy | ||
diff --git a/shared/models/runners/abort-runner-job-body.model.ts b/shared/models/runners/abort-runner-job-body.model.ts deleted file mode 100644 index 0b9c46c91..000000000 --- a/shared/models/runners/abort-runner-job-body.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export interface AbortRunnerJobBody { | ||
2 | runnerToken: string | ||
3 | jobToken: string | ||
4 | |||
5 | reason: string | ||
6 | } | ||
diff --git a/shared/models/runners/accept-runner-job-body.model.ts b/shared/models/runners/accept-runner-job-body.model.ts deleted file mode 100644 index cb266c4e6..000000000 --- a/shared/models/runners/accept-runner-job-body.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface AcceptRunnerJobBody { | ||
2 | runnerToken: string | ||
3 | } | ||
diff --git a/shared/models/runners/accept-runner-job-result.model.ts b/shared/models/runners/accept-runner-job-result.model.ts deleted file mode 100644 index f2094b945..000000000 --- a/shared/models/runners/accept-runner-job-result.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | import { RunnerJobPayload } from './runner-job-payload.model' | ||
2 | import { RunnerJob } from './runner-job.model' | ||
3 | |||
4 | export interface AcceptRunnerJobResult <T extends RunnerJobPayload = RunnerJobPayload> { | ||
5 | job: RunnerJob<T> & { jobToken: string } | ||
6 | } | ||
diff --git a/shared/models/runners/error-runner-job-body.model.ts b/shared/models/runners/error-runner-job-body.model.ts deleted file mode 100644 index ac8568409..000000000 --- a/shared/models/runners/error-runner-job-body.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export interface ErrorRunnerJobBody { | ||
2 | runnerToken: string | ||
3 | jobToken: string | ||
4 | |||
5 | message: string | ||
6 | } | ||
diff --git a/shared/models/runners/index.ts b/shared/models/runners/index.ts deleted file mode 100644 index a52b82d2e..000000000 --- a/shared/models/runners/index.ts +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | export * from './abort-runner-job-body.model' | ||
2 | export * from './accept-runner-job-body.model' | ||
3 | export * from './accept-runner-job-result.model' | ||
4 | export * from './error-runner-job-body.model' | ||
5 | export * from './list-runner-jobs-query.model' | ||
6 | export * from './list-runner-registration-tokens.model' | ||
7 | export * from './list-runners-query.model' | ||
8 | export * from './register-runner-body.model' | ||
9 | export * from './register-runner-result.model' | ||
10 | export * from './request-runner-job-body.model' | ||
11 | export * from './request-runner-job-result.model' | ||
12 | export * from './runner-job-payload.model' | ||
13 | export * from './runner-job-private-payload.model' | ||
14 | export * from './runner-job-state.model' | ||
15 | export * from './runner-job-success-body.model' | ||
16 | export * from './runner-job-type.type' | ||
17 | export * from './runner-job-update-body.model' | ||
18 | export * from './runner-job.model' | ||
19 | export * from './runner-registration-token' | ||
20 | export * from './runner.model' | ||
21 | export * from './unregister-runner-body.model' | ||
diff --git a/shared/models/runners/list-runner-jobs-query.model.ts b/shared/models/runners/list-runner-jobs-query.model.ts deleted file mode 100644 index ef19b31fa..000000000 --- a/shared/models/runners/list-runner-jobs-query.model.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | import { RunnerJobState } from './runner-job-state.model' | ||
2 | |||
3 | export interface ListRunnerJobsQuery { | ||
4 | start?: number | ||
5 | count?: number | ||
6 | sort?: string | ||
7 | search?: string | ||
8 | stateOneOf?: RunnerJobState[] | ||
9 | } | ||
diff --git a/shared/models/runners/list-runner-registration-tokens.model.ts b/shared/models/runners/list-runner-registration-tokens.model.ts deleted file mode 100644 index 872e059cf..000000000 --- a/shared/models/runners/list-runner-registration-tokens.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface ListRunnerRegistrationTokensQuery { | ||
2 | start?: number | ||
3 | count?: number | ||
4 | sort?: string | ||
5 | } | ||
diff --git a/shared/models/runners/list-runners-query.model.ts b/shared/models/runners/list-runners-query.model.ts deleted file mode 100644 index d4362e4c5..000000000 --- a/shared/models/runners/list-runners-query.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface ListRunnersQuery { | ||
2 | start?: number | ||
3 | count?: number | ||
4 | sort?: string | ||
5 | } | ||
diff --git a/shared/models/runners/register-runner-body.model.ts b/shared/models/runners/register-runner-body.model.ts deleted file mode 100644 index 969bb35e1..000000000 --- a/shared/models/runners/register-runner-body.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export interface RegisterRunnerBody { | ||
2 | registrationToken: string | ||
3 | |||
4 | name: string | ||
5 | description?: string | ||
6 | } | ||
diff --git a/shared/models/runners/register-runner-result.model.ts b/shared/models/runners/register-runner-result.model.ts deleted file mode 100644 index e31776c6a..000000000 --- a/shared/models/runners/register-runner-result.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface RegisterRunnerResult { | ||
2 | id: number | ||
3 | runnerToken: string | ||
4 | } | ||
diff --git a/shared/models/runners/request-runner-job-body.model.ts b/shared/models/runners/request-runner-job-body.model.ts deleted file mode 100644 index 0970d9007..000000000 --- a/shared/models/runners/request-runner-job-body.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface RequestRunnerJobBody { | ||
2 | runnerToken: string | ||
3 | } | ||
diff --git a/shared/models/runners/request-runner-job-result.model.ts b/shared/models/runners/request-runner-job-result.model.ts deleted file mode 100644 index 98601c42c..000000000 --- a/shared/models/runners/request-runner-job-result.model.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | import { RunnerJobPayload } from './runner-job-payload.model' | ||
2 | import { RunnerJobType } from './runner-job-type.type' | ||
3 | |||
4 | export interface RequestRunnerJobResult <P extends RunnerJobPayload = RunnerJobPayload> { | ||
5 | availableJobs: { | ||
6 | uuid: string | ||
7 | type: RunnerJobType | ||
8 | payload: P | ||
9 | }[] | ||
10 | } | ||
diff --git a/shared/models/runners/runner-job-payload.model.ts b/shared/models/runners/runner-job-payload.model.ts deleted file mode 100644 index 3dda6c51f..000000000 --- a/shared/models/runners/runner-job-payload.model.ts +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | import { VideoStudioTaskPayload } from '../server' | ||
2 | |||
3 | export type RunnerJobVODPayload = | ||
4 | RunnerJobVODWebVideoTranscodingPayload | | ||
5 | RunnerJobVODHLSTranscodingPayload | | ||
6 | RunnerJobVODAudioMergeTranscodingPayload | ||
7 | |||
8 | export type RunnerJobPayload = | ||
9 | RunnerJobVODPayload | | ||
10 | RunnerJobLiveRTMPHLSTranscodingPayload | | ||
11 | RunnerJobStudioTranscodingPayload | ||
12 | |||
13 | // --------------------------------------------------------------------------- | ||
14 | |||
15 | export interface RunnerJobVODWebVideoTranscodingPayload { | ||
16 | input: { | ||
17 | videoFileUrl: string | ||
18 | } | ||
19 | |||
20 | output: { | ||
21 | resolution: number | ||
22 | fps: number | ||
23 | } | ||
24 | } | ||
25 | |||
26 | export interface RunnerJobVODHLSTranscodingPayload { | ||
27 | input: { | ||
28 | videoFileUrl: string | ||
29 | } | ||
30 | |||
31 | output: { | ||
32 | resolution: number | ||
33 | fps: number | ||
34 | } | ||
35 | } | ||
36 | |||
37 | export interface RunnerJobVODAudioMergeTranscodingPayload { | ||
38 | input: { | ||
39 | audioFileUrl: string | ||
40 | previewFileUrl: string | ||
41 | } | ||
42 | |||
43 | output: { | ||
44 | resolution: number | ||
45 | fps: number | ||
46 | } | ||
47 | } | ||
48 | |||
49 | export interface RunnerJobStudioTranscodingPayload { | ||
50 | input: { | ||
51 | videoFileUrl: string | ||
52 | } | ||
53 | |||
54 | tasks: VideoStudioTaskPayload[] | ||
55 | } | ||
56 | |||
57 | // --------------------------------------------------------------------------- | ||
58 | |||
59 | export function isAudioMergeTranscodingPayload (payload: RunnerJobPayload): payload is RunnerJobVODAudioMergeTranscodingPayload { | ||
60 | return !!(payload as RunnerJobVODAudioMergeTranscodingPayload).input.audioFileUrl | ||
61 | } | ||
62 | |||
63 | // --------------------------------------------------------------------------- | ||
64 | |||
65 | export interface RunnerJobLiveRTMPHLSTranscodingPayload { | ||
66 | input: { | ||
67 | rtmpUrl: string | ||
68 | } | ||
69 | |||
70 | output: { | ||
71 | toTranscode: { | ||
72 | resolution: number | ||
73 | fps: number | ||
74 | }[] | ||
75 | |||
76 | segmentDuration: number | ||
77 | segmentListSize: number | ||
78 | } | ||
79 | } | ||
diff --git a/shared/models/runners/runner-job-private-payload.model.ts b/shared/models/runners/runner-job-private-payload.model.ts deleted file mode 100644 index 529034db8..000000000 --- a/shared/models/runners/runner-job-private-payload.model.ts +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | import { VideoStudioTaskPayload } from '../server' | ||
2 | |||
3 | export type RunnerJobVODPrivatePayload = | ||
4 | RunnerJobVODWebVideoTranscodingPrivatePayload | | ||
5 | RunnerJobVODAudioMergeTranscodingPrivatePayload | | ||
6 | RunnerJobVODHLSTranscodingPrivatePayload | ||
7 | |||
8 | export type RunnerJobPrivatePayload = | ||
9 | RunnerJobVODPrivatePayload | | ||
10 | RunnerJobLiveRTMPHLSTranscodingPrivatePayload | | ||
11 | RunnerJobVideoStudioTranscodingPrivatePayload | ||
12 | |||
13 | // --------------------------------------------------------------------------- | ||
14 | |||
15 | export interface RunnerJobVODWebVideoTranscodingPrivatePayload { | ||
16 | videoUUID: string | ||
17 | isNewVideo: boolean | ||
18 | } | ||
19 | |||
20 | export interface RunnerJobVODAudioMergeTranscodingPrivatePayload { | ||
21 | videoUUID: string | ||
22 | isNewVideo: boolean | ||
23 | } | ||
24 | |||
25 | export interface RunnerJobVODHLSTranscodingPrivatePayload { | ||
26 | videoUUID: string | ||
27 | isNewVideo: boolean | ||
28 | deleteWebVideoFiles: boolean | ||
29 | } | ||
30 | |||
31 | // --------------------------------------------------------------------------- | ||
32 | |||
33 | export interface RunnerJobLiveRTMPHLSTranscodingPrivatePayload { | ||
34 | videoUUID: string | ||
35 | masterPlaylistName: string | ||
36 | outputDirectory: string | ||
37 | sessionId: string | ||
38 | } | ||
39 | |||
40 | // --------------------------------------------------------------------------- | ||
41 | |||
42 | export interface RunnerJobVideoStudioTranscodingPrivatePayload { | ||
43 | videoUUID: string | ||
44 | originalTasks: VideoStudioTaskPayload[] | ||
45 | } | ||
diff --git a/shared/models/runners/runner-job-state.model.ts b/shared/models/runners/runner-job-state.model.ts deleted file mode 100644 index 7ed34b3bf..000000000 --- a/shared/models/runners/runner-job-state.model.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | export enum RunnerJobState { | ||
2 | PENDING = 1, | ||
3 | PROCESSING = 2, | ||
4 | COMPLETED = 3, | ||
5 | ERRORED = 4, | ||
6 | WAITING_FOR_PARENT_JOB = 5, | ||
7 | CANCELLED = 6, | ||
8 | PARENT_ERRORED = 7, | ||
9 | PARENT_CANCELLED = 8, | ||
10 | COMPLETING = 9 | ||
11 | } | ||
diff --git a/shared/models/runners/runner-job-success-body.model.ts b/shared/models/runners/runner-job-success-body.model.ts deleted file mode 100644 index f45336b05..000000000 --- a/shared/models/runners/runner-job-success-body.model.ts +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | export interface RunnerJobSuccessBody { | ||
2 | runnerToken: string | ||
3 | jobToken: string | ||
4 | |||
5 | payload: RunnerJobSuccessPayload | ||
6 | } | ||
7 | |||
8 | // --------------------------------------------------------------------------- | ||
9 | |||
10 | export type RunnerJobSuccessPayload = | ||
11 | VODWebVideoTranscodingSuccess | | ||
12 | VODHLSTranscodingSuccess | | ||
13 | VODAudioMergeTranscodingSuccess | | ||
14 | LiveRTMPHLSTranscodingSuccess | | ||
15 | VideoStudioTranscodingSuccess | ||
16 | |||
17 | export interface VODWebVideoTranscodingSuccess { | ||
18 | videoFile: Blob | string | ||
19 | } | ||
20 | |||
21 | export interface VODHLSTranscodingSuccess { | ||
22 | videoFile: Blob | string | ||
23 | resolutionPlaylistFile: Blob | string | ||
24 | } | ||
25 | |||
26 | export interface VODAudioMergeTranscodingSuccess { | ||
27 | videoFile: Blob | string | ||
28 | } | ||
29 | |||
30 | export interface LiveRTMPHLSTranscodingSuccess { | ||
31 | |||
32 | } | ||
33 | |||
34 | export interface VideoStudioTranscodingSuccess { | ||
35 | videoFile: Blob | string | ||
36 | } | ||
37 | |||
38 | export function isWebVideoOrAudioMergeTranscodingPayloadSuccess ( | ||
39 | payload: RunnerJobSuccessPayload | ||
40 | ): payload is VODHLSTranscodingSuccess | VODAudioMergeTranscodingSuccess { | ||
41 | return !!(payload as VODHLSTranscodingSuccess | VODAudioMergeTranscodingSuccess)?.videoFile | ||
42 | } | ||
43 | |||
44 | export function isHLSTranscodingPayloadSuccess (payload: RunnerJobSuccessPayload): payload is VODHLSTranscodingSuccess { | ||
45 | return !!(payload as VODHLSTranscodingSuccess)?.resolutionPlaylistFile | ||
46 | } | ||
diff --git a/shared/models/runners/runner-job-type.type.ts b/shared/models/runners/runner-job-type.type.ts deleted file mode 100644 index 91b92a729..000000000 --- a/shared/models/runners/runner-job-type.type.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export type RunnerJobType = | ||
2 | 'vod-web-video-transcoding' | | ||
3 | 'vod-hls-transcoding' | | ||
4 | 'vod-audio-merge-transcoding' | | ||
5 | 'live-rtmp-hls-transcoding' | | ||
6 | 'video-studio-transcoding' | ||
diff --git a/shared/models/runners/runner-job-update-body.model.ts b/shared/models/runners/runner-job-update-body.model.ts deleted file mode 100644 index ed94bbe63..000000000 --- a/shared/models/runners/runner-job-update-body.model.ts +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | export interface RunnerJobUpdateBody { | ||
2 | runnerToken: string | ||
3 | jobToken: string | ||
4 | |||
5 | progress?: number | ||
6 | payload?: RunnerJobUpdatePayload | ||
7 | } | ||
8 | |||
9 | // --------------------------------------------------------------------------- | ||
10 | |||
11 | export type RunnerJobUpdatePayload = LiveRTMPHLSTranscodingUpdatePayload | ||
12 | |||
13 | export interface LiveRTMPHLSTranscodingUpdatePayload { | ||
14 | type: 'add-chunk' | 'remove-chunk' | ||
15 | |||
16 | masterPlaylistFile?: Blob | string | ||
17 | |||
18 | resolutionPlaylistFilename?: string | ||
19 | resolutionPlaylistFile?: Blob | string | ||
20 | |||
21 | videoChunkFilename: string | ||
22 | videoChunkFile?: Blob | string | ||
23 | } | ||
24 | |||
25 | export function isLiveRTMPHLSTranscodingUpdatePayload (value: RunnerJobUpdatePayload): value is LiveRTMPHLSTranscodingUpdatePayload { | ||
26 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
27 | return !!(value as LiveRTMPHLSTranscodingUpdatePayload)?.videoChunkFilename | ||
28 | } | ||
diff --git a/shared/models/runners/runner-job.model.ts b/shared/models/runners/runner-job.model.ts deleted file mode 100644 index 080093563..000000000 --- a/shared/models/runners/runner-job.model.ts +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | import { VideoConstant } from '../videos' | ||
2 | import { RunnerJobPayload } from './runner-job-payload.model' | ||
3 | import { RunnerJobPrivatePayload } from './runner-job-private-payload.model' | ||
4 | import { RunnerJobState } from './runner-job-state.model' | ||
5 | import { RunnerJobType } from './runner-job-type.type' | ||
6 | |||
7 | export interface RunnerJob <T extends RunnerJobPayload = RunnerJobPayload> { | ||
8 | uuid: string | ||
9 | |||
10 | type: RunnerJobType | ||
11 | |||
12 | state: VideoConstant<RunnerJobState> | ||
13 | |||
14 | payload: T | ||
15 | |||
16 | failures: number | ||
17 | error: string | null | ||
18 | |||
19 | progress: number | ||
20 | priority: number | ||
21 | |||
22 | startedAt: Date | string | ||
23 | createdAt: Date | string | ||
24 | updatedAt: Date | string | ||
25 | finishedAt: Date | string | ||
26 | |||
27 | parent?: { | ||
28 | type: RunnerJobType | ||
29 | state: VideoConstant<RunnerJobState> | ||
30 | uuid: string | ||
31 | } | ||
32 | |||
33 | // If associated to a runner | ||
34 | runner?: { | ||
35 | id: number | ||
36 | name: string | ||
37 | |||
38 | description: string | ||
39 | } | ||
40 | } | ||
41 | |||
42 | // eslint-disable-next-line max-len | ||
43 | export interface RunnerJobAdmin <T extends RunnerJobPayload = RunnerJobPayload, U extends RunnerJobPrivatePayload = RunnerJobPrivatePayload> extends RunnerJob<T> { | ||
44 | privatePayload: U | ||
45 | } | ||
diff --git a/shared/models/runners/runner-registration-token.ts b/shared/models/runners/runner-registration-token.ts deleted file mode 100644 index 0a157aa51..000000000 --- a/shared/models/runners/runner-registration-token.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | export interface RunnerRegistrationToken { | ||
2 | id: number | ||
3 | |||
4 | registrationToken: string | ||
5 | |||
6 | createdAt: Date | ||
7 | updatedAt: Date | ||
8 | |||
9 | registeredRunnersCount: number | ||
10 | } | ||
diff --git a/shared/models/runners/runner.model.ts b/shared/models/runners/runner.model.ts deleted file mode 100644 index 3284f2992..000000000 --- a/shared/models/runners/runner.model.ts +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | export interface Runner { | ||
2 | id: number | ||
3 | |||
4 | name: string | ||
5 | description: string | ||
6 | |||
7 | ip: string | ||
8 | lastContact: Date | string | ||
9 | |||
10 | createdAt: Date | string | ||
11 | updatedAt: Date | string | ||
12 | } | ||
diff --git a/shared/models/runners/unregister-runner-body.model.ts b/shared/models/runners/unregister-runner-body.model.ts deleted file mode 100644 index d3465c5d6..000000000 --- a/shared/models/runners/unregister-runner-body.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface UnregisterRunnerBody { | ||
2 | runnerToken: string | ||
3 | } | ||
diff --git a/shared/models/search/boolean-both-query.model.ts b/shared/models/search/boolean-both-query.model.ts deleted file mode 100644 index d6a438249..000000000 --- a/shared/models/search/boolean-both-query.model.ts +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | export type BooleanBothQuery = 'true' | 'false' | 'both' | ||
2 | export type BooleanQuery = 'true' | 'false' | ||
diff --git a/shared/models/search/index.ts b/shared/models/search/index.ts deleted file mode 100644 index 50aeeddc8..000000000 --- a/shared/models/search/index.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export * from './boolean-both-query.model' | ||
2 | export * from './search-target-query.model' | ||
3 | export * from './videos-common-query.model' | ||
4 | export * from './video-channels-search-query.model' | ||
5 | export * from './video-playlists-search-query.model' | ||
6 | export * from './videos-search-query.model' | ||
diff --git a/shared/models/search/search-target-query.model.ts b/shared/models/search/search-target-query.model.ts deleted file mode 100644 index 3bb2e0d31..000000000 --- a/shared/models/search/search-target-query.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export type SearchTargetType = 'local' | 'search-index' | ||
2 | |||
3 | export interface SearchTargetQuery { | ||
4 | searchTarget?: SearchTargetType | ||
5 | } | ||
diff --git a/shared/models/search/video-channels-search-query.model.ts b/shared/models/search/video-channels-search-query.model.ts deleted file mode 100644 index b68a1e80b..000000000 --- a/shared/models/search/video-channels-search-query.model.ts +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | import { SearchTargetQuery } from './search-target-query.model' | ||
2 | |||
3 | export interface VideoChannelsSearchQuery extends SearchTargetQuery { | ||
4 | search?: string | ||
5 | |||
6 | start?: number | ||
7 | count?: number | ||
8 | sort?: string | ||
9 | |||
10 | host?: string | ||
11 | handles?: string[] | ||
12 | } | ||
13 | |||
14 | export interface VideoChannelsSearchQueryAfterSanitize extends VideoChannelsSearchQuery { | ||
15 | start: number | ||
16 | count: number | ||
17 | sort: string | ||
18 | } | ||
diff --git a/shared/models/search/video-playlists-search-query.model.ts b/shared/models/search/video-playlists-search-query.model.ts deleted file mode 100644 index d9027eb5b..000000000 --- a/shared/models/search/video-playlists-search-query.model.ts +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | import { SearchTargetQuery } from './search-target-query.model' | ||
2 | |||
3 | export interface VideoPlaylistsSearchQuery extends SearchTargetQuery { | ||
4 | search?: string | ||
5 | |||
6 | start?: number | ||
7 | count?: number | ||
8 | sort?: string | ||
9 | |||
10 | host?: string | ||
11 | |||
12 | // UUIDs or short UUIDs | ||
13 | uuids?: string[] | ||
14 | } | ||
15 | |||
16 | export interface VideoPlaylistsSearchQueryAfterSanitize extends VideoPlaylistsSearchQuery { | ||
17 | start: number | ||
18 | count: number | ||
19 | sort: string | ||
20 | } | ||
diff --git a/shared/models/search/videos-common-query.model.ts b/shared/models/search/videos-common-query.model.ts deleted file mode 100644 index f783d7534..000000000 --- a/shared/models/search/videos-common-query.model.ts +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | import { VideoPrivacy } from '@shared/models' | ||
2 | import { VideoInclude } from '../videos/video-include.enum' | ||
3 | import { BooleanBothQuery } from './boolean-both-query.model' | ||
4 | |||
5 | // These query parameters can be used with any endpoint that list videos | ||
6 | export interface VideosCommonQuery { | ||
7 | start?: number | ||
8 | count?: number | ||
9 | sort?: string | ||
10 | |||
11 | nsfw?: BooleanBothQuery | ||
12 | |||
13 | isLive?: boolean | ||
14 | |||
15 | isLocal?: boolean | ||
16 | include?: VideoInclude | ||
17 | |||
18 | categoryOneOf?: number[] | ||
19 | |||
20 | licenceOneOf?: number[] | ||
21 | |||
22 | languageOneOf?: string[] | ||
23 | |||
24 | privacyOneOf?: VideoPrivacy[] | ||
25 | |||
26 | tagsOneOf?: string[] | ||
27 | tagsAllOf?: string[] | ||
28 | |||
29 | hasHLSFiles?: boolean | ||
30 | |||
31 | hasWebtorrentFiles?: boolean // TODO: remove in v7 | ||
32 | hasWebVideoFiles?: boolean | ||
33 | |||
34 | skipCount?: boolean | ||
35 | |||
36 | search?: string | ||
37 | |||
38 | excludeAlreadyWatched?: boolean | ||
39 | } | ||
40 | |||
41 | export interface VideosCommonQueryAfterSanitize extends VideosCommonQuery { | ||
42 | start: number | ||
43 | count: number | ||
44 | sort: string | ||
45 | } | ||
diff --git a/shared/models/search/videos-search-query.model.ts b/shared/models/search/videos-search-query.model.ts deleted file mode 100644 index a5436879d..000000000 --- a/shared/models/search/videos-search-query.model.ts +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | import { SearchTargetQuery } from './search-target-query.model' | ||
2 | import { VideosCommonQuery } from './videos-common-query.model' | ||
3 | |||
4 | export interface VideosSearchQuery extends SearchTargetQuery, VideosCommonQuery { | ||
5 | search?: string | ||
6 | |||
7 | host?: string | ||
8 | |||
9 | startDate?: string // ISO 8601 | ||
10 | endDate?: string // ISO 8601 | ||
11 | |||
12 | originallyPublishedStartDate?: string // ISO 8601 | ||
13 | originallyPublishedEndDate?: string // ISO 8601 | ||
14 | |||
15 | durationMin?: number // seconds | ||
16 | durationMax?: number // seconds | ||
17 | |||
18 | // UUIDs or short UUIDs | ||
19 | uuids?: string[] | ||
20 | } | ||
21 | |||
22 | export interface VideosSearchQueryAfterSanitize extends VideosSearchQuery { | ||
23 | start: number | ||
24 | count: number | ||
25 | sort: string | ||
26 | } | ||
diff --git a/shared/models/server/about.model.ts b/shared/models/server/about.model.ts deleted file mode 100644 index 6d4ba63c4..000000000 --- a/shared/models/server/about.model.ts +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | export interface About { | ||
2 | instance: { | ||
3 | name: string | ||
4 | shortDescription: string | ||
5 | description: string | ||
6 | terms: string | ||
7 | |||
8 | codeOfConduct: string | ||
9 | hardwareInformation: string | ||
10 | |||
11 | creationReason: string | ||
12 | moderationInformation: string | ||
13 | administrator: string | ||
14 | maintenanceLifetime: string | ||
15 | businessModel: string | ||
16 | |||
17 | languages: string[] | ||
18 | categories: number[] | ||
19 | } | ||
20 | } | ||
diff --git a/shared/models/server/broadcast-message-level.type.ts b/shared/models/server/broadcast-message-level.type.ts deleted file mode 100644 index bf43e18b5..000000000 --- a/shared/models/server/broadcast-message-level.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type BroadcastMessageLevel = 'info' | 'warning' | 'error' | ||
diff --git a/shared/models/server/client-log-create.model.ts b/shared/models/server/client-log-create.model.ts deleted file mode 100644 index c9dc65568..000000000 --- a/shared/models/server/client-log-create.model.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | import { ClientLogLevel } from './client-log-level.type' | ||
2 | |||
3 | export interface ClientLogCreate { | ||
4 | message: string | ||
5 | url: string | ||
6 | level: ClientLogLevel | ||
7 | |||
8 | stackTrace?: string | ||
9 | userAgent?: string | ||
10 | meta?: string | ||
11 | } | ||
diff --git a/shared/models/server/client-log-level.type.ts b/shared/models/server/client-log-level.type.ts deleted file mode 100644 index 18dea2751..000000000 --- a/shared/models/server/client-log-level.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type ClientLogLevel = 'warn' | 'error' | ||
diff --git a/shared/models/server/contact-form.model.ts b/shared/models/server/contact-form.model.ts deleted file mode 100644 index c23e6d1ba..000000000 --- a/shared/models/server/contact-form.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export interface ContactForm { | ||
2 | fromEmail: string | ||
3 | fromName: string | ||
4 | subject: string | ||
5 | body: string | ||
6 | } | ||
diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts deleted file mode 100644 index 0dbb46fa8..000000000 --- a/shared/models/server/custom-config.model.ts +++ /dev/null | |||
@@ -1,259 +0,0 @@ | |||
1 | import { NSFWPolicyType } from '../videos/nsfw-policy.type' | ||
2 | import { BroadcastMessageLevel } from './broadcast-message-level.type' | ||
3 | |||
4 | export type ConfigResolutions = { | ||
5 | '144p': boolean | ||
6 | '240p': boolean | ||
7 | '360p': boolean | ||
8 | '480p': boolean | ||
9 | '720p': boolean | ||
10 | '1080p': boolean | ||
11 | '1440p': boolean | ||
12 | '2160p': boolean | ||
13 | } | ||
14 | |||
15 | export interface CustomConfig { | ||
16 | instance: { | ||
17 | name: string | ||
18 | shortDescription: string | ||
19 | description: string | ||
20 | terms: string | ||
21 | codeOfConduct: string | ||
22 | |||
23 | creationReason: string | ||
24 | moderationInformation: string | ||
25 | administrator: string | ||
26 | maintenanceLifetime: string | ||
27 | businessModel: string | ||
28 | hardwareInformation: string | ||
29 | |||
30 | languages: string[] | ||
31 | categories: number[] | ||
32 | |||
33 | isNSFW: boolean | ||
34 | defaultNSFWPolicy: NSFWPolicyType | ||
35 | |||
36 | defaultClientRoute: string | ||
37 | |||
38 | customizations: { | ||
39 | javascript?: string | ||
40 | css?: string | ||
41 | } | ||
42 | } | ||
43 | |||
44 | theme: { | ||
45 | default: string | ||
46 | } | ||
47 | |||
48 | services: { | ||
49 | twitter: { | ||
50 | username: string | ||
51 | whitelisted: boolean | ||
52 | } | ||
53 | } | ||
54 | |||
55 | client: { | ||
56 | videos: { | ||
57 | miniature: { | ||
58 | preferAuthorDisplayName: boolean | ||
59 | } | ||
60 | } | ||
61 | |||
62 | menu: { | ||
63 | login: { | ||
64 | redirectOnSingleExternalAuth: boolean | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | |||
69 | cache: { | ||
70 | previews: { | ||
71 | size: number | ||
72 | } | ||
73 | |||
74 | captions: { | ||
75 | size: number | ||
76 | } | ||
77 | |||
78 | torrents: { | ||
79 | size: number | ||
80 | } | ||
81 | |||
82 | storyboards: { | ||
83 | size: number | ||
84 | } | ||
85 | } | ||
86 | |||
87 | signup: { | ||
88 | enabled: boolean | ||
89 | limit: number | ||
90 | requiresApproval: boolean | ||
91 | requiresEmailVerification: boolean | ||
92 | minimumAge: number | ||
93 | } | ||
94 | |||
95 | admin: { | ||
96 | email: string | ||
97 | } | ||
98 | |||
99 | contactForm: { | ||
100 | enabled: boolean | ||
101 | } | ||
102 | |||
103 | user: { | ||
104 | history: { | ||
105 | videos: { | ||
106 | enabled: boolean | ||
107 | } | ||
108 | } | ||
109 | videoQuota: number | ||
110 | videoQuotaDaily: number | ||
111 | } | ||
112 | |||
113 | videoChannels: { | ||
114 | maxPerUser: number | ||
115 | } | ||
116 | |||
117 | transcoding: { | ||
118 | enabled: boolean | ||
119 | |||
120 | allowAdditionalExtensions: boolean | ||
121 | allowAudioFiles: boolean | ||
122 | |||
123 | remoteRunners: { | ||
124 | enabled: boolean | ||
125 | } | ||
126 | |||
127 | threads: number | ||
128 | concurrency: number | ||
129 | |||
130 | profile: string | ||
131 | |||
132 | resolutions: ConfigResolutions & { '0p': boolean } | ||
133 | |||
134 | alwaysTranscodeOriginalResolution: boolean | ||
135 | |||
136 | webVideos: { | ||
137 | enabled: boolean | ||
138 | } | ||
139 | |||
140 | hls: { | ||
141 | enabled: boolean | ||
142 | } | ||
143 | } | ||
144 | |||
145 | live: { | ||
146 | enabled: boolean | ||
147 | |||
148 | allowReplay: boolean | ||
149 | |||
150 | latencySetting: { | ||
151 | enabled: boolean | ||
152 | } | ||
153 | |||
154 | maxDuration: number | ||
155 | maxInstanceLives: number | ||
156 | maxUserLives: number | ||
157 | |||
158 | transcoding: { | ||
159 | enabled: boolean | ||
160 | remoteRunners: { | ||
161 | enabled: boolean | ||
162 | } | ||
163 | threads: number | ||
164 | profile: string | ||
165 | resolutions: ConfigResolutions | ||
166 | alwaysTranscodeOriginalResolution: boolean | ||
167 | } | ||
168 | } | ||
169 | |||
170 | videoStudio: { | ||
171 | enabled: boolean | ||
172 | |||
173 | remoteRunners: { | ||
174 | enabled: boolean | ||
175 | } | ||
176 | } | ||
177 | |||
178 | videoFile: { | ||
179 | update: { | ||
180 | enabled: boolean | ||
181 | } | ||
182 | } | ||
183 | |||
184 | import: { | ||
185 | videos: { | ||
186 | concurrency: number | ||
187 | |||
188 | http: { | ||
189 | enabled: boolean | ||
190 | } | ||
191 | torrent: { | ||
192 | enabled: boolean | ||
193 | } | ||
194 | } | ||
195 | videoChannelSynchronization: { | ||
196 | enabled: boolean | ||
197 | maxPerUser: number | ||
198 | } | ||
199 | } | ||
200 | |||
201 | trending: { | ||
202 | videos: { | ||
203 | algorithms: { | ||
204 | enabled: string[] | ||
205 | default: string | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | autoBlacklist: { | ||
211 | videos: { | ||
212 | ofUsers: { | ||
213 | enabled: boolean | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | |||
218 | followers: { | ||
219 | instance: { | ||
220 | enabled: boolean | ||
221 | manualApproval: boolean | ||
222 | } | ||
223 | } | ||
224 | |||
225 | followings: { | ||
226 | instance: { | ||
227 | autoFollowBack: { | ||
228 | enabled: boolean | ||
229 | } | ||
230 | |||
231 | autoFollowIndex: { | ||
232 | enabled: boolean | ||
233 | indexUrl: string | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | |||
238 | broadcastMessage: { | ||
239 | enabled: boolean | ||
240 | message: string | ||
241 | level: BroadcastMessageLevel | ||
242 | dismissable: boolean | ||
243 | } | ||
244 | |||
245 | search: { | ||
246 | remoteUri: { | ||
247 | users: boolean | ||
248 | anonymous: boolean | ||
249 | } | ||
250 | |||
251 | searchIndex: { | ||
252 | enabled: boolean | ||
253 | url: string | ||
254 | disableLocalSearch: boolean | ||
255 | isDefaultSearch: boolean | ||
256 | } | ||
257 | } | ||
258 | |||
259 | } | ||
diff --git a/shared/models/server/debug.model.ts b/shared/models/server/debug.model.ts deleted file mode 100644 index 41f2109af..000000000 --- a/shared/models/server/debug.model.ts +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | export interface Debug { | ||
2 | ip: string | ||
3 | activityPubMessagesWaiting: number | ||
4 | } | ||
5 | |||
6 | export interface SendDebugCommand { | ||
7 | command: 'remove-dandling-resumable-uploads' | ||
8 | | 'process-video-views-buffer' | ||
9 | | 'process-video-viewers' | ||
10 | | 'process-video-channel-sync-latest' | ||
11 | | 'process-update-videos-scheduler' | ||
12 | } | ||
diff --git a/shared/models/server/emailer.model.ts b/shared/models/server/emailer.model.ts deleted file mode 100644 index 39512d306..000000000 --- a/shared/models/server/emailer.model.ts +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | type From = string | { name?: string, address: string } | ||
2 | |||
3 | interface Base extends Partial<SendEmailDefaultMessageOptions> { | ||
4 | to: string[] | string | ||
5 | } | ||
6 | |||
7 | interface MailTemplate extends Base { | ||
8 | template: string | ||
9 | locals?: { [key: string]: any } | ||
10 | text?: undefined | ||
11 | } | ||
12 | |||
13 | interface MailText extends Base { | ||
14 | text: string | ||
15 | |||
16 | locals?: Partial<SendEmailDefaultLocalsOptions> & { | ||
17 | title?: string | ||
18 | action?: { | ||
19 | url: string | ||
20 | text: string | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | |||
25 | interface SendEmailDefaultLocalsOptions { | ||
26 | instanceName: string | ||
27 | text: string | ||
28 | subject: string | ||
29 | } | ||
30 | |||
31 | interface SendEmailDefaultMessageOptions { | ||
32 | to: string[] | string | ||
33 | from: From | ||
34 | subject: string | ||
35 | replyTo: string | ||
36 | } | ||
37 | |||
38 | export type SendEmailDefaultOptions = { | ||
39 | template: 'common' | ||
40 | |||
41 | message: SendEmailDefaultMessageOptions | ||
42 | |||
43 | locals: SendEmailDefaultLocalsOptions & { | ||
44 | WEBSERVER: any | ||
45 | EMAIL: any | ||
46 | } | ||
47 | } | ||
48 | |||
49 | export type SendEmailOptions = MailTemplate | MailText | ||
diff --git a/shared/models/server/index.ts b/shared/models/server/index.ts deleted file mode 100644 index a9136f3d4..000000000 --- a/shared/models/server/index.ts +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | export * from './about.model' | ||
2 | export * from './broadcast-message-level.type' | ||
3 | export * from './client-log-create.model' | ||
4 | export * from './client-log-level.type' | ||
5 | export * from './contact-form.model' | ||
6 | export * from './custom-config.model' | ||
7 | export * from './debug.model' | ||
8 | export * from './emailer.model' | ||
9 | export * from './job.model' | ||
10 | export * from './peertube-problem-document.model' | ||
11 | export * from './server-config.model' | ||
12 | export * from './server-debug.model' | ||
13 | export * from './server-error-code.enum' | ||
14 | export * from './server-follow-create.model' | ||
15 | export * from './server-log-level.type' | ||
16 | export * from './server-stats.model' | ||
diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts deleted file mode 100644 index c14806dab..000000000 --- a/shared/models/server/job.model.ts +++ /dev/null | |||
@@ -1,304 +0,0 @@ | |||
1 | import { ContextType } from '../activitypub/context' | ||
2 | import { VideoState } from '../videos' | ||
3 | import { VideoResolution } from '../videos/file/video-resolution.enum' | ||
4 | import { VideoStudioTaskCut } from '../videos/studio' | ||
5 | import { SendEmailOptions } from './emailer.model' | ||
6 | |||
7 | export type JobState = 'active' | 'completed' | 'failed' | 'waiting' | 'delayed' | 'paused' | 'waiting-children' | ||
8 | |||
9 | export type JobType = | ||
10 | | 'activitypub-cleaner' | ||
11 | | 'activitypub-follow' | ||
12 | | 'activitypub-http-broadcast-parallel' | ||
13 | | 'activitypub-http-broadcast' | ||
14 | | 'activitypub-http-fetcher' | ||
15 | | 'activitypub-http-unicast' | ||
16 | | 'activitypub-refresher' | ||
17 | | 'actor-keys' | ||
18 | | 'after-video-channel-import' | ||
19 | | 'email' | ||
20 | | 'federate-video' | ||
21 | | 'transcoding-job-builder' | ||
22 | | 'manage-video-torrent' | ||
23 | | 'move-to-object-storage' | ||
24 | | 'notify' | ||
25 | | 'video-channel-import' | ||
26 | | 'video-file-import' | ||
27 | | 'video-import' | ||
28 | | 'video-live-ending' | ||
29 | | 'video-redundancy' | ||
30 | | 'video-studio-edition' | ||
31 | | 'video-transcoding' | ||
32 | | 'videos-views-stats' | ||
33 | | 'generate-video-storyboard' | ||
34 | |||
35 | export interface Job { | ||
36 | id: number | string | ||
37 | state: JobState | 'unknown' | ||
38 | type: JobType | ||
39 | data: any | ||
40 | priority: number | ||
41 | progress: number | ||
42 | error: any | ||
43 | createdAt: Date | string | ||
44 | finishedOn: Date | string | ||
45 | processedOn: Date | string | ||
46 | |||
47 | parent?: { | ||
48 | id: string | ||
49 | } | ||
50 | } | ||
51 | |||
52 | export type ActivitypubHttpBroadcastPayload = { | ||
53 | uris: string[] | ||
54 | contextType: ContextType | ||
55 | body: any | ||
56 | signatureActorId?: number | ||
57 | } | ||
58 | |||
59 | export type ActivitypubFollowPayload = { | ||
60 | followerActorId: number | ||
61 | name: string | ||
62 | host: string | ||
63 | isAutoFollow?: boolean | ||
64 | assertIsChannel?: boolean | ||
65 | } | ||
66 | |||
67 | export type FetchType = 'activity' | 'video-shares' | 'video-comments' | 'account-playlists' | ||
68 | export type ActivitypubHttpFetcherPayload = { | ||
69 | uri: string | ||
70 | type: FetchType | ||
71 | videoId?: number | ||
72 | } | ||
73 | |||
74 | export type ActivitypubHttpUnicastPayload = { | ||
75 | uri: string | ||
76 | contextType: ContextType | ||
77 | signatureActorId?: number | ||
78 | body: object | ||
79 | } | ||
80 | |||
81 | export type RefreshPayload = { | ||
82 | type: 'video' | 'video-playlist' | 'actor' | ||
83 | url: string | ||
84 | } | ||
85 | |||
86 | export type EmailPayload = SendEmailOptions | ||
87 | |||
88 | export type VideoFileImportPayload = { | ||
89 | videoUUID: string | ||
90 | filePath: string | ||
91 | } | ||
92 | |||
93 | // --------------------------------------------------------------------------- | ||
94 | |||
95 | export type VideoImportTorrentPayloadType = 'magnet-uri' | 'torrent-file' | ||
96 | export type VideoImportYoutubeDLPayloadType = 'youtube-dl' | ||
97 | |||
98 | export interface VideoImportYoutubeDLPayload { | ||
99 | type: VideoImportYoutubeDLPayloadType | ||
100 | videoImportId: number | ||
101 | |||
102 | fileExt?: string | ||
103 | } | ||
104 | |||
105 | export interface VideoImportTorrentPayload { | ||
106 | type: VideoImportTorrentPayloadType | ||
107 | videoImportId: number | ||
108 | } | ||
109 | |||
110 | export type VideoImportPayload = (VideoImportYoutubeDLPayload | VideoImportTorrentPayload) & { | ||
111 | preventException: boolean | ||
112 | } | ||
113 | |||
114 | export interface VideoImportPreventExceptionResult { | ||
115 | resultType: 'success' | 'error' | ||
116 | } | ||
117 | |||
118 | // --------------------------------------------------------------------------- | ||
119 | |||
120 | export type VideoRedundancyPayload = { | ||
121 | videoId: number | ||
122 | } | ||
123 | |||
124 | export type ManageVideoTorrentPayload = | ||
125 | { | ||
126 | action: 'create' | ||
127 | videoId: number | ||
128 | videoFileId: number | ||
129 | } | { | ||
130 | action: 'update-metadata' | ||
131 | |||
132 | videoId?: number | ||
133 | streamingPlaylistId?: number | ||
134 | |||
135 | videoFileId: number | ||
136 | } | ||
137 | |||
138 | // Video transcoding payloads | ||
139 | |||
140 | interface BaseTranscodingPayload { | ||
141 | videoUUID: string | ||
142 | isNewVideo?: boolean | ||
143 | } | ||
144 | |||
145 | export interface HLSTranscodingPayload extends BaseTranscodingPayload { | ||
146 | type: 'new-resolution-to-hls' | ||
147 | resolution: VideoResolution | ||
148 | fps: number | ||
149 | copyCodecs: boolean | ||
150 | |||
151 | deleteWebVideoFiles: boolean | ||
152 | } | ||
153 | |||
154 | export interface NewWebVideoResolutionTranscodingPayload extends BaseTranscodingPayload { | ||
155 | type: 'new-resolution-to-web-video' | ||
156 | resolution: VideoResolution | ||
157 | fps: number | ||
158 | } | ||
159 | |||
160 | export interface MergeAudioTranscodingPayload extends BaseTranscodingPayload { | ||
161 | type: 'merge-audio-to-web-video' | ||
162 | |||
163 | resolution: VideoResolution | ||
164 | fps: number | ||
165 | |||
166 | hasChildren: boolean | ||
167 | } | ||
168 | |||
169 | export interface OptimizeTranscodingPayload extends BaseTranscodingPayload { | ||
170 | type: 'optimize-to-web-video' | ||
171 | |||
172 | quickTranscode: boolean | ||
173 | |||
174 | hasChildren: boolean | ||
175 | } | ||
176 | |||
177 | export type VideoTranscodingPayload = | ||
178 | HLSTranscodingPayload | ||
179 | | NewWebVideoResolutionTranscodingPayload | ||
180 | | OptimizeTranscodingPayload | ||
181 | | MergeAudioTranscodingPayload | ||
182 | |||
183 | export interface VideoLiveEndingPayload { | ||
184 | videoId: number | ||
185 | publishedAt: string | ||
186 | liveSessionId: number | ||
187 | streamingPlaylistId: number | ||
188 | |||
189 | replayDirectory?: string | ||
190 | } | ||
191 | |||
192 | export interface ActorKeysPayload { | ||
193 | actorId: number | ||
194 | } | ||
195 | |||
196 | export interface DeleteResumableUploadMetaFilePayload { | ||
197 | filepath: string | ||
198 | } | ||
199 | |||
200 | export interface MoveObjectStoragePayload { | ||
201 | videoUUID: string | ||
202 | isNewVideo: boolean | ||
203 | previousVideoState: VideoState | ||
204 | } | ||
205 | |||
206 | export type VideoStudioTaskCutPayload = VideoStudioTaskCut | ||
207 | |||
208 | export type VideoStudioTaskIntroPayload = { | ||
209 | name: 'add-intro' | ||
210 | |||
211 | options: { | ||
212 | file: string | ||
213 | } | ||
214 | } | ||
215 | |||
216 | export type VideoStudioTaskOutroPayload = { | ||
217 | name: 'add-outro' | ||
218 | |||
219 | options: { | ||
220 | file: string | ||
221 | } | ||
222 | } | ||
223 | |||
224 | export type VideoStudioTaskWatermarkPayload = { | ||
225 | name: 'add-watermark' | ||
226 | |||
227 | options: { | ||
228 | file: string | ||
229 | |||
230 | watermarkSizeRatio: number | ||
231 | horitonzalMarginRatio: number | ||
232 | verticalMarginRatio: number | ||
233 | } | ||
234 | } | ||
235 | |||
236 | export type VideoStudioTaskPayload = | ||
237 | VideoStudioTaskCutPayload | | ||
238 | VideoStudioTaskIntroPayload | | ||
239 | VideoStudioTaskOutroPayload | | ||
240 | VideoStudioTaskWatermarkPayload | ||
241 | |||
242 | export interface VideoStudioEditionPayload { | ||
243 | videoUUID: string | ||
244 | tasks: VideoStudioTaskPayload[] | ||
245 | } | ||
246 | |||
247 | // --------------------------------------------------------------------------- | ||
248 | |||
249 | export interface VideoChannelImportPayload { | ||
250 | externalChannelUrl: string | ||
251 | videoChannelId: number | ||
252 | |||
253 | partOfChannelSyncId?: number | ||
254 | } | ||
255 | |||
256 | export interface AfterVideoChannelImportPayload { | ||
257 | channelSyncId: number | ||
258 | } | ||
259 | |||
260 | // --------------------------------------------------------------------------- | ||
261 | |||
262 | export type NotifyPayload = | ||
263 | { | ||
264 | action: 'new-video' | ||
265 | videoUUID: string | ||
266 | } | ||
267 | |||
268 | // --------------------------------------------------------------------------- | ||
269 | |||
270 | export interface FederateVideoPayload { | ||
271 | videoUUID: string | ||
272 | isNewVideo: boolean | ||
273 | } | ||
274 | |||
275 | // --------------------------------------------------------------------------- | ||
276 | |||
277 | export interface TranscodingJobBuilderPayload { | ||
278 | videoUUID: string | ||
279 | |||
280 | optimizeJob?: { | ||
281 | isNewVideo: boolean | ||
282 | } | ||
283 | |||
284 | // Array of jobs to create | ||
285 | jobs?: { | ||
286 | type: 'video-transcoding' | ||
287 | payload: VideoTranscodingPayload | ||
288 | priority?: number | ||
289 | }[] | ||
290 | |||
291 | // Array of sequential jobs to create | ||
292 | sequentialJobs?: { | ||
293 | type: 'video-transcoding' | ||
294 | payload: VideoTranscodingPayload | ||
295 | priority?: number | ||
296 | }[][] | ||
297 | } | ||
298 | |||
299 | // --------------------------------------------------------------------------- | ||
300 | |||
301 | export interface GenerateStoryboardPayload { | ||
302 | videoUUID: string | ||
303 | federate: boolean | ||
304 | } | ||
diff --git a/shared/models/server/peertube-problem-document.model.ts b/shared/models/server/peertube-problem-document.model.ts deleted file mode 100644 index 83d9cea9b..000000000 --- a/shared/models/server/peertube-problem-document.model.ts +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | import { HttpStatusCode } from '../../models' | ||
2 | import { OAuth2ErrorCode, ServerErrorCode } from './server-error-code.enum' | ||
3 | |||
4 | export interface PeerTubeProblemDocumentData { | ||
5 | 'invalid-params'?: Record<string, object> | ||
6 | |||
7 | originUrl?: string | ||
8 | |||
9 | keyId?: string | ||
10 | |||
11 | targetUrl?: string | ||
12 | |||
13 | actorUrl?: string | ||
14 | |||
15 | // Feeds | ||
16 | format?: string | ||
17 | url?: string | ||
18 | } | ||
19 | |||
20 | export interface PeerTubeProblemDocument extends PeerTubeProblemDocumentData { | ||
21 | type: string | ||
22 | title: string | ||
23 | |||
24 | detail: string | ||
25 | // Compat PeerTube <= 3.2 | ||
26 | error: string | ||
27 | |||
28 | status: HttpStatusCode | ||
29 | |||
30 | docs?: string | ||
31 | code?: ServerErrorCode | OAuth2ErrorCode | ||
32 | } | ||
diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts deleted file mode 100644 index 3f61e93b5..000000000 --- a/shared/models/server/server-config.model.ts +++ /dev/null | |||
@@ -1,305 +0,0 @@ | |||
1 | import { ClientScriptJSON } from '../plugins/plugin-package-json.model' | ||
2 | import { NSFWPolicyType } from '../videos/nsfw-policy.type' | ||
3 | import { VideoPrivacy } from '../videos/video-privacy.enum' | ||
4 | import { BroadcastMessageLevel } from './broadcast-message-level.type' | ||
5 | |||
6 | export interface ServerConfigPlugin { | ||
7 | name: string | ||
8 | npmName: string | ||
9 | version: string | ||
10 | description: string | ||
11 | clientScripts: { [name: string]: ClientScriptJSON } | ||
12 | } | ||
13 | |||
14 | export interface ServerConfigTheme extends ServerConfigPlugin { | ||
15 | css: string[] | ||
16 | } | ||
17 | |||
18 | export interface RegisteredExternalAuthConfig { | ||
19 | npmName: string | ||
20 | name: string | ||
21 | version: string | ||
22 | authName: string | ||
23 | authDisplayName: string | ||
24 | } | ||
25 | |||
26 | export interface RegisteredIdAndPassAuthConfig { | ||
27 | npmName: string | ||
28 | name: string | ||
29 | version: string | ||
30 | authName: string | ||
31 | weight: number | ||
32 | } | ||
33 | |||
34 | export interface ServerConfig { | ||
35 | serverVersion: string | ||
36 | serverCommit?: string | ||
37 | |||
38 | client: { | ||
39 | videos: { | ||
40 | miniature: { | ||
41 | displayAuthorAvatar: boolean | ||
42 | preferAuthorDisplayName: boolean | ||
43 | } | ||
44 | resumableUpload: { | ||
45 | maxChunkSize: number | ||
46 | } | ||
47 | } | ||
48 | |||
49 | menu: { | ||
50 | login: { | ||
51 | redirectOnSingleExternalAuth: boolean | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | defaults: { | ||
57 | publish: { | ||
58 | downloadEnabled: boolean | ||
59 | commentsEnabled: boolean | ||
60 | privacy: VideoPrivacy | ||
61 | licence: number | ||
62 | } | ||
63 | |||
64 | p2p: { | ||
65 | webapp: { | ||
66 | enabled: boolean | ||
67 | } | ||
68 | |||
69 | embed: { | ||
70 | enabled: boolean | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | webadmin: { | ||
76 | configuration: { | ||
77 | edition: { | ||
78 | allowed: boolean | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | instance: { | ||
84 | name: string | ||
85 | shortDescription: string | ||
86 | isNSFW: boolean | ||
87 | defaultNSFWPolicy: NSFWPolicyType | ||
88 | defaultClientRoute: string | ||
89 | customizations: { | ||
90 | javascript: string | ||
91 | css: string | ||
92 | } | ||
93 | } | ||
94 | |||
95 | search: { | ||
96 | remoteUri: { | ||
97 | users: boolean | ||
98 | anonymous: boolean | ||
99 | } | ||
100 | |||
101 | searchIndex: { | ||
102 | enabled: boolean | ||
103 | url: string | ||
104 | disableLocalSearch: boolean | ||
105 | isDefaultSearch: boolean | ||
106 | } | ||
107 | } | ||
108 | |||
109 | plugin: { | ||
110 | registered: ServerConfigPlugin[] | ||
111 | |||
112 | registeredExternalAuths: RegisteredExternalAuthConfig[] | ||
113 | |||
114 | registeredIdAndPassAuths: RegisteredIdAndPassAuthConfig[] | ||
115 | } | ||
116 | |||
117 | theme: { | ||
118 | registered: ServerConfigTheme[] | ||
119 | default: string | ||
120 | } | ||
121 | |||
122 | email: { | ||
123 | enabled: boolean | ||
124 | } | ||
125 | |||
126 | contactForm: { | ||
127 | enabled: boolean | ||
128 | } | ||
129 | |||
130 | signup: { | ||
131 | allowed: boolean | ||
132 | allowedForCurrentIP: boolean | ||
133 | requiresEmailVerification: boolean | ||
134 | requiresApproval: boolean | ||
135 | minimumAge: number | ||
136 | } | ||
137 | |||
138 | transcoding: { | ||
139 | hls: { | ||
140 | enabled: boolean | ||
141 | } | ||
142 | |||
143 | web_videos: { | ||
144 | enabled: boolean | ||
145 | } | ||
146 | |||
147 | enabledResolutions: number[] | ||
148 | |||
149 | profile: string | ||
150 | availableProfiles: string[] | ||
151 | |||
152 | remoteRunners: { | ||
153 | enabled: boolean | ||
154 | } | ||
155 | } | ||
156 | |||
157 | live: { | ||
158 | enabled: boolean | ||
159 | |||
160 | allowReplay: boolean | ||
161 | latencySetting: { | ||
162 | enabled: boolean | ||
163 | } | ||
164 | |||
165 | maxDuration: number | ||
166 | maxInstanceLives: number | ||
167 | maxUserLives: number | ||
168 | |||
169 | transcoding: { | ||
170 | enabled: boolean | ||
171 | |||
172 | remoteRunners: { | ||
173 | enabled: boolean | ||
174 | } | ||
175 | |||
176 | enabledResolutions: number[] | ||
177 | |||
178 | profile: string | ||
179 | availableProfiles: string[] | ||
180 | } | ||
181 | |||
182 | rtmp: { | ||
183 | port: number | ||
184 | } | ||
185 | } | ||
186 | |||
187 | videoStudio: { | ||
188 | enabled: boolean | ||
189 | |||
190 | remoteRunners: { | ||
191 | enabled: boolean | ||
192 | } | ||
193 | } | ||
194 | |||
195 | videoFile: { | ||
196 | update: { | ||
197 | enabled: boolean | ||
198 | } | ||
199 | } | ||
200 | |||
201 | import: { | ||
202 | videos: { | ||
203 | http: { | ||
204 | enabled: boolean | ||
205 | } | ||
206 | torrent: { | ||
207 | enabled: boolean | ||
208 | } | ||
209 | } | ||
210 | videoChannelSynchronization: { | ||
211 | enabled: boolean | ||
212 | } | ||
213 | } | ||
214 | |||
215 | autoBlacklist: { | ||
216 | videos: { | ||
217 | ofUsers: { | ||
218 | enabled: boolean | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | avatar: { | ||
224 | file: { | ||
225 | size: { | ||
226 | max: number | ||
227 | } | ||
228 | extensions: string[] | ||
229 | } | ||
230 | } | ||
231 | |||
232 | banner: { | ||
233 | file: { | ||
234 | size: { | ||
235 | max: number | ||
236 | } | ||
237 | extensions: string[] | ||
238 | } | ||
239 | } | ||
240 | |||
241 | video: { | ||
242 | image: { | ||
243 | size: { | ||
244 | max: number | ||
245 | } | ||
246 | extensions: string[] | ||
247 | } | ||
248 | file: { | ||
249 | extensions: string[] | ||
250 | } | ||
251 | } | ||
252 | |||
253 | videoCaption: { | ||
254 | file: { | ||
255 | size: { | ||
256 | max: number | ||
257 | } | ||
258 | extensions: string[] | ||
259 | } | ||
260 | } | ||
261 | |||
262 | user: { | ||
263 | videoQuota: number | ||
264 | videoQuotaDaily: number | ||
265 | } | ||
266 | |||
267 | videoChannels: { | ||
268 | maxPerUser: number | ||
269 | } | ||
270 | |||
271 | trending: { | ||
272 | videos: { | ||
273 | intervalDays: number | ||
274 | algorithms: { | ||
275 | enabled: string[] | ||
276 | default: string | ||
277 | } | ||
278 | } | ||
279 | } | ||
280 | |||
281 | tracker: { | ||
282 | enabled: boolean | ||
283 | } | ||
284 | |||
285 | followings: { | ||
286 | instance: { | ||
287 | autoFollowIndex: { | ||
288 | indexUrl: string | ||
289 | } | ||
290 | } | ||
291 | } | ||
292 | |||
293 | broadcastMessage: { | ||
294 | enabled: boolean | ||
295 | message: string | ||
296 | level: BroadcastMessageLevel | ||
297 | dismissable: boolean | ||
298 | } | ||
299 | |||
300 | homepage: { | ||
301 | enabled: boolean | ||
302 | } | ||
303 | } | ||
304 | |||
305 | export type HTMLServerConfig = Omit<ServerConfig, 'signup'> | ||
diff --git a/shared/models/server/server-debug.model.ts b/shared/models/server/server-debug.model.ts deleted file mode 100644 index 4b731bb90..000000000 --- a/shared/models/server/server-debug.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface ServerDebug { | ||
2 | ip: string | ||
3 | activityPubMessagesWaiting: number | ||
4 | } | ||
diff --git a/shared/models/server/server-error-code.enum.ts b/shared/models/server/server-error-code.enum.ts deleted file mode 100644 index 583e8245f..000000000 --- a/shared/models/server/server-error-code.enum.ts +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | export const enum ServerErrorCode { | ||
2 | /** | ||
3 | * The simplest form of payload too large: when the file size is over the | ||
4 | * global file size limit | ||
5 | */ | ||
6 | MAX_FILE_SIZE_REACHED = 'max_file_size_reached', | ||
7 | |||
8 | /** | ||
9 | * The payload is too large for the user quota set | ||
10 | */ | ||
11 | QUOTA_REACHED = 'quota_reached', | ||
12 | |||
13 | /** | ||
14 | * Error yielded upon trying to access a video that is not federated, nor can | ||
15 | * be. This may be due to: remote videos on instances that are not followed by | ||
16 | * yours, and with your instance disallowing unknown instances being accessed. | ||
17 | */ | ||
18 | DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS = 'does_not_respect_follow_constraints', | ||
19 | |||
20 | LIVE_NOT_ENABLED = 'live_not_enabled', | ||
21 | LIVE_NOT_ALLOWING_REPLAY = 'live_not_allowing_replay', | ||
22 | LIVE_CONFLICTING_PERMANENT_AND_SAVE_REPLAY = 'live_conflicting_permanent_and_save_replay', | ||
23 | /** | ||
24 | * Pretty self-explanatory: the set maximum number of simultaneous lives was | ||
25 | * reached, and this error is typically there to inform the user trying to | ||
26 | * broadcast one. | ||
27 | */ | ||
28 | MAX_INSTANCE_LIVES_LIMIT_REACHED = 'max_instance_lives_limit_reached', | ||
29 | /** | ||
30 | * Pretty self-explanatory: the set maximum number of simultaneous lives FOR | ||
31 | * THIS USER was reached, and this error is typically there to inform the user | ||
32 | * trying to broadcast one. | ||
33 | */ | ||
34 | MAX_USER_LIVES_LIMIT_REACHED = 'max_user_lives_limit_reached', | ||
35 | |||
36 | /** | ||
37 | * A torrent should have at most one correct video file. Any more and we will | ||
38 | * not be able to choose automatically. | ||
39 | */ | ||
40 | INCORRECT_FILES_IN_TORRENT = 'incorrect_files_in_torrent', | ||
41 | |||
42 | COMMENT_NOT_ASSOCIATED_TO_VIDEO = 'comment_not_associated_to_video', | ||
43 | |||
44 | MISSING_TWO_FACTOR = 'missing_two_factor', | ||
45 | INVALID_TWO_FACTOR = 'invalid_two_factor', | ||
46 | |||
47 | ACCOUNT_WAITING_FOR_APPROVAL = 'account_waiting_for_approval', | ||
48 | ACCOUNT_APPROVAL_REJECTED = 'account_approval_rejected', | ||
49 | |||
50 | RUNNER_JOB_NOT_IN_PROCESSING_STATE = 'runner_job_not_in_processing_state', | ||
51 | RUNNER_JOB_NOT_IN_PENDING_STATE = 'runner_job_not_in_pending_state', | ||
52 | UNKNOWN_RUNNER_TOKEN = 'unknown_runner_token', | ||
53 | |||
54 | VIDEO_REQUIRES_PASSWORD = 'video_requires_password', | ||
55 | INCORRECT_VIDEO_PASSWORD = 'incorrect_video_password', | ||
56 | |||
57 | VIDEO_ALREADY_BEING_TRANSCODED = 'video_already_being_transcoded' | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * oauthjs/oauth2-server error codes | ||
62 | * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2 | ||
63 | **/ | ||
64 | export const enum OAuth2ErrorCode { | ||
65 | /** | ||
66 | * The provided authorization grant (e.g., authorization code, resource owner | ||
67 | * credentials) or refresh token is invalid, expired, revoked, does not match | ||
68 | * the redirection URI used in the authorization request, or was issued to | ||
69 | * another client. | ||
70 | * | ||
71 | * @see https://github.com/oauthjs/node-oauth2-server/blob/master/lib/errors/invalid-grant-error.js | ||
72 | */ | ||
73 | INVALID_GRANT = 'invalid_grant', | ||
74 | |||
75 | /** | ||
76 | * Client authentication failed (e.g., unknown client, no client authentication | ||
77 | * included, or unsupported authentication method). | ||
78 | * | ||
79 | * @see https://github.com/oauthjs/node-oauth2-server/blob/master/lib/errors/invalid-client-error.js | ||
80 | */ | ||
81 | INVALID_CLIENT = 'invalid_client', | ||
82 | |||
83 | /** | ||
84 | * The access token provided is expired, revoked, malformed, or invalid for other reasons | ||
85 | * | ||
86 | * @see https://github.com/oauthjs/node-oauth2-server/blob/master/lib/errors/invalid-token-error.js | ||
87 | */ | ||
88 | INVALID_TOKEN = 'invalid_token' | ||
89 | } | ||
diff --git a/shared/models/server/server-follow-create.model.ts b/shared/models/server/server-follow-create.model.ts deleted file mode 100644 index 3f90c7d6f..000000000 --- a/shared/models/server/server-follow-create.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface ServerFollowCreate { | ||
2 | hosts?: string[] | ||
3 | handles?: string[] | ||
4 | } | ||
diff --git a/shared/models/server/server-log-level.type.ts b/shared/models/server/server-log-level.type.ts deleted file mode 100644 index f0f31a4ae..000000000 --- a/shared/models/server/server-log-level.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type ServerLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'audit' | ||
diff --git a/shared/models/server/server-stats.model.ts b/shared/models/server/server-stats.model.ts deleted file mode 100644 index 82f5a737f..000000000 --- a/shared/models/server/server-stats.model.ts +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | import { ActivityType } from '../activitypub' | ||
2 | import { VideoRedundancyStrategyWithManual } from '../redundancy' | ||
3 | |||
4 | type ActivityPubMessagesSuccess = Record<`totalActivityPub${ActivityType}MessagesSuccesses`, number> | ||
5 | type ActivityPubMessagesErrors = Record<`totalActivityPub${ActivityType}MessagesErrors`, number> | ||
6 | |||
7 | export interface ServerStats extends ActivityPubMessagesSuccess, ActivityPubMessagesErrors { | ||
8 | totalUsers: number | ||
9 | totalDailyActiveUsers: number | ||
10 | totalWeeklyActiveUsers: number | ||
11 | totalMonthlyActiveUsers: number | ||
12 | |||
13 | totalLocalVideos: number | ||
14 | totalLocalVideoViews: number | ||
15 | totalLocalVideoComments: number | ||
16 | totalLocalVideoFilesSize: number | ||
17 | |||
18 | totalVideos: number | ||
19 | totalVideoComments: number | ||
20 | |||
21 | totalLocalVideoChannels: number | ||
22 | totalLocalDailyActiveVideoChannels: number | ||
23 | totalLocalWeeklyActiveVideoChannels: number | ||
24 | totalLocalMonthlyActiveVideoChannels: number | ||
25 | |||
26 | totalLocalPlaylists: number | ||
27 | |||
28 | totalInstanceFollowers: number | ||
29 | totalInstanceFollowing: number | ||
30 | |||
31 | videosRedundancy: VideosRedundancyStats[] | ||
32 | |||
33 | totalActivityPubMessagesProcessed: number | ||
34 | totalActivityPubMessagesSuccesses: number | ||
35 | totalActivityPubMessagesErrors: number | ||
36 | |||
37 | activityPubMessagesProcessedPerSecond: number | ||
38 | totalActivityPubMessagesWaiting: number | ||
39 | } | ||
40 | |||
41 | export interface VideosRedundancyStats { | ||
42 | strategy: VideoRedundancyStrategyWithManual | ||
43 | totalSize: number | ||
44 | totalUsed: number | ||
45 | totalVideoFiles: number | ||
46 | totalVideos: number | ||
47 | } | ||
diff --git a/shared/models/tokens/index.ts b/shared/models/tokens/index.ts deleted file mode 100644 index fe130f153..000000000 --- a/shared/models/tokens/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './oauth-client-local.model' | ||
diff --git a/shared/models/tokens/oauth-client-local.model.ts b/shared/models/tokens/oauth-client-local.model.ts deleted file mode 100644 index 0c6ce6c5d..000000000 --- a/shared/models/tokens/oauth-client-local.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface OAuthClientLocal { | ||
2 | client_id: string | ||
3 | client_secret: string | ||
4 | } | ||
diff --git a/shared/models/users/index.ts b/shared/models/users/index.ts deleted file mode 100644 index 4a050c870..000000000 --- a/shared/models/users/index.ts +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | export * from './registration' | ||
2 | export * from './two-factor-enable-result.model' | ||
3 | export * from './user-create-result.model' | ||
4 | export * from './user-create.model' | ||
5 | export * from './user-flag.model' | ||
6 | export * from './user-login.model' | ||
7 | export * from './user-notification-setting.model' | ||
8 | export * from './user-notification.model' | ||
9 | export * from './user-refresh-token.model' | ||
10 | export * from './user-right.enum' | ||
11 | export * from './user-role' | ||
12 | export * from './user-scoped-token' | ||
13 | export * from './user-update-me.model' | ||
14 | export * from './user-update.model' | ||
15 | export * from './user-video-quota.model' | ||
16 | export * from './user.model' | ||
diff --git a/shared/models/users/registration/index.ts b/shared/models/users/registration/index.ts deleted file mode 100644 index 593740c4f..000000000 --- a/shared/models/users/registration/index.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export * from './user-register.model' | ||
2 | export * from './user-registration-request.model' | ||
3 | export * from './user-registration-state.model' | ||
4 | export * from './user-registration-update-state.model' | ||
5 | export * from './user-registration.model' | ||
diff --git a/shared/models/users/registration/user-register.model.ts b/shared/models/users/registration/user-register.model.ts deleted file mode 100644 index cf9a43a67..000000000 --- a/shared/models/users/registration/user-register.model.ts +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | export interface UserRegister { | ||
2 | username: string | ||
3 | password: string | ||
4 | email: string | ||
5 | |||
6 | displayName?: string | ||
7 | |||
8 | channel?: { | ||
9 | name: string | ||
10 | displayName: string | ||
11 | } | ||
12 | } | ||
diff --git a/shared/models/users/registration/user-registration-request.model.ts b/shared/models/users/registration/user-registration-request.model.ts deleted file mode 100644 index 6c38817e0..000000000 --- a/shared/models/users/registration/user-registration-request.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | import { UserRegister } from './user-register.model' | ||
2 | |||
3 | export interface UserRegistrationRequest extends UserRegister { | ||
4 | registrationReason: string | ||
5 | } | ||
diff --git a/shared/models/users/registration/user-registration-state.model.ts b/shared/models/users/registration/user-registration-state.model.ts deleted file mode 100644 index e4c835f78..000000000 --- a/shared/models/users/registration/user-registration-state.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export const enum UserRegistrationState { | ||
2 | PENDING = 1, | ||
3 | REJECTED = 2, | ||
4 | ACCEPTED = 3 | ||
5 | } | ||
diff --git a/shared/models/users/registration/user-registration-update-state.model.ts b/shared/models/users/registration/user-registration-update-state.model.ts deleted file mode 100644 index a1740dcca..000000000 --- a/shared/models/users/registration/user-registration-update-state.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface UserRegistrationUpdateState { | ||
2 | moderationResponse: string | ||
3 | preventEmailDelivery?: boolean | ||
4 | } | ||
diff --git a/shared/models/users/registration/user-registration.model.ts b/shared/models/users/registration/user-registration.model.ts deleted file mode 100644 index 0d74dc28b..000000000 --- a/shared/models/users/registration/user-registration.model.ts +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | import { UserRegistrationState } from './user-registration-state.model' | ||
2 | |||
3 | export interface UserRegistration { | ||
4 | id: number | ||
5 | |||
6 | state: { | ||
7 | id: UserRegistrationState | ||
8 | label: string | ||
9 | } | ||
10 | |||
11 | registrationReason: string | ||
12 | moderationResponse: string | ||
13 | |||
14 | username: string | ||
15 | email: string | ||
16 | emailVerified: boolean | ||
17 | |||
18 | accountDisplayName: string | ||
19 | |||
20 | channelHandle: string | ||
21 | channelDisplayName: string | ||
22 | |||
23 | createdAt: Date | ||
24 | updatedAt: Date | ||
25 | |||
26 | user?: { | ||
27 | id: number | ||
28 | } | ||
29 | } | ||
diff --git a/shared/models/users/two-factor-enable-result.model.ts b/shared/models/users/two-factor-enable-result.model.ts deleted file mode 100644 index 1fc801f0a..000000000 --- a/shared/models/users/two-factor-enable-result.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | export interface TwoFactorEnableResult { | ||
2 | otpRequest: { | ||
3 | requestToken: string | ||
4 | secret: string | ||
5 | uri: string | ||
6 | } | ||
7 | } | ||
diff --git a/shared/models/users/user-create-result.model.ts b/shared/models/users/user-create-result.model.ts deleted file mode 100644 index 835b241ed..000000000 --- a/shared/models/users/user-create-result.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | export interface UserCreateResult { | ||
2 | id: number | ||
3 | |||
4 | account: { | ||
5 | id: number | ||
6 | } | ||
7 | } | ||
diff --git a/shared/models/users/user-create.model.ts b/shared/models/users/user-create.model.ts deleted file mode 100644 index ddc71dd59..000000000 --- a/shared/models/users/user-create.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { UserRole } from './user-role' | ||
2 | import { UserAdminFlag } from './user-flag.model' | ||
3 | |||
4 | export interface UserCreate { | ||
5 | username: string | ||
6 | password: string | ||
7 | email: string | ||
8 | videoQuota: number | ||
9 | videoQuotaDaily: number | ||
10 | role: UserRole | ||
11 | adminFlags?: UserAdminFlag | ||
12 | channelName?: string | ||
13 | } | ||
diff --git a/shared/models/users/user-flag.model.ts b/shared/models/users/user-flag.model.ts deleted file mode 100644 index b791a1263..000000000 --- a/shared/models/users/user-flag.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export const enum UserAdminFlag { | ||
2 | NONE = 0, | ||
3 | BYPASS_VIDEO_AUTO_BLACKLIST = 1 << 0 | ||
4 | } | ||
diff --git a/shared/models/users/user-login.model.ts b/shared/models/users/user-login.model.ts deleted file mode 100644 index 1e85ab30b..000000000 --- a/shared/models/users/user-login.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface UserLogin { | ||
2 | access_token: string | ||
3 | refresh_token: string | ||
4 | token_type: string | ||
5 | } | ||
diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.ts deleted file mode 100644 index 278a05e7a..000000000 --- a/shared/models/users/user-notification-setting.model.ts +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | export const enum UserNotificationSettingValue { | ||
2 | NONE = 0, | ||
3 | WEB = 1 << 0, | ||
4 | EMAIL = 1 << 1 | ||
5 | } | ||
6 | |||
7 | export interface UserNotificationSetting { | ||
8 | abuseAsModerator: UserNotificationSettingValue | ||
9 | videoAutoBlacklistAsModerator: UserNotificationSettingValue | ||
10 | newUserRegistration: UserNotificationSettingValue | ||
11 | |||
12 | newVideoFromSubscription: UserNotificationSettingValue | ||
13 | |||
14 | blacklistOnMyVideo: UserNotificationSettingValue | ||
15 | myVideoPublished: UserNotificationSettingValue | ||
16 | myVideoImportFinished: UserNotificationSettingValue | ||
17 | |||
18 | commentMention: UserNotificationSettingValue | ||
19 | newCommentOnMyVideo: UserNotificationSettingValue | ||
20 | |||
21 | newFollow: UserNotificationSettingValue | ||
22 | newInstanceFollower: UserNotificationSettingValue | ||
23 | autoInstanceFollowing: UserNotificationSettingValue | ||
24 | |||
25 | abuseStateChange: UserNotificationSettingValue | ||
26 | abuseNewMessage: UserNotificationSettingValue | ||
27 | |||
28 | newPeerTubeVersion: UserNotificationSettingValue | ||
29 | newPluginVersion: UserNotificationSettingValue | ||
30 | |||
31 | myVideoStudioEditionFinished: UserNotificationSettingValue | ||
32 | } | ||
diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts deleted file mode 100644 index 294c921bd..000000000 --- a/shared/models/users/user-notification.model.ts +++ /dev/null | |||
@@ -1,138 +0,0 @@ | |||
1 | import { FollowState } from '../actors' | ||
2 | import { AbuseState } from '../moderation' | ||
3 | import { PluginType } from '../plugins' | ||
4 | |||
5 | export const enum UserNotificationType { | ||
6 | NEW_VIDEO_FROM_SUBSCRIPTION = 1, | ||
7 | NEW_COMMENT_ON_MY_VIDEO = 2, | ||
8 | NEW_ABUSE_FOR_MODERATORS = 3, | ||
9 | |||
10 | BLACKLIST_ON_MY_VIDEO = 4, | ||
11 | UNBLACKLIST_ON_MY_VIDEO = 5, | ||
12 | |||
13 | MY_VIDEO_PUBLISHED = 6, | ||
14 | |||
15 | MY_VIDEO_IMPORT_SUCCESS = 7, | ||
16 | MY_VIDEO_IMPORT_ERROR = 8, | ||
17 | |||
18 | NEW_USER_REGISTRATION = 9, | ||
19 | NEW_FOLLOW = 10, | ||
20 | COMMENT_MENTION = 11, | ||
21 | |||
22 | VIDEO_AUTO_BLACKLIST_FOR_MODERATORS = 12, | ||
23 | |||
24 | NEW_INSTANCE_FOLLOWER = 13, | ||
25 | |||
26 | AUTO_INSTANCE_FOLLOWING = 14, | ||
27 | |||
28 | ABUSE_STATE_CHANGE = 15, | ||
29 | |||
30 | ABUSE_NEW_MESSAGE = 16, | ||
31 | |||
32 | NEW_PLUGIN_VERSION = 17, | ||
33 | NEW_PEERTUBE_VERSION = 18, | ||
34 | |||
35 | MY_VIDEO_STUDIO_EDITION_FINISHED = 19, | ||
36 | |||
37 | NEW_USER_REGISTRATION_REQUEST = 20 | ||
38 | } | ||
39 | |||
40 | export interface VideoInfo { | ||
41 | id: number | ||
42 | uuid: string | ||
43 | shortUUID: string | ||
44 | name: string | ||
45 | } | ||
46 | |||
47 | export interface AvatarInfo { | ||
48 | width: number | ||
49 | path: string | ||
50 | } | ||
51 | |||
52 | export interface ActorInfo { | ||
53 | id: number | ||
54 | displayName: string | ||
55 | name: string | ||
56 | host: string | ||
57 | |||
58 | avatars: AvatarInfo[] | ||
59 | avatar: AvatarInfo | ||
60 | } | ||
61 | |||
62 | export interface UserNotification { | ||
63 | id: number | ||
64 | type: UserNotificationType | ||
65 | read: boolean | ||
66 | |||
67 | video?: VideoInfo & { | ||
68 | channel: ActorInfo | ||
69 | } | ||
70 | |||
71 | videoImport?: { | ||
72 | id: number | ||
73 | video?: VideoInfo | ||
74 | torrentName?: string | ||
75 | magnetUri?: string | ||
76 | targetUrl?: string | ||
77 | } | ||
78 | |||
79 | comment?: { | ||
80 | id: number | ||
81 | threadId: number | ||
82 | account: ActorInfo | ||
83 | video: VideoInfo | ||
84 | } | ||
85 | |||
86 | abuse?: { | ||
87 | id: number | ||
88 | state: AbuseState | ||
89 | |||
90 | video?: VideoInfo | ||
91 | |||
92 | comment?: { | ||
93 | threadId: number | ||
94 | |||
95 | video: VideoInfo | ||
96 | } | ||
97 | |||
98 | account?: ActorInfo | ||
99 | } | ||
100 | |||
101 | videoBlacklist?: { | ||
102 | id: number | ||
103 | video: VideoInfo | ||
104 | } | ||
105 | |||
106 | account?: ActorInfo | ||
107 | |||
108 | actorFollow?: { | ||
109 | id: number | ||
110 | follower: ActorInfo | ||
111 | state: FollowState | ||
112 | |||
113 | following: { | ||
114 | type: 'account' | 'channel' | 'instance' | ||
115 | name: string | ||
116 | displayName: string | ||
117 | host: string | ||
118 | } | ||
119 | } | ||
120 | |||
121 | plugin?: { | ||
122 | name: string | ||
123 | type: PluginType | ||
124 | latestVersion: string | ||
125 | } | ||
126 | |||
127 | peertube?: { | ||
128 | latestVersion: string | ||
129 | } | ||
130 | |||
131 | registration?: { | ||
132 | id: number | ||
133 | username: string | ||
134 | } | ||
135 | |||
136 | createdAt: string | ||
137 | updatedAt: string | ||
138 | } | ||
diff --git a/shared/models/users/user-refresh-token.model.ts b/shared/models/users/user-refresh-token.model.ts deleted file mode 100644 index f528dd961..000000000 --- a/shared/models/users/user-refresh-token.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface UserRefreshToken { | ||
2 | access_token: string | ||
3 | refresh_token: string | ||
4 | } | ||
diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.ts deleted file mode 100644 index a5a770b75..000000000 --- a/shared/models/users/user-right.enum.ts +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | export const enum UserRight { | ||
2 | ALL = 0, | ||
3 | |||
4 | MANAGE_USERS = 1, | ||
5 | |||
6 | MANAGE_SERVER_FOLLOW = 2, | ||
7 | |||
8 | MANAGE_LOGS = 3, | ||
9 | |||
10 | MANAGE_DEBUG = 4, | ||
11 | |||
12 | MANAGE_SERVER_REDUNDANCY = 5, | ||
13 | |||
14 | MANAGE_ABUSES = 6, | ||
15 | |||
16 | MANAGE_JOBS = 7, | ||
17 | |||
18 | MANAGE_CONFIGURATION = 8, | ||
19 | MANAGE_INSTANCE_CUSTOM_PAGE = 9, | ||
20 | |||
21 | MANAGE_ACCOUNTS_BLOCKLIST = 10, | ||
22 | MANAGE_SERVERS_BLOCKLIST = 11, | ||
23 | |||
24 | MANAGE_VIDEO_BLACKLIST = 12, | ||
25 | MANAGE_ANY_VIDEO_CHANNEL = 13, | ||
26 | |||
27 | REMOVE_ANY_VIDEO = 14, | ||
28 | REMOVE_ANY_VIDEO_PLAYLIST = 15, | ||
29 | REMOVE_ANY_VIDEO_COMMENT = 16, | ||
30 | |||
31 | UPDATE_ANY_VIDEO = 17, | ||
32 | UPDATE_ANY_VIDEO_PLAYLIST = 18, | ||
33 | |||
34 | GET_ANY_LIVE = 19, | ||
35 | SEE_ALL_VIDEOS = 20, | ||
36 | SEE_ALL_COMMENTS = 21, | ||
37 | CHANGE_VIDEO_OWNERSHIP = 22, | ||
38 | |||
39 | MANAGE_PLUGINS = 23, | ||
40 | |||
41 | MANAGE_VIDEOS_REDUNDANCIES = 24, | ||
42 | |||
43 | MANAGE_VIDEO_FILES = 25, | ||
44 | RUN_VIDEO_TRANSCODING = 26, | ||
45 | |||
46 | MANAGE_VIDEO_IMPORTS = 27, | ||
47 | |||
48 | MANAGE_REGISTRATIONS = 28, | ||
49 | |||
50 | MANAGE_RUNNERS = 29 | ||
51 | } | ||
diff --git a/shared/models/users/user-role.ts b/shared/models/users/user-role.ts deleted file mode 100644 index 687a2aa0d..000000000 --- a/shared/models/users/user-role.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | // Keep the order | ||
2 | export const enum UserRole { | ||
3 | ADMINISTRATOR = 0, | ||
4 | MODERATOR = 1, | ||
5 | USER = 2 | ||
6 | } | ||
diff --git a/shared/models/users/user-scoped-token.ts b/shared/models/users/user-scoped-token.ts deleted file mode 100644 index f9d9b0a8b..000000000 --- a/shared/models/users/user-scoped-token.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export type ScopedTokenType = 'feedToken' | ||
2 | |||
3 | export type ScopedToken = { | ||
4 | feedToken: string | ||
5 | } | ||
diff --git a/shared/models/users/user-update-me.model.ts b/shared/models/users/user-update-me.model.ts deleted file mode 100644 index c1d5ffba4..000000000 --- a/shared/models/users/user-update-me.model.ts +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | import { NSFWPolicyType } from '../videos/nsfw-policy.type' | ||
2 | |||
3 | export interface UserUpdateMe { | ||
4 | displayName?: string | ||
5 | description?: string | ||
6 | nsfwPolicy?: NSFWPolicyType | ||
7 | |||
8 | p2pEnabled?: boolean | ||
9 | |||
10 | autoPlayVideo?: boolean | ||
11 | autoPlayNextVideo?: boolean | ||
12 | autoPlayNextVideoPlaylist?: boolean | ||
13 | videosHistoryEnabled?: boolean | ||
14 | videoLanguages?: string[] | ||
15 | |||
16 | email?: string | ||
17 | emailPublic?: boolean | ||
18 | currentPassword?: string | ||
19 | password?: string | ||
20 | |||
21 | theme?: string | ||
22 | |||
23 | noInstanceConfigWarningModal?: boolean | ||
24 | noWelcomeModal?: boolean | ||
25 | noAccountSetupWarningModal?: boolean | ||
26 | } | ||
diff --git a/shared/models/users/user-update.model.ts b/shared/models/users/user-update.model.ts deleted file mode 100644 index 158738545..000000000 --- a/shared/models/users/user-update.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { UserRole } from './user-role' | ||
2 | import { UserAdminFlag } from './user-flag.model' | ||
3 | |||
4 | export interface UserUpdate { | ||
5 | password?: string | ||
6 | email?: string | ||
7 | emailVerified?: boolean | ||
8 | videoQuota?: number | ||
9 | videoQuotaDaily?: number | ||
10 | role?: UserRole | ||
11 | adminFlags?: UserAdminFlag | ||
12 | pluginAuth?: string | ||
13 | } | ||
diff --git a/shared/models/users/user-video-quota.model.ts b/shared/models/users/user-video-quota.model.ts deleted file mode 100644 index a24871d71..000000000 --- a/shared/models/users/user-video-quota.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface UserVideoQuota { | ||
2 | videoQuotaUsed: number | ||
3 | videoQuotaUsedDaily: number | ||
4 | } | ||
diff --git a/shared/models/users/user.model.ts b/shared/models/users/user.model.ts deleted file mode 100644 index 9de4118b4..000000000 --- a/shared/models/users/user.model.ts +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | import { Account } from '../actors' | ||
2 | import { VideoChannel } from '../videos/channel/video-channel.model' | ||
3 | import { UserRole } from './user-role' | ||
4 | import { NSFWPolicyType } from '../videos/nsfw-policy.type' | ||
5 | import { UserNotificationSetting } from './user-notification-setting.model' | ||
6 | import { UserAdminFlag } from './user-flag.model' | ||
7 | import { VideoPlaylistType } from '../videos/playlist/video-playlist-type.model' | ||
8 | |||
9 | export interface User { | ||
10 | id: number | ||
11 | username: string | ||
12 | email: string | ||
13 | pendingEmail: string | null | ||
14 | |||
15 | emailVerified: boolean | ||
16 | emailPublic: boolean | ||
17 | nsfwPolicy: NSFWPolicyType | ||
18 | |||
19 | adminFlags?: UserAdminFlag | ||
20 | |||
21 | autoPlayVideo: boolean | ||
22 | autoPlayNextVideo: boolean | ||
23 | autoPlayNextVideoPlaylist: boolean | ||
24 | |||
25 | p2pEnabled: boolean | ||
26 | |||
27 | videosHistoryEnabled: boolean | ||
28 | videoLanguages: string[] | ||
29 | |||
30 | role: { | ||
31 | id: UserRole | ||
32 | label: string | ||
33 | } | ||
34 | |||
35 | videoQuota: number | ||
36 | videoQuotaDaily: number | ||
37 | videoQuotaUsed?: number | ||
38 | videoQuotaUsedDaily?: number | ||
39 | |||
40 | videosCount?: number | ||
41 | |||
42 | abusesCount?: number | ||
43 | abusesAcceptedCount?: number | ||
44 | abusesCreatedCount?: number | ||
45 | |||
46 | videoCommentsCount?: number | ||
47 | |||
48 | theme: string | ||
49 | |||
50 | account: Account | ||
51 | notificationSettings?: UserNotificationSetting | ||
52 | videoChannels?: VideoChannel[] | ||
53 | |||
54 | blocked: boolean | ||
55 | blockedReason?: string | ||
56 | |||
57 | noInstanceConfigWarningModal: boolean | ||
58 | noWelcomeModal: boolean | ||
59 | noAccountSetupWarningModal: boolean | ||
60 | |||
61 | createdAt: Date | ||
62 | |||
63 | pluginAuth: string | null | ||
64 | |||
65 | lastLoginDate: Date | null | ||
66 | |||
67 | twoFactorEnabled: boolean | ||
68 | } | ||
69 | |||
70 | export interface MyUserSpecialPlaylist { | ||
71 | id: number | ||
72 | name: string | ||
73 | type: VideoPlaylistType | ||
74 | } | ||
75 | |||
76 | export interface MyUser extends User { | ||
77 | specialPlaylists: MyUserSpecialPlaylist[] | ||
78 | } | ||
diff --git a/shared/models/videos/blacklist/index.ts b/shared/models/videos/blacklist/index.ts deleted file mode 100644 index 66082be34..000000000 --- a/shared/models/videos/blacklist/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './video-blacklist.model' | ||
2 | export * from './video-blacklist-create.model' | ||
3 | export * from './video-blacklist-update.model' | ||
diff --git a/shared/models/videos/blacklist/video-blacklist-create.model.ts b/shared/models/videos/blacklist/video-blacklist-create.model.ts deleted file mode 100644 index 6e7d36421..000000000 --- a/shared/models/videos/blacklist/video-blacklist-create.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface VideoBlacklistCreate { | ||
2 | reason?: string | ||
3 | unfederate?: boolean | ||
4 | } | ||
diff --git a/shared/models/videos/blacklist/video-blacklist-update.model.ts b/shared/models/videos/blacklist/video-blacklist-update.model.ts deleted file mode 100644 index 0a86cf7b0..000000000 --- a/shared/models/videos/blacklist/video-blacklist-update.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface VideoBlacklistUpdate { | ||
2 | reason?: string | ||
3 | } | ||
diff --git a/shared/models/videos/blacklist/video-blacklist.model.ts b/shared/models/videos/blacklist/video-blacklist.model.ts deleted file mode 100644 index 982a34592..000000000 --- a/shared/models/videos/blacklist/video-blacklist.model.ts +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | import { Video } from '../video.model' | ||
2 | |||
3 | export const enum VideoBlacklistType { | ||
4 | MANUAL = 1, | ||
5 | AUTO_BEFORE_PUBLISHED = 2 | ||
6 | } | ||
7 | |||
8 | export interface VideoBlacklist { | ||
9 | id: number | ||
10 | unfederated: boolean | ||
11 | reason?: string | ||
12 | type: VideoBlacklistType | ||
13 | |||
14 | video: Video | ||
15 | |||
16 | createdAt: Date | ||
17 | updatedAt: Date | ||
18 | } | ||
diff --git a/shared/models/videos/caption/index.ts b/shared/models/videos/caption/index.ts deleted file mode 100644 index 2a5ff512d..000000000 --- a/shared/models/videos/caption/index.ts +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | export * from './video-caption.model' | ||
2 | export * from './video-caption-update.model' | ||
diff --git a/shared/models/videos/caption/video-caption-update.model.ts b/shared/models/videos/caption/video-caption-update.model.ts deleted file mode 100644 index ff5728715..000000000 --- a/shared/models/videos/caption/video-caption-update.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface VideoCaptionUpdate { | ||
2 | language: string | ||
3 | captionfile: Blob | ||
4 | } | ||
diff --git a/shared/models/videos/caption/video-caption.model.ts b/shared/models/videos/caption/video-caption.model.ts deleted file mode 100644 index 6d5665006..000000000 --- a/shared/models/videos/caption/video-caption.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | import { VideoConstant } from '../video-constant.model' | ||
2 | |||
3 | export interface VideoCaption { | ||
4 | language: VideoConstant<string> | ||
5 | captionPath: string | ||
6 | updatedAt: string | ||
7 | } | ||
diff --git a/shared/models/videos/change-ownership/index.ts b/shared/models/videos/change-ownership/index.ts deleted file mode 100644 index a942fb2cd..000000000 --- a/shared/models/videos/change-ownership/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './video-change-ownership-accept.model' | ||
2 | export * from './video-change-ownership-create.model' | ||
3 | export * from './video-change-ownership.model' | ||
diff --git a/shared/models/videos/change-ownership/video-change-ownership-accept.model.ts b/shared/models/videos/change-ownership/video-change-ownership-accept.model.ts deleted file mode 100644 index f27247633..000000000 --- a/shared/models/videos/change-ownership/video-change-ownership-accept.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface VideoChangeOwnershipAccept { | ||
2 | channelId: number | ||
3 | } | ||
diff --git a/shared/models/videos/change-ownership/video-change-ownership-create.model.ts b/shared/models/videos/change-ownership/video-change-ownership-create.model.ts deleted file mode 100644 index 40fcca285..000000000 --- a/shared/models/videos/change-ownership/video-change-ownership-create.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface VideoChangeOwnershipCreate { | ||
2 | username: string | ||
3 | } | ||
diff --git a/shared/models/videos/change-ownership/video-change-ownership.model.ts b/shared/models/videos/change-ownership/video-change-ownership.model.ts deleted file mode 100644 index 3d31cad0a..000000000 --- a/shared/models/videos/change-ownership/video-change-ownership.model.ts +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | import { Account } from '../../actors' | ||
2 | import { Video } from '../video.model' | ||
3 | |||
4 | export interface VideoChangeOwnership { | ||
5 | id: number | ||
6 | status: VideoChangeOwnershipStatus | ||
7 | initiatorAccount: Account | ||
8 | nextOwnerAccount: Account | ||
9 | video: Video | ||
10 | createdAt: Date | ||
11 | } | ||
12 | |||
13 | export const enum VideoChangeOwnershipStatus { | ||
14 | WAITING = 'WAITING', | ||
15 | ACCEPTED = 'ACCEPTED', | ||
16 | REFUSED = 'REFUSED' | ||
17 | } | ||
diff --git a/shared/models/videos/channel-sync/index.ts b/shared/models/videos/channel-sync/index.ts deleted file mode 100644 index 7d25aaac3..000000000 --- a/shared/models/videos/channel-sync/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './video-channel-sync-state.enum' | ||
2 | export * from './video-channel-sync.model' | ||
3 | export * from './video-channel-sync-create.model' | ||
diff --git a/shared/models/videos/channel-sync/video-channel-sync-create.model.ts b/shared/models/videos/channel-sync/video-channel-sync-create.model.ts deleted file mode 100644 index 753a8ee4c..000000000 --- a/shared/models/videos/channel-sync/video-channel-sync-create.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface VideoChannelSyncCreate { | ||
2 | externalChannelUrl: string | ||
3 | videoChannelId: number | ||
4 | } | ||
diff --git a/shared/models/videos/channel-sync/video-channel-sync-state.enum.ts b/shared/models/videos/channel-sync/video-channel-sync-state.enum.ts deleted file mode 100644 index 3e9f5ddc2..000000000 --- a/shared/models/videos/channel-sync/video-channel-sync-state.enum.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export const enum VideoChannelSyncState { | ||
2 | WAITING_FIRST_RUN = 1, | ||
3 | PROCESSING = 2, | ||
4 | SYNCED = 3, | ||
5 | FAILED = 4 | ||
6 | } | ||
diff --git a/shared/models/videos/channel-sync/video-channel-sync.model.ts b/shared/models/videos/channel-sync/video-channel-sync.model.ts deleted file mode 100644 index 73ac0615b..000000000 --- a/shared/models/videos/channel-sync/video-channel-sync.model.ts +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | import { VideoChannelSummary } from '../channel/video-channel.model' | ||
2 | import { VideoConstant } from '../video-constant.model' | ||
3 | import { VideoChannelSyncState } from './video-channel-sync-state.enum' | ||
4 | |||
5 | export interface VideoChannelSync { | ||
6 | id: number | ||
7 | |||
8 | externalChannelUrl: string | ||
9 | |||
10 | createdAt: string | ||
11 | channel: VideoChannelSummary | ||
12 | state: VideoConstant<VideoChannelSyncState> | ||
13 | lastSyncAt: string | ||
14 | } | ||
diff --git a/shared/models/videos/channel/index.ts b/shared/models/videos/channel/index.ts deleted file mode 100644 index 6cdabffbd..000000000 --- a/shared/models/videos/channel/index.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export * from './video-channel-create-result.model' | ||
2 | export * from './video-channel-create.model' | ||
3 | export * from './video-channel-update.model' | ||
4 | export * from './video-channel.model' | ||
diff --git a/shared/models/videos/channel/video-channel-create-result.model.ts b/shared/models/videos/channel/video-channel-create-result.model.ts deleted file mode 100644 index e3d7aeb4c..000000000 --- a/shared/models/videos/channel/video-channel-create-result.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface VideoChannelCreateResult { | ||
2 | id: number | ||
3 | } | ||
diff --git a/shared/models/videos/channel/video-channel-create.model.ts b/shared/models/videos/channel/video-channel-create.model.ts deleted file mode 100644 index da8ce620c..000000000 --- a/shared/models/videos/channel/video-channel-create.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export interface VideoChannelCreate { | ||
2 | name: string | ||
3 | displayName: string | ||
4 | description?: string | ||
5 | support?: string | ||
6 | } | ||
diff --git a/shared/models/videos/channel/video-channel-update.model.ts b/shared/models/videos/channel/video-channel-update.model.ts deleted file mode 100644 index 8dde9188b..000000000 --- a/shared/models/videos/channel/video-channel-update.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | export interface VideoChannelUpdate { | ||
2 | displayName?: string | ||
3 | description?: string | ||
4 | support?: string | ||
5 | |||
6 | bulkVideosSupportUpdate?: boolean | ||
7 | } | ||
diff --git a/shared/models/videos/channel/video-channel.model.ts b/shared/models/videos/channel/video-channel.model.ts deleted file mode 100644 index ce5fc0e8d..000000000 --- a/shared/models/videos/channel/video-channel.model.ts +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | import { Account, ActorImage } from '../../actors' | ||
2 | import { Actor } from '../../actors/actor.model' | ||
3 | |||
4 | export type ViewsPerDate = { | ||
5 | date: Date | ||
6 | views: number | ||
7 | } | ||
8 | |||
9 | export interface VideoChannel extends Actor { | ||
10 | displayName: string | ||
11 | description: string | ||
12 | support: string | ||
13 | isLocal: boolean | ||
14 | |||
15 | updatedAt: Date | string | ||
16 | |||
17 | ownerAccount?: Account | ||
18 | |||
19 | videosCount?: number | ||
20 | viewsPerDay?: ViewsPerDate[] // chronologically ordered | ||
21 | totalViews?: number | ||
22 | |||
23 | banners: ActorImage[] | ||
24 | } | ||
25 | |||
26 | export interface VideoChannelSummary { | ||
27 | id: number | ||
28 | name: string | ||
29 | displayName: string | ||
30 | url: string | ||
31 | host: string | ||
32 | |||
33 | avatars: ActorImage[] | ||
34 | } | ||
diff --git a/shared/models/videos/comment/index.ts b/shared/models/videos/comment/index.ts deleted file mode 100644 index 80c6c0724..000000000 --- a/shared/models/videos/comment/index.ts +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | export * from './video-comment-create.model' | ||
2 | export * from './video-comment.model' | ||
diff --git a/shared/models/videos/comment/video-comment-create.model.ts b/shared/models/videos/comment/video-comment-create.model.ts deleted file mode 100644 index 1f0135405..000000000 --- a/shared/models/videos/comment/video-comment-create.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface VideoCommentCreate { | ||
2 | text: string | ||
3 | } | ||
diff --git a/shared/models/videos/comment/video-comment.model.ts b/shared/models/videos/comment/video-comment.model.ts deleted file mode 100644 index 737cfe098..000000000 --- a/shared/models/videos/comment/video-comment.model.ts +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | import { ResultList } from '../../common' | ||
2 | import { Account } from '../../actors' | ||
3 | |||
4 | export interface VideoComment { | ||
5 | id: number | ||
6 | url: string | ||
7 | text: string | ||
8 | threadId: number | ||
9 | inReplyToCommentId: number | ||
10 | videoId: number | ||
11 | createdAt: Date | string | ||
12 | updatedAt: Date | string | ||
13 | deletedAt: Date | string | ||
14 | isDeleted: boolean | ||
15 | totalRepliesFromVideoAuthor: number | ||
16 | totalReplies: number | ||
17 | account: Account | ||
18 | } | ||
19 | |||
20 | export interface VideoCommentAdmin { | ||
21 | id: number | ||
22 | url: string | ||
23 | text: string | ||
24 | |||
25 | threadId: number | ||
26 | inReplyToCommentId: number | ||
27 | |||
28 | createdAt: Date | string | ||
29 | updatedAt: Date | string | ||
30 | |||
31 | account: Account | ||
32 | |||
33 | video: { | ||
34 | id: number | ||
35 | uuid: string | ||
36 | name: string | ||
37 | } | ||
38 | } | ||
39 | |||
40 | export type VideoCommentThreads = ResultList<VideoComment> & { totalNotDeletedComments: number } | ||
41 | |||
42 | export interface VideoCommentThreadTree { | ||
43 | comment: VideoComment | ||
44 | children: VideoCommentThreadTree[] | ||
45 | } | ||
diff --git a/shared/models/videos/file/index.ts b/shared/models/videos/file/index.ts deleted file mode 100644 index 78a784a3c..000000000 --- a/shared/models/videos/file/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './video-file-metadata.model' | ||
2 | export * from './video-file.model' | ||
3 | export * from './video-resolution.enum' | ||
diff --git a/shared/models/videos/file/video-file-metadata.model.ts b/shared/models/videos/file/video-file-metadata.model.ts deleted file mode 100644 index 8f527c0a7..000000000 --- a/shared/models/videos/file/video-file-metadata.model.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | export class VideoFileMetadata { | ||
2 | streams: { [x: string]: any, [x: number]: any }[] | ||
3 | format: { [x: string]: any, [x: number]: any } | ||
4 | chapters: any[] | ||
5 | |||
6 | constructor (hash: { chapters: any[], format: any, streams: any[] }) { | ||
7 | this.chapters = hash.chapters | ||
8 | this.format = hash.format | ||
9 | this.streams = hash.streams | ||
10 | |||
11 | delete this.format.filename | ||
12 | } | ||
13 | } | ||
diff --git a/shared/models/videos/file/video-file.model.ts b/shared/models/videos/file/video-file.model.ts deleted file mode 100644 index 2bbff48eb..000000000 --- a/shared/models/videos/file/video-file.model.ts +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | import { VideoConstant } from '../video-constant.model' | ||
2 | import { VideoFileMetadata } from './video-file-metadata.model' | ||
3 | import { VideoResolution } from './video-resolution.enum' | ||
4 | |||
5 | export interface VideoFile { | ||
6 | id: number | ||
7 | |||
8 | resolution: VideoConstant<VideoResolution> | ||
9 | size: number // Bytes | ||
10 | |||
11 | torrentUrl: string | ||
12 | torrentDownloadUrl: string | ||
13 | |||
14 | fileUrl: string | ||
15 | fileDownloadUrl: string | ||
16 | |||
17 | fps: number | ||
18 | |||
19 | metadata?: VideoFileMetadata | ||
20 | metadataUrl?: string | ||
21 | |||
22 | magnetUri: string | null | ||
23 | } | ||
diff --git a/shared/models/videos/file/video-resolution.enum.ts b/shared/models/videos/file/video-resolution.enum.ts deleted file mode 100644 index 5b48ad353..000000000 --- a/shared/models/videos/file/video-resolution.enum.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | export const enum VideoResolution { | ||
2 | H_NOVIDEO = 0, | ||
3 | H_144P = 144, | ||
4 | H_240P = 240, | ||
5 | H_360P = 360, | ||
6 | H_480P = 480, | ||
7 | H_720P = 720, | ||
8 | H_1080P = 1080, | ||
9 | H_1440P = 1440, | ||
10 | H_4K = 2160 | ||
11 | } | ||
diff --git a/shared/models/videos/import/index.ts b/shared/models/videos/import/index.ts deleted file mode 100644 index b38a67b5f..000000000 --- a/shared/models/videos/import/index.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export * from './video-import-create.model' | ||
2 | export * from './video-import-state.enum' | ||
3 | export * from './video-import.model' | ||
4 | export * from './videos-import-in-channel-create.model' | ||
diff --git a/shared/models/videos/import/video-import-create.model.ts b/shared/models/videos/import/video-import-create.model.ts deleted file mode 100644 index 425477389..000000000 --- a/shared/models/videos/import/video-import-create.model.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | import { VideoUpdate } from '../video-update.model' | ||
2 | |||
3 | export interface VideoImportCreate extends VideoUpdate { | ||
4 | targetUrl?: string | ||
5 | magnetUri?: string | ||
6 | torrentfile?: Blob | ||
7 | |||
8 | channelId: number // Required | ||
9 | } | ||
diff --git a/shared/models/videos/import/video-import-state.enum.ts b/shared/models/videos/import/video-import-state.enum.ts deleted file mode 100644 index ff5c6beff..000000000 --- a/shared/models/videos/import/video-import-state.enum.ts +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | export const enum VideoImportState { | ||
2 | PENDING = 1, | ||
3 | SUCCESS = 2, | ||
4 | FAILED = 3, | ||
5 | REJECTED = 4, | ||
6 | CANCELLED = 5, | ||
7 | PROCESSING = 6 | ||
8 | } | ||
diff --git a/shared/models/videos/import/video-import.model.ts b/shared/models/videos/import/video-import.model.ts deleted file mode 100644 index 6aed7a91a..000000000 --- a/shared/models/videos/import/video-import.model.ts +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | import { Video } from '../video.model' | ||
2 | import { VideoConstant } from '../video-constant.model' | ||
3 | import { VideoImportState } from './video-import-state.enum' | ||
4 | |||
5 | export interface VideoImport { | ||
6 | id: number | ||
7 | |||
8 | targetUrl: string | ||
9 | magnetUri: string | ||
10 | torrentName: string | ||
11 | |||
12 | createdAt: string | ||
13 | updatedAt: string | ||
14 | originallyPublishedAt?: string | ||
15 | state: VideoConstant<VideoImportState> | ||
16 | error?: string | ||
17 | |||
18 | video?: Video & { tags: string[] } | ||
19 | |||
20 | videoChannelSync?: { | ||
21 | id: number | ||
22 | externalChannelUrl: string | ||
23 | } | ||
24 | } | ||
diff --git a/shared/models/videos/import/videos-import-in-channel-create.model.ts b/shared/models/videos/import/videos-import-in-channel-create.model.ts deleted file mode 100644 index fbfef63f8..000000000 --- a/shared/models/videos/import/videos-import-in-channel-create.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface VideosImportInChannelCreate { | ||
2 | externalChannelUrl: string | ||
3 | videoChannelSyncId?: number | ||
4 | } | ||
diff --git a/shared/models/videos/index.ts b/shared/models/videos/index.ts deleted file mode 100644 index f8f1ce081..000000000 --- a/shared/models/videos/index.ts +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | export * from './blacklist' | ||
2 | export * from './caption' | ||
3 | export * from './change-ownership' | ||
4 | export * from './channel' | ||
5 | export * from './comment' | ||
6 | export * from './studio' | ||
7 | export * from './live' | ||
8 | export * from './file' | ||
9 | export * from './import' | ||
10 | export * from './playlist' | ||
11 | export * from './rate' | ||
12 | export * from './stats' | ||
13 | export * from './transcoding' | ||
14 | export * from './channel-sync' | ||
15 | |||
16 | export * from './nsfw-policy.type' | ||
17 | |||
18 | export * from './storyboard.model' | ||
19 | export * from './thumbnail.type' | ||
20 | |||
21 | export * from './video-constant.model' | ||
22 | export * from './video-create.model' | ||
23 | |||
24 | export * from './video-privacy.enum' | ||
25 | export * from './video-include.enum' | ||
26 | export * from './video-rate.type' | ||
27 | |||
28 | export * from './video-schedule-update.model' | ||
29 | export * from './video-sort-field.type' | ||
30 | export * from './video-state.enum' | ||
31 | export * from './video-storage.enum' | ||
32 | |||
33 | export * from './video-streaming-playlist.model' | ||
34 | export * from './video-streaming-playlist.type' | ||
35 | |||
36 | export * from './video-token.model' | ||
37 | |||
38 | export * from './video-update.model' | ||
39 | export * from './video-view.model' | ||
40 | export * from './video.model' | ||
41 | export * from './video-create-result.model' | ||
42 | export * from './video-password.model' | ||
diff --git a/shared/models/videos/live/index.ts b/shared/models/videos/live/index.ts deleted file mode 100644 index 07b59fe2c..000000000 --- a/shared/models/videos/live/index.ts +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | export * from './live-video-create.model' | ||
2 | export * from './live-video-error.enum' | ||
3 | export * from './live-video-event-payload.model' | ||
4 | export * from './live-video-event.type' | ||
5 | export * from './live-video-latency-mode.enum' | ||
6 | export * from './live-video-session.model' | ||
7 | export * from './live-video-update.model' | ||
8 | export * from './live-video.model' | ||
diff --git a/shared/models/videos/live/live-video-create.model.ts b/shared/models/videos/live/live-video-create.model.ts deleted file mode 100644 index f8ae9e5a9..000000000 --- a/shared/models/videos/live/live-video-create.model.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | import { VideoCreate } from '../video-create.model' | ||
2 | import { VideoPrivacy } from '../video-privacy.enum' | ||
3 | import { LiveVideoLatencyMode } from './live-video-latency-mode.enum' | ||
4 | |||
5 | export interface LiveVideoCreate extends VideoCreate { | ||
6 | permanentLive?: boolean | ||
7 | latencyMode?: LiveVideoLatencyMode | ||
8 | |||
9 | saveReplay?: boolean | ||
10 | replaySettings?: { privacy: VideoPrivacy } | ||
11 | } | ||
diff --git a/shared/models/videos/live/live-video-error.enum.ts b/shared/models/videos/live/live-video-error.enum.ts deleted file mode 100644 index a26453505..000000000 --- a/shared/models/videos/live/live-video-error.enum.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | export const enum LiveVideoError { | ||
2 | BAD_SOCKET_HEALTH = 1, | ||
3 | DURATION_EXCEEDED = 2, | ||
4 | QUOTA_EXCEEDED = 3, | ||
5 | FFMPEG_ERROR = 4, | ||
6 | BLACKLISTED = 5, | ||
7 | RUNNER_JOB_ERROR = 6, | ||
8 | RUNNER_JOB_CANCEL = 7 | ||
9 | } | ||
diff --git a/shared/models/videos/live/live-video-event-payload.model.ts b/shared/models/videos/live/live-video-event-payload.model.ts deleted file mode 100644 index 646856ac3..000000000 --- a/shared/models/videos/live/live-video-event-payload.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | import { VideoState } from '../video-state.enum' | ||
2 | |||
3 | export interface LiveVideoEventPayload { | ||
4 | state?: VideoState | ||
5 | |||
6 | viewers?: number | ||
7 | } | ||
diff --git a/shared/models/videos/live/live-video-event.type.ts b/shared/models/videos/live/live-video-event.type.ts deleted file mode 100644 index 50f794561..000000000 --- a/shared/models/videos/live/live-video-event.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type LiveVideoEventType = 'state-change' | 'views-change' | ||
diff --git a/shared/models/videos/live/live-video-latency-mode.enum.ts b/shared/models/videos/live/live-video-latency-mode.enum.ts deleted file mode 100644 index 4285e1d41..000000000 --- a/shared/models/videos/live/live-video-latency-mode.enum.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export const enum LiveVideoLatencyMode { | ||
2 | DEFAULT = 1, | ||
3 | HIGH_LATENCY = 2, | ||
4 | SMALL_LATENCY = 3 | ||
5 | } | ||
diff --git a/shared/models/videos/live/live-video-session.model.ts b/shared/models/videos/live/live-video-session.model.ts deleted file mode 100644 index 888c20a8a..000000000 --- a/shared/models/videos/live/live-video-session.model.ts +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | import { VideoPrivacy } from '../video-privacy.enum' | ||
2 | import { LiveVideoError } from './live-video-error.enum' | ||
3 | |||
4 | export interface LiveVideoSession { | ||
5 | id: number | ||
6 | |||
7 | startDate: string | ||
8 | endDate: string | ||
9 | |||
10 | error: LiveVideoError | ||
11 | |||
12 | saveReplay: boolean | ||
13 | endingProcessed: boolean | ||
14 | |||
15 | replaySettings?: { privacy: VideoPrivacy } | ||
16 | |||
17 | replayVideo: { | ||
18 | id: number | ||
19 | uuid: string | ||
20 | shortUUID: string | ||
21 | } | ||
22 | } | ||
diff --git a/shared/models/videos/live/live-video-update.model.ts b/shared/models/videos/live/live-video-update.model.ts deleted file mode 100644 index d6aa6fb37..000000000 --- a/shared/models/videos/live/live-video-update.model.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | import { VideoPrivacy } from '../video-privacy.enum' | ||
2 | import { LiveVideoLatencyMode } from './live-video-latency-mode.enum' | ||
3 | |||
4 | export interface LiveVideoUpdate { | ||
5 | permanentLive?: boolean | ||
6 | saveReplay?: boolean | ||
7 | replaySettings?: { privacy: VideoPrivacy } | ||
8 | latencyMode?: LiveVideoLatencyMode | ||
9 | } | ||
diff --git a/shared/models/videos/live/live-video.model.ts b/shared/models/videos/live/live-video.model.ts deleted file mode 100644 index fd8454123..000000000 --- a/shared/models/videos/live/live-video.model.ts +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | import { VideoPrivacy } from '../video-privacy.enum' | ||
2 | import { LiveVideoLatencyMode } from './live-video-latency-mode.enum' | ||
3 | |||
4 | export interface LiveVideo { | ||
5 | // If owner | ||
6 | rtmpUrl?: string | ||
7 | rtmpsUrl?: string | ||
8 | streamKey?: string | ||
9 | |||
10 | saveReplay: boolean | ||
11 | replaySettings?: { privacy: VideoPrivacy } | ||
12 | permanentLive: boolean | ||
13 | latencyMode: LiveVideoLatencyMode | ||
14 | } | ||
diff --git a/shared/models/videos/nsfw-policy.type.ts b/shared/models/videos/nsfw-policy.type.ts deleted file mode 100644 index dc0032a14..000000000 --- a/shared/models/videos/nsfw-policy.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type NSFWPolicyType = 'do_not_list' | 'blur' | 'display' | ||
diff --git a/shared/models/videos/playlist/index.ts b/shared/models/videos/playlist/index.ts deleted file mode 100644 index a9e8ce496..000000000 --- a/shared/models/videos/playlist/index.ts +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | export * from './video-exist-in-playlist.model' | ||
2 | export * from './video-playlist-create-result.model' | ||
3 | export * from './video-playlist-create.model' | ||
4 | export * from './video-playlist-element-create-result.model' | ||
5 | export * from './video-playlist-element-create.model' | ||
6 | export * from './video-playlist-element-update.model' | ||
7 | export * from './video-playlist-element.model' | ||
8 | export * from './video-playlist-privacy.model' | ||
9 | export * from './video-playlist-reorder.model' | ||
10 | export * from './video-playlist-type.model' | ||
11 | export * from './video-playlist-update.model' | ||
12 | export * from './video-playlist.model' | ||
diff --git a/shared/models/videos/playlist/video-exist-in-playlist.model.ts b/shared/models/videos/playlist/video-exist-in-playlist.model.ts deleted file mode 100644 index 6d06c0f4d..000000000 --- a/shared/models/videos/playlist/video-exist-in-playlist.model.ts +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | export type VideosExistInPlaylists = { | ||
2 | [videoId: number]: VideoExistInPlaylist[] | ||
3 | } | ||
4 | export type CachedVideosExistInPlaylists = { | ||
5 | [videoId: number]: CachedVideoExistInPlaylist[] | ||
6 | } | ||
7 | |||
8 | export type CachedVideoExistInPlaylist = { | ||
9 | playlistElementId: number | ||
10 | playlistId: number | ||
11 | startTimestamp?: number | ||
12 | stopTimestamp?: number | ||
13 | } | ||
14 | |||
15 | export type VideoExistInPlaylist = CachedVideoExistInPlaylist & { | ||
16 | playlistDisplayName: string | ||
17 | playlistShortUUID: string | ||
18 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-create-result.model.ts b/shared/models/videos/playlist/video-playlist-create-result.model.ts deleted file mode 100644 index cd9b170ae..000000000 --- a/shared/models/videos/playlist/video-playlist-create-result.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface VideoPlaylistCreateResult { | ||
2 | id: number | ||
3 | uuid: string | ||
4 | shortUUID: string | ||
5 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-create.model.ts b/shared/models/videos/playlist/video-playlist-create.model.ts deleted file mode 100644 index 67a33fa35..000000000 --- a/shared/models/videos/playlist/video-playlist-create.model.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | import { VideoPlaylistPrivacy } from './video-playlist-privacy.model' | ||
2 | |||
3 | export interface VideoPlaylistCreate { | ||
4 | displayName: string | ||
5 | privacy: VideoPlaylistPrivacy | ||
6 | |||
7 | description?: string | ||
8 | videoChannelId?: number | ||
9 | |||
10 | thumbnailfile?: any | ||
11 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-element-create-result.model.ts b/shared/models/videos/playlist/video-playlist-element-create-result.model.ts deleted file mode 100644 index dc475e7d8..000000000 --- a/shared/models/videos/playlist/video-playlist-element-create-result.model.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export interface VideoPlaylistElementCreateResult { | ||
2 | id: number | ||
3 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-element-create.model.ts b/shared/models/videos/playlist/video-playlist-element-create.model.ts deleted file mode 100644 index c31702892..000000000 --- a/shared/models/videos/playlist/video-playlist-element-create.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export interface VideoPlaylistElementCreate { | ||
2 | videoId: number | ||
3 | |||
4 | startTimestamp?: number | ||
5 | stopTimestamp?: number | ||
6 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-element-update.model.ts b/shared/models/videos/playlist/video-playlist-element-update.model.ts deleted file mode 100644 index 15a30fbdc..000000000 --- a/shared/models/videos/playlist/video-playlist-element-update.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface VideoPlaylistElementUpdate { | ||
2 | startTimestamp?: number | ||
3 | stopTimestamp?: number | ||
4 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-element.model.ts b/shared/models/videos/playlist/video-playlist-element.model.ts deleted file mode 100644 index df9e3b5cf..000000000 --- a/shared/models/videos/playlist/video-playlist-element.model.ts +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | import { Video } from '../video.model' | ||
2 | |||
3 | export const enum VideoPlaylistElementType { | ||
4 | REGULAR = 0, | ||
5 | DELETED = 1, | ||
6 | PRIVATE = 2, | ||
7 | UNAVAILABLE = 3 // Blacklisted, blocked by the user/instance, NSFW... | ||
8 | } | ||
9 | |||
10 | export interface VideoPlaylistElement { | ||
11 | id: number | ||
12 | position: number | ||
13 | startTimestamp: number | ||
14 | stopTimestamp: number | ||
15 | |||
16 | type: VideoPlaylistElementType | ||
17 | |||
18 | video?: Video | ||
19 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-privacy.model.ts b/shared/models/videos/playlist/video-playlist-privacy.model.ts deleted file mode 100644 index 480e1f104..000000000 --- a/shared/models/videos/playlist/video-playlist-privacy.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export const enum VideoPlaylistPrivacy { | ||
2 | PUBLIC = 1, | ||
3 | UNLISTED = 2, | ||
4 | PRIVATE = 3 | ||
5 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-reorder.model.ts b/shared/models/videos/playlist/video-playlist-reorder.model.ts deleted file mode 100644 index 63ec714c5..000000000 --- a/shared/models/videos/playlist/video-playlist-reorder.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface VideoPlaylistReorder { | ||
2 | startPosition: number | ||
3 | insertAfterPosition: number | ||
4 | reorderLength?: number | ||
5 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-type.model.ts b/shared/models/videos/playlist/video-playlist-type.model.ts deleted file mode 100644 index 7f51a6354..000000000 --- a/shared/models/videos/playlist/video-playlist-type.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export const enum VideoPlaylistType { | ||
2 | REGULAR = 1, | ||
3 | WATCH_LATER = 2 | ||
4 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist-update.model.ts b/shared/models/videos/playlist/video-playlist-update.model.ts deleted file mode 100644 index a6a3f74d9..000000000 --- a/shared/models/videos/playlist/video-playlist-update.model.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | import { VideoPlaylistPrivacy } from './video-playlist-privacy.model' | ||
2 | |||
3 | export interface VideoPlaylistUpdate { | ||
4 | displayName?: string | ||
5 | privacy?: VideoPlaylistPrivacy | ||
6 | |||
7 | description?: string | ||
8 | videoChannelId?: number | ||
9 | thumbnailfile?: any | ||
10 | } | ||
diff --git a/shared/models/videos/playlist/video-playlist.model.ts b/shared/models/videos/playlist/video-playlist.model.ts deleted file mode 100644 index b8a9955d9..000000000 --- a/shared/models/videos/playlist/video-playlist.model.ts +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | import { AccountSummary } from '../../actors/index' | ||
2 | import { VideoChannelSummary, VideoConstant } from '..' | ||
3 | import { VideoPlaylistPrivacy } from './video-playlist-privacy.model' | ||
4 | import { VideoPlaylistType } from './video-playlist-type.model' | ||
5 | |||
6 | export interface VideoPlaylist { | ||
7 | id: number | ||
8 | uuid: string | ||
9 | shortUUID: string | ||
10 | |||
11 | isLocal: boolean | ||
12 | |||
13 | url: string | ||
14 | |||
15 | displayName: string | ||
16 | description: string | ||
17 | privacy: VideoConstant<VideoPlaylistPrivacy> | ||
18 | |||
19 | thumbnailPath: string | ||
20 | thumbnailUrl?: string | ||
21 | |||
22 | videosLength: number | ||
23 | |||
24 | type: VideoConstant<VideoPlaylistType> | ||
25 | |||
26 | embedPath: string | ||
27 | embedUrl?: string | ||
28 | |||
29 | createdAt: Date | string | ||
30 | updatedAt: Date | string | ||
31 | |||
32 | ownerAccount: AccountSummary | ||
33 | videoChannel?: VideoChannelSummary | ||
34 | } | ||
diff --git a/shared/models/videos/rate/account-video-rate.model.ts b/shared/models/videos/rate/account-video-rate.model.ts deleted file mode 100644 index e789367dc..000000000 --- a/shared/models/videos/rate/account-video-rate.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | import { UserVideoRateType } from './user-video-rate.type' | ||
2 | import { Video } from '../video.model' | ||
3 | |||
4 | export interface AccountVideoRate { | ||
5 | video: Video | ||
6 | rating: UserVideoRateType | ||
7 | } | ||
diff --git a/shared/models/videos/rate/index.ts b/shared/models/videos/rate/index.ts deleted file mode 100644 index 06aa691bd..000000000 --- a/shared/models/videos/rate/index.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | |||
2 | export * from './user-video-rate-update.model' | ||
3 | export * from './user-video-rate.model' | ||
4 | export * from './account-video-rate.model' | ||
5 | export * from './user-video-rate.type' | ||
diff --git a/shared/models/videos/rate/user-video-rate-update.model.ts b/shared/models/videos/rate/user-video-rate-update.model.ts deleted file mode 100644 index 85e89271a..000000000 --- a/shared/models/videos/rate/user-video-rate-update.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | import { UserVideoRateType } from './user-video-rate.type' | ||
2 | |||
3 | export interface UserVideoRateUpdate { | ||
4 | rating: UserVideoRateType | ||
5 | } | ||
diff --git a/shared/models/videos/rate/user-video-rate.model.ts b/shared/models/videos/rate/user-video-rate.model.ts deleted file mode 100644 index d39a1c3d5..000000000 --- a/shared/models/videos/rate/user-video-rate.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | import { UserVideoRateType } from './user-video-rate.type' | ||
2 | |||
3 | export interface UserVideoRate { | ||
4 | videoId: number | ||
5 | rating: UserVideoRateType | ||
6 | } | ||
diff --git a/shared/models/videos/rate/user-video-rate.type.ts b/shared/models/videos/rate/user-video-rate.type.ts deleted file mode 100644 index a4d9c7e39..000000000 --- a/shared/models/videos/rate/user-video-rate.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type UserVideoRateType = 'like' | 'dislike' | 'none' | ||
diff --git a/shared/models/videos/stats/index.ts b/shared/models/videos/stats/index.ts deleted file mode 100644 index a9b203f58..000000000 --- a/shared/models/videos/stats/index.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export * from './video-stats-overall-query.model' | ||
2 | export * from './video-stats-overall.model' | ||
3 | export * from './video-stats-retention.model' | ||
4 | export * from './video-stats-timeserie-query.model' | ||
5 | export * from './video-stats-timeserie-metric.type' | ||
6 | export * from './video-stats-timeserie.model' | ||
diff --git a/shared/models/videos/stats/video-stats-overall-query.model.ts b/shared/models/videos/stats/video-stats-overall-query.model.ts deleted file mode 100644 index 6b4c2164f..000000000 --- a/shared/models/videos/stats/video-stats-overall-query.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface VideoStatsOverallQuery { | ||
2 | startDate?: string | ||
3 | endDate?: string | ||
4 | } | ||
diff --git a/shared/models/videos/stats/video-stats-overall.model.ts b/shared/models/videos/stats/video-stats-overall.model.ts deleted file mode 100644 index 54b57798f..000000000 --- a/shared/models/videos/stats/video-stats-overall.model.ts +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | export interface VideoStatsOverall { | ||
2 | averageWatchTime: number | ||
3 | totalWatchTime: number | ||
4 | |||
5 | totalViewers: number | ||
6 | |||
7 | viewersPeak: number | ||
8 | viewersPeakDate: string | ||
9 | |||
10 | countries: { | ||
11 | isoCode: string | ||
12 | viewers: number | ||
13 | }[] | ||
14 | } | ||
diff --git a/shared/models/videos/stats/video-stats-retention.model.ts b/shared/models/videos/stats/video-stats-retention.model.ts deleted file mode 100644 index e494888ed..000000000 --- a/shared/models/videos/stats/video-stats-retention.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export interface VideoStatsRetention { | ||
2 | data: { | ||
3 | second: number | ||
4 | retentionPercent: number | ||
5 | }[] | ||
6 | } | ||
diff --git a/shared/models/videos/stats/video-stats-timeserie-metric.type.ts b/shared/models/videos/stats/video-stats-timeserie-metric.type.ts deleted file mode 100644 index fc268d083..000000000 --- a/shared/models/videos/stats/video-stats-timeserie-metric.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type VideoStatsTimeserieMetric = 'viewers' | 'aggregateWatchTime' | ||
diff --git a/shared/models/videos/stats/video-stats-timeserie-query.model.ts b/shared/models/videos/stats/video-stats-timeserie-query.model.ts deleted file mode 100644 index f3a8430e1..000000000 --- a/shared/models/videos/stats/video-stats-timeserie-query.model.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface VideoStatsTimeserieQuery { | ||
2 | startDate?: string | ||
3 | endDate?: string | ||
4 | } | ||
diff --git a/shared/models/videos/stats/video-stats-timeserie.model.ts b/shared/models/videos/stats/video-stats-timeserie.model.ts deleted file mode 100644 index 4a0e208df..000000000 --- a/shared/models/videos/stats/video-stats-timeserie.model.ts +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | export interface VideoStatsTimeserie { | ||
2 | groupInterval: string | ||
3 | |||
4 | data: { | ||
5 | date: string | ||
6 | value: number | ||
7 | }[] | ||
8 | } | ||
diff --git a/shared/models/videos/storyboard.model.ts b/shared/models/videos/storyboard.model.ts deleted file mode 100644 index c92c81f09..000000000 --- a/shared/models/videos/storyboard.model.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | export interface Storyboard { | ||
2 | storyboardPath: string | ||
3 | |||
4 | totalHeight: number | ||
5 | totalWidth: number | ||
6 | |||
7 | spriteHeight: number | ||
8 | spriteWidth: number | ||
9 | |||
10 | spriteDuration: number | ||
11 | } | ||
diff --git a/shared/models/videos/studio/index.ts b/shared/models/videos/studio/index.ts deleted file mode 100644 index a1eb98a49..000000000 --- a/shared/models/videos/studio/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './video-studio-create-edit.model' | ||
diff --git a/shared/models/videos/studio/video-studio-create-edit.model.ts b/shared/models/videos/studio/video-studio-create-edit.model.ts deleted file mode 100644 index 5e8296dc9..000000000 --- a/shared/models/videos/studio/video-studio-create-edit.model.ts +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | export interface VideoStudioCreateEdition { | ||
2 | tasks: VideoStudioTask[] | ||
3 | } | ||
4 | |||
5 | export type VideoStudioTask = | ||
6 | VideoStudioTaskCut | | ||
7 | VideoStudioTaskIntro | | ||
8 | VideoStudioTaskOutro | | ||
9 | VideoStudioTaskWatermark | ||
10 | |||
11 | export interface VideoStudioTaskCut { | ||
12 | name: 'cut' | ||
13 | |||
14 | options: { | ||
15 | start?: number | ||
16 | end?: number | ||
17 | } | ||
18 | } | ||
19 | |||
20 | export interface VideoStudioTaskIntro { | ||
21 | name: 'add-intro' | ||
22 | |||
23 | options: { | ||
24 | file: Blob | string | ||
25 | } | ||
26 | } | ||
27 | |||
28 | export interface VideoStudioTaskOutro { | ||
29 | name: 'add-outro' | ||
30 | |||
31 | options: { | ||
32 | file: Blob | string | ||
33 | } | ||
34 | } | ||
35 | |||
36 | export interface VideoStudioTaskWatermark { | ||
37 | name: 'add-watermark' | ||
38 | |||
39 | options: { | ||
40 | file: Blob | string | ||
41 | } | ||
42 | } | ||
43 | |||
44 | // --------------------------------------------------------------------------- | ||
45 | |||
46 | export function isVideoStudioTaskIntro (v: VideoStudioTask): v is VideoStudioTaskIntro { | ||
47 | return v.name === 'add-intro' | ||
48 | } | ||
49 | |||
50 | export function isVideoStudioTaskOutro (v: VideoStudioTask): v is VideoStudioTaskOutro { | ||
51 | return v.name === 'add-outro' | ||
52 | } | ||
53 | |||
54 | export function isVideoStudioTaskWatermark (v: VideoStudioTask): v is VideoStudioTaskWatermark { | ||
55 | return v.name === 'add-watermark' | ||
56 | } | ||
57 | |||
58 | export function hasVideoStudioTaskFile (v: VideoStudioTask): v is VideoStudioTaskIntro | VideoStudioTaskOutro | VideoStudioTaskWatermark { | ||
59 | return isVideoStudioTaskIntro(v) || isVideoStudioTaskOutro(v) || isVideoStudioTaskWatermark(v) | ||
60 | } | ||
diff --git a/shared/models/videos/thumbnail.type.ts b/shared/models/videos/thumbnail.type.ts deleted file mode 100644 index 6907b2802..000000000 --- a/shared/models/videos/thumbnail.type.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export const enum ThumbnailType { | ||
2 | MINIATURE = 1, | ||
3 | PREVIEW = 2 | ||
4 | } | ||
diff --git a/shared/models/videos/transcoding/index.ts b/shared/models/videos/transcoding/index.ts deleted file mode 100644 index 14472d900..000000000 --- a/shared/models/videos/transcoding/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './video-transcoding-create.model' | ||
2 | export * from './video-transcoding-fps.model' | ||
3 | export * from './video-transcoding.model' | ||
diff --git a/shared/models/videos/transcoding/video-transcoding-create.model.ts b/shared/models/videos/transcoding/video-transcoding-create.model.ts deleted file mode 100644 index 6c2dbefa6..000000000 --- a/shared/models/videos/transcoding/video-transcoding-create.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface VideoTranscodingCreate { | ||
2 | transcodingType: 'hls' | 'webtorrent' | 'web-video' // TODO: remove webtorrent in v7 | ||
3 | |||
4 | forceTranscoding?: boolean // Default false | ||
5 | } | ||
diff --git a/shared/models/videos/transcoding/video-transcoding-fps.model.ts b/shared/models/videos/transcoding/video-transcoding-fps.model.ts deleted file mode 100644 index 9a330ac94..000000000 --- a/shared/models/videos/transcoding/video-transcoding-fps.model.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | export type VideoTranscodingFPS = { | ||
2 | MIN: number | ||
3 | STANDARD: number[] | ||
4 | HD_STANDARD: number[] | ||
5 | AUDIO_MERGE: number | ||
6 | AVERAGE: number | ||
7 | MAX: number | ||
8 | KEEP_ORIGIN_FPS_RESOLUTION_MIN: number | ||
9 | } | ||
diff --git a/shared/models/videos/transcoding/video-transcoding.model.ts b/shared/models/videos/transcoding/video-transcoding.model.ts deleted file mode 100644 index 91eacf8dc..000000000 --- a/shared/models/videos/transcoding/video-transcoding.model.ts +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | import { VideoResolution } from '../file/video-resolution.enum' | ||
2 | |||
3 | // Types used by plugins and ffmpeg-utils | ||
4 | |||
5 | export type EncoderOptionsBuilderParams = { | ||
6 | input: string | ||
7 | |||
8 | resolution: VideoResolution | ||
9 | |||
10 | // If PeerTube applies a filter, transcoding profile must not copy input stream | ||
11 | canCopyAudio: boolean | ||
12 | canCopyVideo: boolean | ||
13 | |||
14 | fps: number | ||
15 | |||
16 | // Could be undefined if we could not get input bitrate (some RTMP streams for example) | ||
17 | inputBitrate: number | ||
18 | inputRatio: number | ||
19 | |||
20 | // For lives | ||
21 | streamNum?: number | ||
22 | } | ||
23 | |||
24 | export type EncoderOptionsBuilder = (params: EncoderOptionsBuilderParams) => Promise<EncoderOptions> | EncoderOptions | ||
25 | |||
26 | export interface EncoderOptions { | ||
27 | copy?: boolean // Copy stream? Default to false | ||
28 | |||
29 | scaleFilter?: { | ||
30 | name: string | ||
31 | } | ||
32 | |||
33 | inputOptions?: string[] | ||
34 | outputOptions?: string[] | ||
35 | } | ||
36 | |||
37 | // All our encoders | ||
38 | |||
39 | export interface EncoderProfile <T> { | ||
40 | [ profile: string ]: T | ||
41 | |||
42 | default: T | ||
43 | } | ||
44 | |||
45 | export type AvailableEncoders = { | ||
46 | available: { | ||
47 | live: { | ||
48 | [ encoder: string ]: EncoderProfile<EncoderOptionsBuilder> | ||
49 | } | ||
50 | |||
51 | vod: { | ||
52 | [ encoder: string ]: EncoderProfile<EncoderOptionsBuilder> | ||
53 | } | ||
54 | } | ||
55 | |||
56 | encodersToTry: { | ||
57 | vod: { | ||
58 | video: string[] | ||
59 | audio: string[] | ||
60 | } | ||
61 | |||
62 | live: { | ||
63 | video: string[] | ||
64 | audio: string[] | ||
65 | } | ||
66 | } | ||
67 | } | ||
diff --git a/shared/models/videos/video-constant.model.ts b/shared/models/videos/video-constant.model.ts deleted file mode 100644 index 353a29535..000000000 --- a/shared/models/videos/video-constant.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface VideoConstant<T> { | ||
2 | id: T | ||
3 | label: string | ||
4 | description?: string | ||
5 | } | ||
diff --git a/shared/models/videos/video-create-result.model.ts b/shared/models/videos/video-create-result.model.ts deleted file mode 100644 index a9f8e25a0..000000000 --- a/shared/models/videos/video-create-result.model.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export interface VideoCreateResult { | ||
2 | id: number | ||
3 | uuid: string | ||
4 | shortUUID: string | ||
5 | } | ||
diff --git a/shared/models/videos/video-create.model.ts b/shared/models/videos/video-create.model.ts deleted file mode 100644 index 7a34b5afe..000000000 --- a/shared/models/videos/video-create.model.ts +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | import { VideoPrivacy } from './video-privacy.enum' | ||
2 | import { VideoScheduleUpdate } from './video-schedule-update.model' | ||
3 | |||
4 | export interface VideoCreate { | ||
5 | name: string | ||
6 | channelId: number | ||
7 | |||
8 | category?: number | ||
9 | licence?: number | ||
10 | language?: string | ||
11 | description?: string | ||
12 | support?: string | ||
13 | nsfw?: boolean | ||
14 | waitTranscoding?: boolean | ||
15 | tags?: string[] | ||
16 | commentsEnabled?: boolean | ||
17 | downloadEnabled?: boolean | ||
18 | privacy: VideoPrivacy | ||
19 | scheduleUpdate?: VideoScheduleUpdate | ||
20 | originallyPublishedAt?: Date | string | ||
21 | videoPasswords?: string[] | ||
22 | |||
23 | thumbnailfile?: Blob | string | ||
24 | previewfile?: Blob | string | ||
25 | } | ||
diff --git a/shared/models/videos/video-include.enum.ts b/shared/models/videos/video-include.enum.ts deleted file mode 100644 index 32ee12e86..000000000 --- a/shared/models/videos/video-include.enum.ts +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | export const enum VideoInclude { | ||
2 | NONE = 0, | ||
3 | NOT_PUBLISHED_STATE = 1 << 0, | ||
4 | BLACKLISTED = 1 << 1, | ||
5 | BLOCKED_OWNER = 1 << 2, | ||
6 | FILES = 1 << 3, | ||
7 | CAPTIONS = 1 << 4 | ||
8 | } | ||
diff --git a/shared/models/videos/video-password.model.ts b/shared/models/videos/video-password.model.ts deleted file mode 100644 index c0280b9b9..000000000 --- a/shared/models/videos/video-password.model.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | export interface VideoPassword { | ||
2 | id: number | ||
3 | password: string | ||
4 | videoId: number | ||
5 | createdAt: Date | string | ||
6 | updatedAt: Date | string | ||
7 | } | ||
diff --git a/shared/models/videos/video-privacy.enum.ts b/shared/models/videos/video-privacy.enum.ts deleted file mode 100644 index 12e1d196f..000000000 --- a/shared/models/videos/video-privacy.enum.ts +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | export const enum VideoPrivacy { | ||
2 | PUBLIC = 1, | ||
3 | UNLISTED = 2, | ||
4 | PRIVATE = 3, | ||
5 | INTERNAL = 4, | ||
6 | PASSWORD_PROTECTED = 5 | ||
7 | } | ||
diff --git a/shared/models/videos/video-rate.type.ts b/shared/models/videos/video-rate.type.ts deleted file mode 100644 index d48774a4b..000000000 --- a/shared/models/videos/video-rate.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type VideoRateType = 'like' | 'dislike' | ||
diff --git a/shared/models/videos/video-schedule-update.model.ts b/shared/models/videos/video-schedule-update.model.ts deleted file mode 100644 index 87d74f654..000000000 --- a/shared/models/videos/video-schedule-update.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | import { VideoPrivacy } from './video-privacy.enum' | ||
2 | |||
3 | export interface VideoScheduleUpdate { | ||
4 | updateAt: Date | string | ||
5 | privacy?: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED | VideoPrivacy.INTERNAL // Cannot schedule an update to PRIVATE | ||
6 | } | ||
diff --git a/shared/models/videos/video-sort-field.type.ts b/shared/models/videos/video-sort-field.type.ts deleted file mode 100644 index 7fa07fa73..000000000 --- a/shared/models/videos/video-sort-field.type.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | export type VideoSortField = | ||
2 | 'name' | '-name' | | ||
3 | 'duration' | '-duration' | | ||
4 | 'publishedAt' | '-publishedAt' | | ||
5 | 'originallyPublishedAt' | '-originallyPublishedAt' | | ||
6 | 'createdAt' | '-createdAt' | | ||
7 | 'views' | '-views' | | ||
8 | 'likes' | '-likes' | | ||
9 | |||
10 | // trending sorts | ||
11 | 'trending' | '-trending' | | ||
12 | 'hot' | '-hot' | | ||
13 | 'best' | '-best' | ||
diff --git a/shared/models/videos/video-source.ts b/shared/models/videos/video-source.ts deleted file mode 100644 index bf4ad2453..000000000 --- a/shared/models/videos/video-source.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export interface VideoSource { | ||
2 | filename: string | ||
3 | createdAt: string | Date | ||
4 | } | ||
diff --git a/shared/models/videos/video-state.enum.ts b/shared/models/videos/video-state.enum.ts deleted file mode 100644 index e45e4adc2..000000000 --- a/shared/models/videos/video-state.enum.ts +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | export const enum VideoState { | ||
2 | PUBLISHED = 1, | ||
3 | TO_TRANSCODE = 2, | ||
4 | TO_IMPORT = 3, | ||
5 | WAITING_FOR_LIVE = 4, | ||
6 | LIVE_ENDED = 5, | ||
7 | TO_MOVE_TO_EXTERNAL_STORAGE = 6, | ||
8 | TRANSCODING_FAILED = 7, | ||
9 | TO_MOVE_TO_EXTERNAL_STORAGE_FAILED = 8, | ||
10 | TO_EDIT = 9 | ||
11 | } | ||
diff --git a/shared/models/videos/video-storage.enum.ts b/shared/models/videos/video-storage.enum.ts deleted file mode 100644 index 7c6690db2..000000000 --- a/shared/models/videos/video-storage.enum.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export const enum VideoStorage { | ||
2 | FILE_SYSTEM, | ||
3 | OBJECT_STORAGE, | ||
4 | } | ||
diff --git a/shared/models/videos/video-streaming-playlist.model.ts b/shared/models/videos/video-streaming-playlist.model.ts deleted file mode 100644 index 11919a4ee..000000000 --- a/shared/models/videos/video-streaming-playlist.model.ts +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | import { VideoStreamingPlaylistType } from './video-streaming-playlist.type' | ||
2 | import { VideoFile } from './file' | ||
3 | |||
4 | export interface VideoStreamingPlaylist { | ||
5 | id: number | ||
6 | type: VideoStreamingPlaylistType | ||
7 | playlistUrl: string | ||
8 | segmentsSha256Url: string | ||
9 | |||
10 | redundancies: { | ||
11 | baseUrl: string | ||
12 | }[] | ||
13 | |||
14 | files: VideoFile[] | ||
15 | } | ||
diff --git a/shared/models/videos/video-streaming-playlist.type.ts b/shared/models/videos/video-streaming-playlist.type.ts deleted file mode 100644 index e2e2b93ea..000000000 --- a/shared/models/videos/video-streaming-playlist.type.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export const enum VideoStreamingPlaylistType { | ||
2 | HLS = 1 | ||
3 | } | ||
diff --git a/shared/models/videos/video-token.model.ts b/shared/models/videos/video-token.model.ts deleted file mode 100644 index aefea565f..000000000 --- a/shared/models/videos/video-token.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export interface VideoToken { | ||
2 | files: { | ||
3 | token: string | ||
4 | expires: string | Date | ||
5 | } | ||
6 | } | ||
diff --git a/shared/models/videos/video-update.model.ts b/shared/models/videos/video-update.model.ts deleted file mode 100644 index 43537b5af..000000000 --- a/shared/models/videos/video-update.model.ts +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | import { VideoPrivacy } from './video-privacy.enum' | ||
2 | import { VideoScheduleUpdate } from './video-schedule-update.model' | ||
3 | |||
4 | export interface VideoUpdate { | ||
5 | name?: string | ||
6 | category?: number | ||
7 | licence?: number | ||
8 | language?: string | ||
9 | description?: string | ||
10 | support?: string | ||
11 | privacy?: VideoPrivacy | ||
12 | tags?: string[] | ||
13 | commentsEnabled?: boolean | ||
14 | downloadEnabled?: boolean | ||
15 | nsfw?: boolean | ||
16 | waitTranscoding?: boolean | ||
17 | channelId?: number | ||
18 | thumbnailfile?: Blob | ||
19 | previewfile?: Blob | ||
20 | scheduleUpdate?: VideoScheduleUpdate | ||
21 | originallyPublishedAt?: Date | string | ||
22 | videoPasswords?: string[] | ||
23 | |||
24 | pluginData?: any | ||
25 | } | ||
diff --git a/shared/models/videos/video-view.model.ts b/shared/models/videos/video-view.model.ts deleted file mode 100644 index f61211104..000000000 --- a/shared/models/videos/video-view.model.ts +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | export type VideoViewEvent = 'seek' | ||
2 | |||
3 | export interface VideoView { | ||
4 | currentTime: number | ||
5 | viewEvent?: VideoViewEvent | ||
6 | } | ||
diff --git a/shared/models/videos/video.model.ts b/shared/models/videos/video.model.ts deleted file mode 100644 index 7e5930067..000000000 --- a/shared/models/videos/video.model.ts +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | import { Account, AccountSummary } from '../actors' | ||
2 | import { VideoChannel, VideoChannelSummary } from './channel/video-channel.model' | ||
3 | import { VideoFile } from './file' | ||
4 | import { VideoConstant } from './video-constant.model' | ||
5 | import { VideoPrivacy } from './video-privacy.enum' | ||
6 | import { VideoScheduleUpdate } from './video-schedule-update.model' | ||
7 | import { VideoState } from './video-state.enum' | ||
8 | import { VideoStreamingPlaylist } from './video-streaming-playlist.model' | ||
9 | |||
10 | export interface Video extends Partial<VideoAdditionalAttributes> { | ||
11 | id: number | ||
12 | uuid: string | ||
13 | shortUUID: string | ||
14 | |||
15 | createdAt: Date | string | ||
16 | updatedAt: Date | string | ||
17 | publishedAt: Date | string | ||
18 | originallyPublishedAt: Date | string | ||
19 | category: VideoConstant<number> | ||
20 | licence: VideoConstant<number> | ||
21 | language: VideoConstant<string> | ||
22 | privacy: VideoConstant<VideoPrivacy> | ||
23 | |||
24 | // Deprecated in 5.0 in favour of truncatedDescription | ||
25 | description: string | ||
26 | truncatedDescription: string | ||
27 | |||
28 | duration: number | ||
29 | isLocal: boolean | ||
30 | name: string | ||
31 | |||
32 | isLive: boolean | ||
33 | |||
34 | thumbnailPath: string | ||
35 | thumbnailUrl?: string | ||
36 | |||
37 | previewPath: string | ||
38 | previewUrl?: string | ||
39 | |||
40 | embedPath: string | ||
41 | embedUrl?: string | ||
42 | |||
43 | url: string | ||
44 | |||
45 | views: number | ||
46 | viewers: number | ||
47 | |||
48 | likes: number | ||
49 | dislikes: number | ||
50 | nsfw: boolean | ||
51 | |||
52 | account: AccountSummary | ||
53 | channel: VideoChannelSummary | ||
54 | |||
55 | userHistory?: { | ||
56 | currentTime: number | ||
57 | } | ||
58 | |||
59 | pluginData?: any | ||
60 | } | ||
61 | |||
62 | // Not included by default, needs query params | ||
63 | export interface VideoAdditionalAttributes { | ||
64 | waitTranscoding: boolean | ||
65 | state: VideoConstant<VideoState> | ||
66 | scheduledUpdate: VideoScheduleUpdate | ||
67 | |||
68 | blacklisted: boolean | ||
69 | blacklistedReason: string | ||
70 | |||
71 | blockedOwner: boolean | ||
72 | blockedServer: boolean | ||
73 | |||
74 | files: VideoFile[] | ||
75 | streamingPlaylists: VideoStreamingPlaylist[] | ||
76 | } | ||
77 | |||
78 | export interface VideoDetails extends Video { | ||
79 | // Deprecated in 5.0 | ||
80 | descriptionPath: string | ||
81 | |||
82 | support: string | ||
83 | channel: VideoChannel | ||
84 | account: Account | ||
85 | tags: string[] | ||
86 | commentsEnabled: boolean | ||
87 | downloadEnabled: boolean | ||
88 | |||
89 | // Not optional in details (unlike in parent Video) | ||
90 | waitTranscoding: boolean | ||
91 | state: VideoConstant<VideoState> | ||
92 | |||
93 | trackerUrls: string[] | ||
94 | |||
95 | files: VideoFile[] | ||
96 | streamingPlaylists: VideoStreamingPlaylist[] | ||
97 | |||
98 | inputFileUpdatedAt: string | Date | ||
99 | } | ||
diff --git a/shared/server-commands/bulk/bulk-command.ts b/shared/server-commands/bulk/bulk-command.ts deleted file mode 100644 index b5c5673ce..000000000 --- a/shared/server-commands/bulk/bulk-command.ts +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | import { BulkRemoveCommentsOfBody, HttpStatusCode } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class BulkCommand extends AbstractCommand { | ||
5 | |||
6 | removeCommentsOf (options: OverrideCommandOptions & { | ||
7 | attributes: BulkRemoveCommentsOfBody | ||
8 | }) { | ||
9 | const { attributes } = options | ||
10 | |||
11 | return this.postBodyRequest({ | ||
12 | ...options, | ||
13 | |||
14 | path: '/api/v1/bulk/remove-comments-of', | ||
15 | fields: attributes, | ||
16 | implicitToken: true, | ||
17 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
18 | }) | ||
19 | } | ||
20 | } | ||
diff --git a/shared/server-commands/bulk/index.ts b/shared/server-commands/bulk/index.ts deleted file mode 100644 index 391597243..000000000 --- a/shared/server-commands/bulk/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './bulk-command' | ||
diff --git a/shared/server-commands/cli/cli-command.ts b/shared/server-commands/cli/cli-command.ts deleted file mode 100644 index ab9738174..000000000 --- a/shared/server-commands/cli/cli-command.ts +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | import { exec } from 'child_process' | ||
2 | import { AbstractCommand } from '../shared' | ||
3 | |||
4 | export class CLICommand extends AbstractCommand { | ||
5 | |||
6 | static exec (command: string) { | ||
7 | return new Promise<string>((res, rej) => { | ||
8 | exec(command, (err, stdout, _stderr) => { | ||
9 | if (err) return rej(err) | ||
10 | |||
11 | return res(stdout) | ||
12 | }) | ||
13 | }) | ||
14 | } | ||
15 | |||
16 | getEnv () { | ||
17 | return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}` | ||
18 | } | ||
19 | |||
20 | async execWithEnv (command: string, configOverride?: any) { | ||
21 | const prefix = configOverride | ||
22 | ? `NODE_CONFIG='${JSON.stringify(configOverride)}'` | ||
23 | : '' | ||
24 | |||
25 | return CLICommand.exec(`${prefix} ${this.getEnv()} ${command}`) | ||
26 | } | ||
27 | } | ||
diff --git a/shared/server-commands/cli/index.ts b/shared/server-commands/cli/index.ts deleted file mode 100644 index 91b5abfbe..000000000 --- a/shared/server-commands/cli/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './cli-command' | ||
diff --git a/shared/server-commands/custom-pages/custom-pages-command.ts b/shared/server-commands/custom-pages/custom-pages-command.ts deleted file mode 100644 index cd869a8de..000000000 --- a/shared/server-commands/custom-pages/custom-pages-command.ts +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | import { CustomPage, HttpStatusCode } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class CustomPagesCommand extends AbstractCommand { | ||
5 | |||
6 | getInstanceHomepage (options: OverrideCommandOptions = {}) { | ||
7 | const path = '/api/v1/custom-pages/homepage/instance' | ||
8 | |||
9 | return this.getRequestBody<CustomPage>({ | ||
10 | ...options, | ||
11 | |||
12 | path, | ||
13 | implicitToken: false, | ||
14 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
15 | }) | ||
16 | } | ||
17 | |||
18 | updateInstanceHomepage (options: OverrideCommandOptions & { | ||
19 | content: string | ||
20 | }) { | ||
21 | const { content } = options | ||
22 | const path = '/api/v1/custom-pages/homepage/instance' | ||
23 | |||
24 | return this.putBodyRequest({ | ||
25 | ...options, | ||
26 | |||
27 | path, | ||
28 | fields: { content }, | ||
29 | implicitToken: true, | ||
30 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
31 | }) | ||
32 | } | ||
33 | } | ||
diff --git a/shared/server-commands/custom-pages/index.ts b/shared/server-commands/custom-pages/index.ts deleted file mode 100644 index 58aed04f2..000000000 --- a/shared/server-commands/custom-pages/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './custom-pages-command' | ||
diff --git a/shared/server-commands/feeds/feeds-command.ts b/shared/server-commands/feeds/feeds-command.ts deleted file mode 100644 index 26763b43e..000000000 --- a/shared/server-commands/feeds/feeds-command.ts +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | import { buildUUID } from '@shared/extra-utils' | ||
2 | import { HttpStatusCode } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | type FeedType = 'videos' | 'video-comments' | 'subscriptions' | ||
6 | |||
7 | export class FeedCommand extends AbstractCommand { | ||
8 | |||
9 | getXML (options: OverrideCommandOptions & { | ||
10 | feed: FeedType | ||
11 | ignoreCache: boolean | ||
12 | format?: string | ||
13 | }) { | ||
14 | const { feed, format, ignoreCache } = options | ||
15 | const path = '/feeds/' + feed + '.xml' | ||
16 | |||
17 | const query: { [id: string]: string } = {} | ||
18 | |||
19 | if (ignoreCache) query.v = buildUUID() | ||
20 | if (format) query.format = format | ||
21 | |||
22 | return this.getRequestText({ | ||
23 | ...options, | ||
24 | |||
25 | path, | ||
26 | query, | ||
27 | accept: 'application/xml', | ||
28 | implicitToken: false, | ||
29 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
30 | }) | ||
31 | } | ||
32 | |||
33 | getPodcastXML (options: OverrideCommandOptions & { | ||
34 | ignoreCache: boolean | ||
35 | channelId: number | ||
36 | }) { | ||
37 | const { ignoreCache, channelId } = options | ||
38 | const path = `/feeds/podcast/videos.xml` | ||
39 | |||
40 | const query: { [id: string]: string } = {} | ||
41 | |||
42 | if (ignoreCache) query.v = buildUUID() | ||
43 | if (channelId) query.videoChannelId = channelId + '' | ||
44 | |||
45 | return this.getRequestText({ | ||
46 | ...options, | ||
47 | |||
48 | path, | ||
49 | query, | ||
50 | accept: 'application/xml', | ||
51 | implicitToken: false, | ||
52 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
53 | }) | ||
54 | } | ||
55 | |||
56 | getJSON (options: OverrideCommandOptions & { | ||
57 | feed: FeedType | ||
58 | ignoreCache: boolean | ||
59 | query?: { [ id: string ]: any } | ||
60 | }) { | ||
61 | const { feed, query = {}, ignoreCache } = options | ||
62 | const path = '/feeds/' + feed + '.json' | ||
63 | |||
64 | const cacheQuery = ignoreCache | ||
65 | ? { v: buildUUID() } | ||
66 | : {} | ||
67 | |||
68 | return this.getRequestText({ | ||
69 | ...options, | ||
70 | |||
71 | path, | ||
72 | query: { ...query, ...cacheQuery }, | ||
73 | accept: 'application/json', | ||
74 | implicitToken: false, | ||
75 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
76 | }) | ||
77 | } | ||
78 | } | ||
diff --git a/shared/server-commands/feeds/index.ts b/shared/server-commands/feeds/index.ts deleted file mode 100644 index 662a22b6f..000000000 --- a/shared/server-commands/feeds/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './feeds-command' | ||
diff --git a/shared/server-commands/index.ts b/shared/server-commands/index.ts deleted file mode 100644 index a4581dbc0..000000000 --- a/shared/server-commands/index.ts +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | export * from './bulk' | ||
2 | export * from './cli' | ||
3 | export * from './custom-pages' | ||
4 | export * from './feeds' | ||
5 | export * from './logs' | ||
6 | export * from './moderation' | ||
7 | export * from './overviews' | ||
8 | export * from './requests' | ||
9 | export * from './runners' | ||
10 | export * from './search' | ||
11 | export * from './server' | ||
12 | export * from './socket' | ||
13 | export * from './users' | ||
14 | export * from './videos' | ||
diff --git a/shared/server-commands/logs/index.ts b/shared/server-commands/logs/index.ts deleted file mode 100644 index 69452d7f0..000000000 --- a/shared/server-commands/logs/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './logs-command' | ||
diff --git a/shared/server-commands/logs/logs-command.ts b/shared/server-commands/logs/logs-command.ts deleted file mode 100644 index 1c5de7f59..000000000 --- a/shared/server-commands/logs/logs-command.ts +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | import { ClientLogCreate, HttpStatusCode, ServerLogLevel } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class LogsCommand extends AbstractCommand { | ||
5 | |||
6 | createLogClient (options: OverrideCommandOptions & { payload: ClientLogCreate }) { | ||
7 | const path = '/api/v1/server/logs/client' | ||
8 | |||
9 | return this.postBodyRequest({ | ||
10 | ...options, | ||
11 | |||
12 | path, | ||
13 | fields: options.payload, | ||
14 | implicitToken: true, | ||
15 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
16 | }) | ||
17 | } | ||
18 | |||
19 | getLogs (options: OverrideCommandOptions & { | ||
20 | startDate: Date | ||
21 | endDate?: Date | ||
22 | level?: ServerLogLevel | ||
23 | tagsOneOf?: string[] | ||
24 | }) { | ||
25 | const { startDate, endDate, tagsOneOf, level } = options | ||
26 | const path = '/api/v1/server/logs' | ||
27 | |||
28 | return this.getRequestBody<any[]>({ | ||
29 | ...options, | ||
30 | |||
31 | path, | ||
32 | query: { startDate, endDate, level, tagsOneOf }, | ||
33 | implicitToken: true, | ||
34 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
35 | }) | ||
36 | } | ||
37 | |||
38 | getAuditLogs (options: OverrideCommandOptions & { | ||
39 | startDate: Date | ||
40 | endDate?: Date | ||
41 | }) { | ||
42 | const { startDate, endDate } = options | ||
43 | |||
44 | const path = '/api/v1/server/audit-logs' | ||
45 | |||
46 | return this.getRequestBody({ | ||
47 | ...options, | ||
48 | |||
49 | path, | ||
50 | query: { startDate, endDate }, | ||
51 | implicitToken: true, | ||
52 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
53 | }) | ||
54 | } | ||
55 | |||
56 | } | ||
diff --git a/shared/server-commands/moderation/abuses-command.ts b/shared/server-commands/moderation/abuses-command.ts deleted file mode 100644 index 0db32ba46..000000000 --- a/shared/server-commands/moderation/abuses-command.ts +++ /dev/null | |||
@@ -1,228 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { | ||
3 | AbuseFilter, | ||
4 | AbuseMessage, | ||
5 | AbusePredefinedReasonsString, | ||
6 | AbuseState, | ||
7 | AbuseUpdate, | ||
8 | AbuseVideoIs, | ||
9 | AdminAbuse, | ||
10 | HttpStatusCode, | ||
11 | ResultList, | ||
12 | UserAbuse | ||
13 | } from '@shared/models' | ||
14 | import { unwrapBody } from '../requests/requests' | ||
15 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
16 | |||
17 | export class AbusesCommand extends AbstractCommand { | ||
18 | |||
19 | report (options: OverrideCommandOptions & { | ||
20 | reason: string | ||
21 | |||
22 | accountId?: number | ||
23 | videoId?: number | ||
24 | commentId?: number | ||
25 | |||
26 | predefinedReasons?: AbusePredefinedReasonsString[] | ||
27 | |||
28 | startAt?: number | ||
29 | endAt?: number | ||
30 | }) { | ||
31 | const path = '/api/v1/abuses' | ||
32 | |||
33 | const video = options.videoId | ||
34 | ? { | ||
35 | id: options.videoId, | ||
36 | startAt: options.startAt, | ||
37 | endAt: options.endAt | ||
38 | } | ||
39 | : undefined | ||
40 | |||
41 | const comment = options.commentId | ||
42 | ? { id: options.commentId } | ||
43 | : undefined | ||
44 | |||
45 | const account = options.accountId | ||
46 | ? { id: options.accountId } | ||
47 | : undefined | ||
48 | |||
49 | const body = { | ||
50 | account, | ||
51 | video, | ||
52 | comment, | ||
53 | |||
54 | reason: options.reason, | ||
55 | predefinedReasons: options.predefinedReasons | ||
56 | } | ||
57 | |||
58 | return unwrapBody<{ abuse: { id: number } }>(this.postBodyRequest({ | ||
59 | ...options, | ||
60 | |||
61 | path, | ||
62 | fields: body, | ||
63 | implicitToken: true, | ||
64 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
65 | })) | ||
66 | } | ||
67 | |||
68 | getAdminList (options: OverrideCommandOptions & { | ||
69 | start?: number | ||
70 | count?: number | ||
71 | sort?: string | ||
72 | |||
73 | id?: number | ||
74 | predefinedReason?: AbusePredefinedReasonsString | ||
75 | search?: string | ||
76 | filter?: AbuseFilter | ||
77 | state?: AbuseState | ||
78 | videoIs?: AbuseVideoIs | ||
79 | searchReporter?: string | ||
80 | searchReportee?: string | ||
81 | searchVideo?: string | ||
82 | searchVideoChannel?: string | ||
83 | } = {}) { | ||
84 | const toPick: (keyof typeof options)[] = [ | ||
85 | 'count', | ||
86 | 'filter', | ||
87 | 'id', | ||
88 | 'predefinedReason', | ||
89 | 'search', | ||
90 | 'searchReportee', | ||
91 | 'searchReporter', | ||
92 | 'searchVideo', | ||
93 | 'searchVideoChannel', | ||
94 | 'sort', | ||
95 | 'start', | ||
96 | 'state', | ||
97 | 'videoIs' | ||
98 | ] | ||
99 | |||
100 | const path = '/api/v1/abuses' | ||
101 | |||
102 | const defaultQuery = { sort: 'createdAt' } | ||
103 | const query = { ...defaultQuery, ...pick(options, toPick) } | ||
104 | |||
105 | return this.getRequestBody<ResultList<AdminAbuse>>({ | ||
106 | ...options, | ||
107 | |||
108 | path, | ||
109 | query, | ||
110 | implicitToken: true, | ||
111 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
112 | }) | ||
113 | } | ||
114 | |||
115 | getUserList (options: OverrideCommandOptions & { | ||
116 | start?: number | ||
117 | count?: number | ||
118 | sort?: string | ||
119 | |||
120 | id?: number | ||
121 | search?: string | ||
122 | state?: AbuseState | ||
123 | }) { | ||
124 | const toPick: (keyof typeof options)[] = [ | ||
125 | 'id', | ||
126 | 'search', | ||
127 | 'state', | ||
128 | 'start', | ||
129 | 'count', | ||
130 | 'sort' | ||
131 | ] | ||
132 | |||
133 | const path = '/api/v1/users/me/abuses' | ||
134 | |||
135 | const defaultQuery = { sort: 'createdAt' } | ||
136 | const query = { ...defaultQuery, ...pick(options, toPick) } | ||
137 | |||
138 | return this.getRequestBody<ResultList<UserAbuse>>({ | ||
139 | ...options, | ||
140 | |||
141 | path, | ||
142 | query, | ||
143 | implicitToken: true, | ||
144 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
145 | }) | ||
146 | } | ||
147 | |||
148 | update (options: OverrideCommandOptions & { | ||
149 | abuseId: number | ||
150 | body: AbuseUpdate | ||
151 | }) { | ||
152 | const { abuseId, body } = options | ||
153 | const path = '/api/v1/abuses/' + abuseId | ||
154 | |||
155 | return this.putBodyRequest({ | ||
156 | ...options, | ||
157 | |||
158 | path, | ||
159 | fields: body, | ||
160 | implicitToken: true, | ||
161 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
162 | }) | ||
163 | } | ||
164 | |||
165 | delete (options: OverrideCommandOptions & { | ||
166 | abuseId: number | ||
167 | }) { | ||
168 | const { abuseId } = options | ||
169 | const path = '/api/v1/abuses/' + abuseId | ||
170 | |||
171 | return this.deleteRequest({ | ||
172 | ...options, | ||
173 | |||
174 | path, | ||
175 | implicitToken: true, | ||
176 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
177 | }) | ||
178 | } | ||
179 | |||
180 | listMessages (options: OverrideCommandOptions & { | ||
181 | abuseId: number | ||
182 | }) { | ||
183 | const { abuseId } = options | ||
184 | const path = '/api/v1/abuses/' + abuseId + '/messages' | ||
185 | |||
186 | return this.getRequestBody<ResultList<AbuseMessage>>({ | ||
187 | ...options, | ||
188 | |||
189 | path, | ||
190 | implicitToken: true, | ||
191 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
192 | }) | ||
193 | } | ||
194 | |||
195 | deleteMessage (options: OverrideCommandOptions & { | ||
196 | abuseId: number | ||
197 | messageId: number | ||
198 | }) { | ||
199 | const { abuseId, messageId } = options | ||
200 | const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId | ||
201 | |||
202 | return this.deleteRequest({ | ||
203 | ...options, | ||
204 | |||
205 | path, | ||
206 | implicitToken: true, | ||
207 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
208 | }) | ||
209 | } | ||
210 | |||
211 | addMessage (options: OverrideCommandOptions & { | ||
212 | abuseId: number | ||
213 | message: string | ||
214 | }) { | ||
215 | const { abuseId, message } = options | ||
216 | const path = '/api/v1/abuses/' + abuseId + '/messages' | ||
217 | |||
218 | return this.postBodyRequest({ | ||
219 | ...options, | ||
220 | |||
221 | path, | ||
222 | fields: { message }, | ||
223 | implicitToken: true, | ||
224 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
225 | }) | ||
226 | } | ||
227 | |||
228 | } | ||
diff --git a/shared/server-commands/moderation/index.ts b/shared/server-commands/moderation/index.ts deleted file mode 100644 index b37643956..000000000 --- a/shared/server-commands/moderation/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './abuses-command' | ||
diff --git a/shared/server-commands/overviews/index.ts b/shared/server-commands/overviews/index.ts deleted file mode 100644 index e19551907..000000000 --- a/shared/server-commands/overviews/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './overviews-command' | ||
diff --git a/shared/server-commands/overviews/overviews-command.ts b/shared/server-commands/overviews/overviews-command.ts deleted file mode 100644 index 06b4892d2..000000000 --- a/shared/server-commands/overviews/overviews-command.ts +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | import { HttpStatusCode, VideosOverview } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class OverviewsCommand extends AbstractCommand { | ||
5 | |||
6 | getVideos (options: OverrideCommandOptions & { | ||
7 | page: number | ||
8 | }) { | ||
9 | const { page } = options | ||
10 | const path = '/api/v1/overviews/videos' | ||
11 | |||
12 | const query = { page } | ||
13 | |||
14 | return this.getRequestBody<VideosOverview>({ | ||
15 | ...options, | ||
16 | |||
17 | path, | ||
18 | query, | ||
19 | implicitToken: false, | ||
20 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
21 | }) | ||
22 | } | ||
23 | } | ||
diff --git a/shared/server-commands/requests/index.ts b/shared/server-commands/requests/index.ts deleted file mode 100644 index 802982301..000000000 --- a/shared/server-commands/requests/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './requests' | ||
diff --git a/shared/server-commands/requests/requests.ts b/shared/server-commands/requests/requests.ts deleted file mode 100644 index 8227017eb..000000000 --- a/shared/server-commands/requests/requests.ts +++ /dev/null | |||
@@ -1,259 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-floating-promises */ | ||
2 | |||
3 | import { decode } from 'querystring' | ||
4 | import request from 'supertest' | ||
5 | import { URL } from 'url' | ||
6 | import { buildAbsoluteFixturePath, pick } from '@shared/core-utils' | ||
7 | import { HttpStatusCode } from '@shared/models' | ||
8 | |||
9 | export type CommonRequestParams = { | ||
10 | url: string | ||
11 | path?: string | ||
12 | contentType?: string | ||
13 | responseType?: string | ||
14 | range?: string | ||
15 | redirects?: number | ||
16 | accept?: string | ||
17 | host?: string | ||
18 | token?: string | ||
19 | headers?: { [ name: string ]: string } | ||
20 | type?: string | ||
21 | xForwardedFor?: string | ||
22 | expectedStatus?: HttpStatusCode | ||
23 | } | ||
24 | |||
25 | function makeRawRequest (options: { | ||
26 | url: string | ||
27 | token?: string | ||
28 | expectedStatus?: HttpStatusCode | ||
29 | range?: string | ||
30 | query?: { [ id: string ]: string } | ||
31 | method?: 'GET' | 'POST' | ||
32 | headers?: { [ name: string ]: string } | ||
33 | }) { | ||
34 | const { host, protocol, pathname } = new URL(options.url) | ||
35 | |||
36 | const reqOptions = { | ||
37 | url: `${protocol}//${host}`, | ||
38 | path: pathname, | ||
39 | contentType: undefined, | ||
40 | |||
41 | ...pick(options, [ 'expectedStatus', 'range', 'token', 'query', 'headers' ]) | ||
42 | } | ||
43 | |||
44 | if (options.method === 'POST') { | ||
45 | return makePostBodyRequest(reqOptions) | ||
46 | } | ||
47 | |||
48 | return makeGetRequest(reqOptions) | ||
49 | } | ||
50 | |||
51 | function makeGetRequest (options: CommonRequestParams & { | ||
52 | query?: any | ||
53 | rawQuery?: string | ||
54 | }) { | ||
55 | const req = request(options.url).get(options.path) | ||
56 | |||
57 | if (options.query) req.query(options.query) | ||
58 | if (options.rawQuery) req.query(options.rawQuery) | ||
59 | |||
60 | return buildRequest(req, { contentType: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options }) | ||
61 | } | ||
62 | |||
63 | function makeHTMLRequest (url: string, path: string) { | ||
64 | return makeGetRequest({ | ||
65 | url, | ||
66 | path, | ||
67 | accept: 'text/html', | ||
68 | expectedStatus: HttpStatusCode.OK_200 | ||
69 | }) | ||
70 | } | ||
71 | |||
72 | function makeActivityPubGetRequest (url: string, path: string, expectedStatus = HttpStatusCode.OK_200) { | ||
73 | return makeGetRequest({ | ||
74 | url, | ||
75 | path, | ||
76 | expectedStatus, | ||
77 | accept: 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8' | ||
78 | }) | ||
79 | } | ||
80 | |||
81 | function makeDeleteRequest (options: CommonRequestParams & { | ||
82 | query?: any | ||
83 | rawQuery?: string | ||
84 | }) { | ||
85 | const req = request(options.url).delete(options.path) | ||
86 | |||
87 | if (options.query) req.query(options.query) | ||
88 | if (options.rawQuery) req.query(options.rawQuery) | ||
89 | |||
90 | return buildRequest(req, { accept: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options }) | ||
91 | } | ||
92 | |||
93 | function makeUploadRequest (options: CommonRequestParams & { | ||
94 | method?: 'POST' | 'PUT' | ||
95 | |||
96 | fields: { [ fieldName: string ]: any } | ||
97 | attaches?: { [ attachName: string ]: any | any[] } | ||
98 | }) { | ||
99 | let req = options.method === 'PUT' | ||
100 | ? request(options.url).put(options.path) | ||
101 | : request(options.url).post(options.path) | ||
102 | |||
103 | req = buildRequest(req, { accept: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options }) | ||
104 | |||
105 | buildFields(req, options.fields) | ||
106 | |||
107 | Object.keys(options.attaches || {}).forEach(attach => { | ||
108 | const value = options.attaches[attach] | ||
109 | if (!value) return | ||
110 | |||
111 | if (Array.isArray(value)) { | ||
112 | req.attach(attach, buildAbsoluteFixturePath(value[0]), value[1]) | ||
113 | } else { | ||
114 | req.attach(attach, buildAbsoluteFixturePath(value)) | ||
115 | } | ||
116 | }) | ||
117 | |||
118 | return req | ||
119 | } | ||
120 | |||
121 | function makePostBodyRequest (options: CommonRequestParams & { | ||
122 | fields?: { [ fieldName: string ]: any } | ||
123 | }) { | ||
124 | const req = request(options.url).post(options.path) | ||
125 | .send(options.fields) | ||
126 | |||
127 | return buildRequest(req, { accept: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options }) | ||
128 | } | ||
129 | |||
130 | function makePutBodyRequest (options: { | ||
131 | url: string | ||
132 | path: string | ||
133 | token?: string | ||
134 | fields: { [ fieldName: string ]: any } | ||
135 | expectedStatus?: HttpStatusCode | ||
136 | headers?: { [name: string]: string } | ||
137 | }) { | ||
138 | const req = request(options.url).put(options.path) | ||
139 | .send(options.fields) | ||
140 | |||
141 | return buildRequest(req, { accept: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options }) | ||
142 | } | ||
143 | |||
144 | function decodeQueryString (path: string) { | ||
145 | return decode(path.split('?')[1]) | ||
146 | } | ||
147 | |||
148 | // --------------------------------------------------------------------------- | ||
149 | |||
150 | function unwrapBody <T> (test: request.Test): Promise<T> { | ||
151 | return test.then(res => res.body) | ||
152 | } | ||
153 | |||
154 | function unwrapText (test: request.Test): Promise<string> { | ||
155 | return test.then(res => res.text) | ||
156 | } | ||
157 | |||
158 | function unwrapBodyOrDecodeToJSON <T> (test: request.Test): Promise<T> { | ||
159 | return test.then(res => { | ||
160 | if (res.body instanceof Buffer) { | ||
161 | try { | ||
162 | return JSON.parse(new TextDecoder().decode(res.body)) | ||
163 | } catch (err) { | ||
164 | console.error('Cannot decode JSON.', { res, body: res.body instanceof Buffer ? res.body.toString() : res.body }) | ||
165 | throw err | ||
166 | } | ||
167 | } | ||
168 | |||
169 | if (res.text) { | ||
170 | try { | ||
171 | return JSON.parse(res.text) | ||
172 | } catch (err) { | ||
173 | console.error('Cannot decode json', { res, text: res.text }) | ||
174 | throw err | ||
175 | } | ||
176 | } | ||
177 | |||
178 | return res.body | ||
179 | }) | ||
180 | } | ||
181 | |||
182 | function unwrapTextOrDecode (test: request.Test): Promise<string> { | ||
183 | return test.then(res => res.text || new TextDecoder().decode(res.body)) | ||
184 | } | ||
185 | |||
186 | // --------------------------------------------------------------------------- | ||
187 | |||
188 | export { | ||
189 | makeHTMLRequest, | ||
190 | makeGetRequest, | ||
191 | decodeQueryString, | ||
192 | makeUploadRequest, | ||
193 | makePostBodyRequest, | ||
194 | makePutBodyRequest, | ||
195 | makeDeleteRequest, | ||
196 | makeRawRequest, | ||
197 | makeActivityPubGetRequest, | ||
198 | unwrapBody, | ||
199 | unwrapTextOrDecode, | ||
200 | unwrapBodyOrDecodeToJSON, | ||
201 | unwrapText | ||
202 | } | ||
203 | |||
204 | // --------------------------------------------------------------------------- | ||
205 | |||
206 | function buildRequest (req: request.Test, options: CommonRequestParams) { | ||
207 | if (options.contentType) req.set('Accept', options.contentType) | ||
208 | if (options.responseType) req.responseType(options.responseType) | ||
209 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) | ||
210 | if (options.range) req.set('Range', options.range) | ||
211 | if (options.accept) req.set('Accept', options.accept) | ||
212 | if (options.host) req.set('Host', options.host) | ||
213 | if (options.redirects) req.redirects(options.redirects) | ||
214 | if (options.xForwardedFor) req.set('X-Forwarded-For', options.xForwardedFor) | ||
215 | if (options.type) req.type(options.type) | ||
216 | |||
217 | Object.keys(options.headers || {}).forEach(name => { | ||
218 | req.set(name, options.headers[name]) | ||
219 | }) | ||
220 | |||
221 | return req.expect(res => { | ||
222 | if (options.expectedStatus && res.status !== options.expectedStatus) { | ||
223 | const err = new Error(`Expected status ${options.expectedStatus}, got ${res.status}. ` + | ||
224 | `\nThe server responded: "${res.body?.error ?? res.text}".\n` + | ||
225 | 'You may take a closer look at the logs. To see how to do so, check out this page: ' + | ||
226 | 'https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/development/tests.md#debug-server-logs'); | ||
227 | |||
228 | (err as any).res = res | ||
229 | |||
230 | throw err | ||
231 | } | ||
232 | |||
233 | return res | ||
234 | }) | ||
235 | } | ||
236 | |||
237 | function buildFields (req: request.Test, fields: { [ fieldName: string ]: any }, namespace?: string) { | ||
238 | if (!fields) return | ||
239 | |||
240 | let formKey: string | ||
241 | |||
242 | for (const key of Object.keys(fields)) { | ||
243 | if (namespace) formKey = `${namespace}[${key}]` | ||
244 | else formKey = key | ||
245 | |||
246 | if (fields[key] === undefined) continue | ||
247 | |||
248 | if (Array.isArray(fields[key]) && fields[key].length === 0) { | ||
249 | req.field(key, []) | ||
250 | continue | ||
251 | } | ||
252 | |||
253 | if (fields[key] !== null && typeof fields[key] === 'object') { | ||
254 | buildFields(req, fields[key], formKey) | ||
255 | } else { | ||
256 | req.field(formKey, fields[key]) | ||
257 | } | ||
258 | } | ||
259 | } | ||
diff --git a/shared/server-commands/runners/index.ts b/shared/server-commands/runners/index.ts deleted file mode 100644 index 9e8e1baf2..000000000 --- a/shared/server-commands/runners/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './runner-jobs-command' | ||
2 | export * from './runner-registration-tokens-command' | ||
3 | export * from './runners-command' | ||
diff --git a/shared/server-commands/runners/runner-jobs-command.ts b/shared/server-commands/runners/runner-jobs-command.ts deleted file mode 100644 index 0a0ffb5d3..000000000 --- a/shared/server-commands/runners/runner-jobs-command.ts +++ /dev/null | |||
@@ -1,294 +0,0 @@ | |||
1 | import { omit, pick, wait } from '@shared/core-utils' | ||
2 | import { | ||
3 | AbortRunnerJobBody, | ||
4 | AcceptRunnerJobBody, | ||
5 | AcceptRunnerJobResult, | ||
6 | ErrorRunnerJobBody, | ||
7 | HttpStatusCode, | ||
8 | isHLSTranscodingPayloadSuccess, | ||
9 | isLiveRTMPHLSTranscodingUpdatePayload, | ||
10 | isWebVideoOrAudioMergeTranscodingPayloadSuccess, | ||
11 | ListRunnerJobsQuery, | ||
12 | RequestRunnerJobBody, | ||
13 | RequestRunnerJobResult, | ||
14 | ResultList, | ||
15 | RunnerJobAdmin, | ||
16 | RunnerJobLiveRTMPHLSTranscodingPayload, | ||
17 | RunnerJobPayload, | ||
18 | RunnerJobState, | ||
19 | RunnerJobSuccessBody, | ||
20 | RunnerJobSuccessPayload, | ||
21 | RunnerJobType, | ||
22 | RunnerJobUpdateBody, | ||
23 | RunnerJobVODPayload | ||
24 | } from '@shared/models' | ||
25 | import { unwrapBody } from '../requests' | ||
26 | import { waitJobs } from '../server' | ||
27 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
28 | |||
29 | export class RunnerJobsCommand extends AbstractCommand { | ||
30 | |||
31 | list (options: OverrideCommandOptions & ListRunnerJobsQuery = {}) { | ||
32 | const path = '/api/v1/runners/jobs' | ||
33 | |||
34 | return this.getRequestBody<ResultList<RunnerJobAdmin>>({ | ||
35 | ...options, | ||
36 | |||
37 | path, | ||
38 | query: pick(options, [ 'start', 'count', 'sort', 'search', 'stateOneOf' ]), | ||
39 | implicitToken: true, | ||
40 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
41 | }) | ||
42 | } | ||
43 | |||
44 | cancelByAdmin (options: OverrideCommandOptions & { jobUUID: string }) { | ||
45 | const path = '/api/v1/runners/jobs/' + options.jobUUID + '/cancel' | ||
46 | |||
47 | return this.postBodyRequest({ | ||
48 | ...options, | ||
49 | |||
50 | path, | ||
51 | implicitToken: true, | ||
52 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
53 | }) | ||
54 | } | ||
55 | |||
56 | deleteByAdmin (options: OverrideCommandOptions & { jobUUID: string }) { | ||
57 | const path = '/api/v1/runners/jobs/' + options.jobUUID | ||
58 | |||
59 | return this.deleteRequest({ | ||
60 | ...options, | ||
61 | |||
62 | path, | ||
63 | implicitToken: true, | ||
64 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
65 | }) | ||
66 | } | ||
67 | |||
68 | // --------------------------------------------------------------------------- | ||
69 | |||
70 | request (options: OverrideCommandOptions & RequestRunnerJobBody) { | ||
71 | const path = '/api/v1/runners/jobs/request' | ||
72 | |||
73 | return unwrapBody<RequestRunnerJobResult>(this.postBodyRequest({ | ||
74 | ...options, | ||
75 | |||
76 | path, | ||
77 | fields: pick(options, [ 'runnerToken' ]), | ||
78 | implicitToken: false, | ||
79 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
80 | })) | ||
81 | } | ||
82 | |||
83 | async requestVOD (options: OverrideCommandOptions & RequestRunnerJobBody) { | ||
84 | const vodTypes = new Set<RunnerJobType>([ 'vod-audio-merge-transcoding', 'vod-hls-transcoding', 'vod-web-video-transcoding' ]) | ||
85 | |||
86 | const { availableJobs } = await this.request(options) | ||
87 | |||
88 | return { | ||
89 | availableJobs: availableJobs.filter(j => vodTypes.has(j.type)) | ||
90 | } as RequestRunnerJobResult<RunnerJobVODPayload> | ||
91 | } | ||
92 | |||
93 | async requestLive (options: OverrideCommandOptions & RequestRunnerJobBody) { | ||
94 | const vodTypes = new Set<RunnerJobType>([ 'live-rtmp-hls-transcoding' ]) | ||
95 | |||
96 | const { availableJobs } = await this.request(options) | ||
97 | |||
98 | return { | ||
99 | availableJobs: availableJobs.filter(j => vodTypes.has(j.type)) | ||
100 | } as RequestRunnerJobResult<RunnerJobLiveRTMPHLSTranscodingPayload> | ||
101 | } | ||
102 | |||
103 | // --------------------------------------------------------------------------- | ||
104 | |||
105 | accept <T extends RunnerJobPayload = RunnerJobPayload> (options: OverrideCommandOptions & AcceptRunnerJobBody & { jobUUID: string }) { | ||
106 | const path = '/api/v1/runners/jobs/' + options.jobUUID + '/accept' | ||
107 | |||
108 | return unwrapBody<AcceptRunnerJobResult<T>>(this.postBodyRequest({ | ||
109 | ...options, | ||
110 | |||
111 | path, | ||
112 | fields: pick(options, [ 'runnerToken' ]), | ||
113 | implicitToken: false, | ||
114 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
115 | })) | ||
116 | } | ||
117 | |||
118 | abort (options: OverrideCommandOptions & AbortRunnerJobBody & { jobUUID: string }) { | ||
119 | const path = '/api/v1/runners/jobs/' + options.jobUUID + '/abort' | ||
120 | |||
121 | return this.postBodyRequest({ | ||
122 | ...options, | ||
123 | |||
124 | path, | ||
125 | fields: pick(options, [ 'reason', 'jobToken', 'runnerToken' ]), | ||
126 | implicitToken: false, | ||
127 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
128 | }) | ||
129 | } | ||
130 | |||
131 | update (options: OverrideCommandOptions & RunnerJobUpdateBody & { jobUUID: string }) { | ||
132 | const path = '/api/v1/runners/jobs/' + options.jobUUID + '/update' | ||
133 | |||
134 | const { payload } = options | ||
135 | const attaches: { [id: string]: any } = {} | ||
136 | let payloadWithoutFiles = payload | ||
137 | |||
138 | if (isLiveRTMPHLSTranscodingUpdatePayload(payload)) { | ||
139 | if (payload.masterPlaylistFile) { | ||
140 | attaches[`payload[masterPlaylistFile]`] = payload.masterPlaylistFile | ||
141 | } | ||
142 | |||
143 | attaches[`payload[resolutionPlaylistFile]`] = payload.resolutionPlaylistFile | ||
144 | attaches[`payload[videoChunkFile]`] = payload.videoChunkFile | ||
145 | |||
146 | payloadWithoutFiles = omit(payloadWithoutFiles as any, [ 'masterPlaylistFile', 'resolutionPlaylistFile', 'videoChunkFile' ]) | ||
147 | } | ||
148 | |||
149 | return this.postUploadRequest({ | ||
150 | ...options, | ||
151 | |||
152 | path, | ||
153 | fields: { | ||
154 | ...pick(options, [ 'progress', 'jobToken', 'runnerToken' ]), | ||
155 | |||
156 | payload: payloadWithoutFiles | ||
157 | }, | ||
158 | attaches, | ||
159 | implicitToken: false, | ||
160 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
161 | }) | ||
162 | } | ||
163 | |||
164 | error (options: OverrideCommandOptions & ErrorRunnerJobBody & { jobUUID: string }) { | ||
165 | const path = '/api/v1/runners/jobs/' + options.jobUUID + '/error' | ||
166 | |||
167 | return this.postBodyRequest({ | ||
168 | ...options, | ||
169 | |||
170 | path, | ||
171 | fields: pick(options, [ 'message', 'jobToken', 'runnerToken' ]), | ||
172 | implicitToken: false, | ||
173 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
174 | }) | ||
175 | } | ||
176 | |||
177 | success (options: OverrideCommandOptions & RunnerJobSuccessBody & { jobUUID: string }) { | ||
178 | const { payload } = options | ||
179 | |||
180 | const path = '/api/v1/runners/jobs/' + options.jobUUID + '/success' | ||
181 | const attaches: { [id: string]: any } = {} | ||
182 | let payloadWithoutFiles = payload | ||
183 | |||
184 | if ((isWebVideoOrAudioMergeTranscodingPayloadSuccess(payload) || isHLSTranscodingPayloadSuccess(payload)) && payload.videoFile) { | ||
185 | attaches[`payload[videoFile]`] = payload.videoFile | ||
186 | |||
187 | payloadWithoutFiles = omit(payloadWithoutFiles as any, [ 'videoFile' ]) | ||
188 | } | ||
189 | |||
190 | if (isHLSTranscodingPayloadSuccess(payload) && payload.resolutionPlaylistFile) { | ||
191 | attaches[`payload[resolutionPlaylistFile]`] = payload.resolutionPlaylistFile | ||
192 | |||
193 | payloadWithoutFiles = omit(payloadWithoutFiles as any, [ 'resolutionPlaylistFile' ]) | ||
194 | } | ||
195 | |||
196 | return this.postUploadRequest({ | ||
197 | ...options, | ||
198 | |||
199 | path, | ||
200 | attaches, | ||
201 | fields: { | ||
202 | ...pick(options, [ 'jobToken', 'runnerToken' ]), | ||
203 | |||
204 | payload: payloadWithoutFiles | ||
205 | }, | ||
206 | implicitToken: false, | ||
207 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
208 | }) | ||
209 | } | ||
210 | |||
211 | getJobFile (options: OverrideCommandOptions & { url: string, jobToken: string, runnerToken: string }) { | ||
212 | const { host, protocol, pathname } = new URL(options.url) | ||
213 | |||
214 | return this.postBodyRequest({ | ||
215 | url: `${protocol}//${host}`, | ||
216 | path: pathname, | ||
217 | |||
218 | fields: pick(options, [ 'jobToken', 'runnerToken' ]), | ||
219 | implicitToken: false, | ||
220 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
221 | }) | ||
222 | } | ||
223 | |||
224 | // --------------------------------------------------------------------------- | ||
225 | |||
226 | async autoAccept (options: OverrideCommandOptions & RequestRunnerJobBody & { type?: RunnerJobType }) { | ||
227 | const { availableJobs } = await this.request(options) | ||
228 | |||
229 | const job = options.type | ||
230 | ? availableJobs.find(j => j.type === options.type) | ||
231 | : availableJobs[0] | ||
232 | |||
233 | return this.accept({ ...options, jobUUID: job.uuid }) | ||
234 | } | ||
235 | |||
236 | async autoProcessWebVideoJob (runnerToken: string, jobUUIDToProcess?: string) { | ||
237 | let jobUUID = jobUUIDToProcess | ||
238 | |||
239 | if (!jobUUID) { | ||
240 | const { availableJobs } = await this.request({ runnerToken }) | ||
241 | jobUUID = availableJobs[0].uuid | ||
242 | } | ||
243 | |||
244 | const { job } = await this.accept({ runnerToken, jobUUID }) | ||
245 | const jobToken = job.jobToken | ||
246 | |||
247 | const payload: RunnerJobSuccessPayload = { videoFile: 'video_short.mp4' } | ||
248 | await this.success({ runnerToken, jobUUID, jobToken, payload }) | ||
249 | |||
250 | await waitJobs([ this.server ]) | ||
251 | |||
252 | return job | ||
253 | } | ||
254 | |||
255 | async cancelAllJobs (options: { state?: RunnerJobState } = {}) { | ||
256 | const { state } = options | ||
257 | |||
258 | const { data } = await this.list({ count: 100 }) | ||
259 | |||
260 | const allowedStates = new Set<RunnerJobState>([ | ||
261 | RunnerJobState.PENDING, | ||
262 | RunnerJobState.PROCESSING, | ||
263 | RunnerJobState.WAITING_FOR_PARENT_JOB | ||
264 | ]) | ||
265 | |||
266 | for (const job of data) { | ||
267 | if (state && job.state.id !== state) continue | ||
268 | else if (allowedStates.has(job.state.id) !== true) continue | ||
269 | |||
270 | await this.cancelByAdmin({ jobUUID: job.uuid }) | ||
271 | } | ||
272 | } | ||
273 | |||
274 | async getJob (options: OverrideCommandOptions & { uuid: string }) { | ||
275 | const { data } = await this.list({ ...options, count: 100, sort: '-updatedAt' }) | ||
276 | |||
277 | return data.find(j => j.uuid === options.uuid) | ||
278 | } | ||
279 | |||
280 | async requestLiveJob (runnerToken: string) { | ||
281 | let availableJobs: RequestRunnerJobResult<RunnerJobLiveRTMPHLSTranscodingPayload>['availableJobs'] = [] | ||
282 | |||
283 | while (availableJobs.length === 0) { | ||
284 | const result = await this.requestLive({ runnerToken }) | ||
285 | availableJobs = result.availableJobs | ||
286 | |||
287 | if (availableJobs.length === 1) break | ||
288 | |||
289 | await wait(150) | ||
290 | } | ||
291 | |||
292 | return availableJobs[0] | ||
293 | } | ||
294 | } | ||
diff --git a/shared/server-commands/runners/runner-registration-tokens-command.ts b/shared/server-commands/runners/runner-registration-tokens-command.ts deleted file mode 100644 index e4f2e3d95..000000000 --- a/shared/server-commands/runners/runner-registration-tokens-command.ts +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { HttpStatusCode, ResultList, RunnerRegistrationToken } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class RunnerRegistrationTokensCommand extends AbstractCommand { | ||
6 | |||
7 | list (options: OverrideCommandOptions & { | ||
8 | start?: number | ||
9 | count?: number | ||
10 | sort?: string | ||
11 | } = {}) { | ||
12 | const path = '/api/v1/runners/registration-tokens' | ||
13 | |||
14 | return this.getRequestBody<ResultList<RunnerRegistrationToken>>({ | ||
15 | ...options, | ||
16 | |||
17 | path, | ||
18 | query: pick(options, [ 'start', 'count', 'sort' ]), | ||
19 | implicitToken: true, | ||
20 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
21 | }) | ||
22 | } | ||
23 | |||
24 | generate (options: OverrideCommandOptions = {}) { | ||
25 | const path = '/api/v1/runners/registration-tokens/generate' | ||
26 | |||
27 | return this.postBodyRequest({ | ||
28 | ...options, | ||
29 | |||
30 | path, | ||
31 | implicitToken: true, | ||
32 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
33 | }) | ||
34 | } | ||
35 | |||
36 | delete (options: OverrideCommandOptions & { | ||
37 | id: number | ||
38 | }) { | ||
39 | const path = '/api/v1/runners/registration-tokens/' + options.id | ||
40 | |||
41 | return this.deleteRequest({ | ||
42 | ...options, | ||
43 | |||
44 | path, | ||
45 | implicitToken: true, | ||
46 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
47 | }) | ||
48 | } | ||
49 | |||
50 | async getFirstRegistrationToken (options: OverrideCommandOptions = {}) { | ||
51 | const { data } = await this.list(options) | ||
52 | |||
53 | return data[0].registrationToken | ||
54 | } | ||
55 | } | ||
diff --git a/shared/server-commands/runners/runners-command.ts b/shared/server-commands/runners/runners-command.ts deleted file mode 100644 index b0083e841..000000000 --- a/shared/server-commands/runners/runners-command.ts +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { buildUUID } from '@shared/extra-utils' | ||
3 | import { HttpStatusCode, RegisterRunnerBody, RegisterRunnerResult, ResultList, Runner, UnregisterRunnerBody } from '@shared/models' | ||
4 | import { unwrapBody } from '../requests' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export class RunnersCommand extends AbstractCommand { | ||
8 | |||
9 | list (options: OverrideCommandOptions & { | ||
10 | start?: number | ||
11 | count?: number | ||
12 | sort?: string | ||
13 | } = {}) { | ||
14 | const path = '/api/v1/runners' | ||
15 | |||
16 | return this.getRequestBody<ResultList<Runner>>({ | ||
17 | ...options, | ||
18 | |||
19 | path, | ||
20 | query: pick(options, [ 'start', 'count', 'sort' ]), | ||
21 | implicitToken: true, | ||
22 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
23 | }) | ||
24 | } | ||
25 | |||
26 | register (options: OverrideCommandOptions & RegisterRunnerBody) { | ||
27 | const path = '/api/v1/runners/register' | ||
28 | |||
29 | return unwrapBody<RegisterRunnerResult>(this.postBodyRequest({ | ||
30 | ...options, | ||
31 | |||
32 | path, | ||
33 | fields: pick(options, [ 'name', 'registrationToken', 'description' ]), | ||
34 | implicitToken: true, | ||
35 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
36 | })) | ||
37 | } | ||
38 | |||
39 | unregister (options: OverrideCommandOptions & UnregisterRunnerBody) { | ||
40 | const path = '/api/v1/runners/unregister' | ||
41 | |||
42 | return this.postBodyRequest({ | ||
43 | ...options, | ||
44 | |||
45 | path, | ||
46 | fields: pick(options, [ 'runnerToken' ]), | ||
47 | implicitToken: false, | ||
48 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
49 | }) | ||
50 | } | ||
51 | |||
52 | delete (options: OverrideCommandOptions & { | ||
53 | id: number | ||
54 | }) { | ||
55 | const path = '/api/v1/runners/' + options.id | ||
56 | |||
57 | return this.deleteRequest({ | ||
58 | ...options, | ||
59 | |||
60 | path, | ||
61 | implicitToken: true, | ||
62 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
63 | }) | ||
64 | } | ||
65 | |||
66 | // --------------------------------------------------------------------------- | ||
67 | |||
68 | async autoRegisterRunner () { | ||
69 | const { data } = await this.server.runnerRegistrationTokens.list({ sort: 'createdAt' }) | ||
70 | |||
71 | const { runnerToken } = await this.register({ | ||
72 | name: 'runner ' + buildUUID(), | ||
73 | registrationToken: data[0].registrationToken | ||
74 | }) | ||
75 | |||
76 | return runnerToken | ||
77 | } | ||
78 | } | ||
diff --git a/shared/server-commands/search/index.ts b/shared/server-commands/search/index.ts deleted file mode 100644 index 48dbe8ae9..000000000 --- a/shared/server-commands/search/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './search-command' | ||
diff --git a/shared/server-commands/search/search-command.ts b/shared/server-commands/search/search-command.ts deleted file mode 100644 index a5b498b66..000000000 --- a/shared/server-commands/search/search-command.ts +++ /dev/null | |||
@@ -1,98 +0,0 @@ | |||
1 | import { | ||
2 | HttpStatusCode, | ||
3 | ResultList, | ||
4 | Video, | ||
5 | VideoChannel, | ||
6 | VideoChannelsSearchQuery, | ||
7 | VideoPlaylist, | ||
8 | VideoPlaylistsSearchQuery, | ||
9 | VideosSearchQuery | ||
10 | } from '@shared/models' | ||
11 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
12 | |||
13 | export class SearchCommand extends AbstractCommand { | ||
14 | |||
15 | searchChannels (options: OverrideCommandOptions & { | ||
16 | search: string | ||
17 | }) { | ||
18 | return this.advancedChannelSearch({ | ||
19 | ...options, | ||
20 | |||
21 | search: { search: options.search } | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | advancedChannelSearch (options: OverrideCommandOptions & { | ||
26 | search: VideoChannelsSearchQuery | ||
27 | }) { | ||
28 | const { search } = options | ||
29 | const path = '/api/v1/search/video-channels' | ||
30 | |||
31 | return this.getRequestBody<ResultList<VideoChannel>>({ | ||
32 | ...options, | ||
33 | |||
34 | path, | ||
35 | query: search, | ||
36 | implicitToken: false, | ||
37 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
38 | }) | ||
39 | } | ||
40 | |||
41 | searchPlaylists (options: OverrideCommandOptions & { | ||
42 | search: string | ||
43 | }) { | ||
44 | return this.advancedPlaylistSearch({ | ||
45 | ...options, | ||
46 | |||
47 | search: { search: options.search } | ||
48 | }) | ||
49 | } | ||
50 | |||
51 | advancedPlaylistSearch (options: OverrideCommandOptions & { | ||
52 | search: VideoPlaylistsSearchQuery | ||
53 | }) { | ||
54 | const { search } = options | ||
55 | const path = '/api/v1/search/video-playlists' | ||
56 | |||
57 | return this.getRequestBody<ResultList<VideoPlaylist>>({ | ||
58 | ...options, | ||
59 | |||
60 | path, | ||
61 | query: search, | ||
62 | implicitToken: false, | ||
63 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
64 | }) | ||
65 | } | ||
66 | |||
67 | searchVideos (options: OverrideCommandOptions & { | ||
68 | search: string | ||
69 | sort?: string | ||
70 | }) { | ||
71 | const { search, sort } = options | ||
72 | |||
73 | return this.advancedVideoSearch({ | ||
74 | ...options, | ||
75 | |||
76 | search: { | ||
77 | search, | ||
78 | sort: sort ?? '-publishedAt' | ||
79 | } | ||
80 | }) | ||
81 | } | ||
82 | |||
83 | advancedVideoSearch (options: OverrideCommandOptions & { | ||
84 | search: VideosSearchQuery | ||
85 | }) { | ||
86 | const { search } = options | ||
87 | const path = '/api/v1/search/videos' | ||
88 | |||
89 | return this.getRequestBody<ResultList<Video>>({ | ||
90 | ...options, | ||
91 | |||
92 | path, | ||
93 | query: search, | ||
94 | implicitToken: false, | ||
95 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
96 | }) | ||
97 | } | ||
98 | } | ||
diff --git a/shared/server-commands/server/config-command.ts b/shared/server-commands/server/config-command.ts deleted file mode 100644 index 5ee2fe021..000000000 --- a/shared/server-commands/server/config-command.ts +++ /dev/null | |||
@@ -1,576 +0,0 @@ | |||
1 | import { merge } from 'lodash' | ||
2 | import { About, CustomConfig, HttpStatusCode, ServerConfig } from '@shared/models' | ||
3 | import { DeepPartial } from '@shared/typescript-utils' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared/abstract-command' | ||
5 | |||
6 | export class ConfigCommand extends AbstractCommand { | ||
7 | |||
8 | static getCustomConfigResolutions (enabled: boolean, with0p = false) { | ||
9 | return { | ||
10 | '0p': enabled && with0p, | ||
11 | '144p': enabled, | ||
12 | '240p': enabled, | ||
13 | '360p': enabled, | ||
14 | '480p': enabled, | ||
15 | '720p': enabled, | ||
16 | '1080p': enabled, | ||
17 | '1440p': enabled, | ||
18 | '2160p': enabled | ||
19 | } | ||
20 | } | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
23 | |||
24 | static getEmailOverrideConfig (emailPort: number) { | ||
25 | return { | ||
26 | smtp: { | ||
27 | hostname: '127.0.0.1', | ||
28 | port: emailPort | ||
29 | } | ||
30 | } | ||
31 | } | ||
32 | |||
33 | // --------------------------------------------------------------------------- | ||
34 | |||
35 | enableSignup (requiresApproval: boolean, limit = -1) { | ||
36 | return this.updateExistingSubConfig({ | ||
37 | newConfig: { | ||
38 | signup: { | ||
39 | enabled: true, | ||
40 | requiresApproval, | ||
41 | limit | ||
42 | } | ||
43 | } | ||
44 | }) | ||
45 | } | ||
46 | |||
47 | // --------------------------------------------------------------------------- | ||
48 | |||
49 | disableImports () { | ||
50 | return this.setImportsEnabled(false) | ||
51 | } | ||
52 | |||
53 | enableImports () { | ||
54 | return this.setImportsEnabled(true) | ||
55 | } | ||
56 | |||
57 | private setImportsEnabled (enabled: boolean) { | ||
58 | return this.updateExistingSubConfig({ | ||
59 | newConfig: { | ||
60 | import: { | ||
61 | videos: { | ||
62 | http: { | ||
63 | enabled | ||
64 | }, | ||
65 | |||
66 | torrent: { | ||
67 | enabled | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | }) | ||
73 | } | ||
74 | |||
75 | // --------------------------------------------------------------------------- | ||
76 | |||
77 | disableFileUpdate () { | ||
78 | return this.setFileUpdateEnabled(false) | ||
79 | } | ||
80 | |||
81 | enableFileUpdate () { | ||
82 | return this.setFileUpdateEnabled(true) | ||
83 | } | ||
84 | |||
85 | private setFileUpdateEnabled (enabled: boolean) { | ||
86 | return this.updateExistingSubConfig({ | ||
87 | newConfig: { | ||
88 | videoFile: { | ||
89 | update: { | ||
90 | enabled | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | }) | ||
95 | } | ||
96 | |||
97 | // --------------------------------------------------------------------------- | ||
98 | |||
99 | enableChannelSync () { | ||
100 | return this.setChannelSyncEnabled(true) | ||
101 | } | ||
102 | |||
103 | disableChannelSync () { | ||
104 | return this.setChannelSyncEnabled(false) | ||
105 | } | ||
106 | |||
107 | private setChannelSyncEnabled (enabled: boolean) { | ||
108 | return this.updateExistingSubConfig({ | ||
109 | newConfig: { | ||
110 | import: { | ||
111 | videoChannelSynchronization: { | ||
112 | enabled | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | }) | ||
117 | } | ||
118 | |||
119 | // --------------------------------------------------------------------------- | ||
120 | |||
121 | enableLive (options: { | ||
122 | allowReplay?: boolean | ||
123 | transcoding?: boolean | ||
124 | resolutions?: 'min' | 'max' // Default max | ||
125 | } = {}) { | ||
126 | const { allowReplay, transcoding, resolutions = 'max' } = options | ||
127 | |||
128 | return this.updateExistingSubConfig({ | ||
129 | newConfig: { | ||
130 | live: { | ||
131 | enabled: true, | ||
132 | allowReplay: allowReplay ?? true, | ||
133 | transcoding: { | ||
134 | enabled: transcoding ?? true, | ||
135 | resolutions: ConfigCommand.getCustomConfigResolutions(resolutions === 'max') | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | }) | ||
140 | } | ||
141 | |||
142 | disableTranscoding () { | ||
143 | return this.updateExistingSubConfig({ | ||
144 | newConfig: { | ||
145 | transcoding: { | ||
146 | enabled: false | ||
147 | }, | ||
148 | videoStudio: { | ||
149 | enabled: false | ||
150 | } | ||
151 | } | ||
152 | }) | ||
153 | } | ||
154 | |||
155 | enableTranscoding (options: { | ||
156 | webVideo?: boolean // default true | ||
157 | hls?: boolean // default true | ||
158 | with0p?: boolean // default false | ||
159 | } = {}) { | ||
160 | const { webVideo = true, hls = true, with0p = false } = options | ||
161 | |||
162 | return this.updateExistingSubConfig({ | ||
163 | newConfig: { | ||
164 | transcoding: { | ||
165 | enabled: true, | ||
166 | |||
167 | allowAudioFiles: true, | ||
168 | allowAdditionalExtensions: true, | ||
169 | |||
170 | resolutions: ConfigCommand.getCustomConfigResolutions(true, with0p), | ||
171 | |||
172 | webVideos: { | ||
173 | enabled: webVideo | ||
174 | }, | ||
175 | hls: { | ||
176 | enabled: hls | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | }) | ||
181 | } | ||
182 | |||
183 | enableMinimumTranscoding (options: { | ||
184 | webVideo?: boolean // default true | ||
185 | hls?: boolean // default true | ||
186 | } = {}) { | ||
187 | const { webVideo = true, hls = true } = options | ||
188 | |||
189 | return this.updateExistingSubConfig({ | ||
190 | newConfig: { | ||
191 | transcoding: { | ||
192 | enabled: true, | ||
193 | |||
194 | allowAudioFiles: true, | ||
195 | allowAdditionalExtensions: true, | ||
196 | |||
197 | resolutions: { | ||
198 | ...ConfigCommand.getCustomConfigResolutions(false), | ||
199 | |||
200 | '240p': true | ||
201 | }, | ||
202 | |||
203 | webVideos: { | ||
204 | enabled: webVideo | ||
205 | }, | ||
206 | hls: { | ||
207 | enabled: hls | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | }) | ||
212 | } | ||
213 | |||
214 | enableRemoteTranscoding () { | ||
215 | return this.updateExistingSubConfig({ | ||
216 | newConfig: { | ||
217 | transcoding: { | ||
218 | remoteRunners: { | ||
219 | enabled: true | ||
220 | } | ||
221 | }, | ||
222 | live: { | ||
223 | transcoding: { | ||
224 | remoteRunners: { | ||
225 | enabled: true | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | }) | ||
231 | } | ||
232 | |||
233 | enableRemoteStudio () { | ||
234 | return this.updateExistingSubConfig({ | ||
235 | newConfig: { | ||
236 | videoStudio: { | ||
237 | remoteRunners: { | ||
238 | enabled: true | ||
239 | } | ||
240 | } | ||
241 | } | ||
242 | }) | ||
243 | } | ||
244 | |||
245 | // --------------------------------------------------------------------------- | ||
246 | |||
247 | enableStudio () { | ||
248 | return this.updateExistingSubConfig({ | ||
249 | newConfig: { | ||
250 | videoStudio: { | ||
251 | enabled: true | ||
252 | } | ||
253 | } | ||
254 | }) | ||
255 | } | ||
256 | |||
257 | // --------------------------------------------------------------------------- | ||
258 | |||
259 | getConfig (options: OverrideCommandOptions = {}) { | ||
260 | const path = '/api/v1/config' | ||
261 | |||
262 | return this.getRequestBody<ServerConfig>({ | ||
263 | ...options, | ||
264 | |||
265 | path, | ||
266 | implicitToken: false, | ||
267 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
268 | }) | ||
269 | } | ||
270 | |||
271 | async getIndexHTMLConfig (options: OverrideCommandOptions = {}) { | ||
272 | const text = await this.getRequestText({ | ||
273 | ...options, | ||
274 | |||
275 | path: '/', | ||
276 | implicitToken: false, | ||
277 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
278 | }) | ||
279 | |||
280 | const match = text.match('<script type="application/javascript">window.PeerTubeServerConfig = (".+?")</script>') | ||
281 | |||
282 | // We parse the string twice, first to extract the string and then to extract the JSON | ||
283 | return JSON.parse(JSON.parse(match[1])) as ServerConfig | ||
284 | } | ||
285 | |||
286 | getAbout (options: OverrideCommandOptions = {}) { | ||
287 | const path = '/api/v1/config/about' | ||
288 | |||
289 | return this.getRequestBody<About>({ | ||
290 | ...options, | ||
291 | |||
292 | path, | ||
293 | implicitToken: false, | ||
294 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
295 | }) | ||
296 | } | ||
297 | |||
298 | getCustomConfig (options: OverrideCommandOptions = {}) { | ||
299 | const path = '/api/v1/config/custom' | ||
300 | |||
301 | return this.getRequestBody<CustomConfig>({ | ||
302 | ...options, | ||
303 | |||
304 | path, | ||
305 | implicitToken: true, | ||
306 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
307 | }) | ||
308 | } | ||
309 | |||
310 | updateCustomConfig (options: OverrideCommandOptions & { | ||
311 | newCustomConfig: CustomConfig | ||
312 | }) { | ||
313 | const path = '/api/v1/config/custom' | ||
314 | |||
315 | return this.putBodyRequest({ | ||
316 | ...options, | ||
317 | |||
318 | path, | ||
319 | fields: options.newCustomConfig, | ||
320 | implicitToken: true, | ||
321 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
322 | }) | ||
323 | } | ||
324 | |||
325 | deleteCustomConfig (options: OverrideCommandOptions = {}) { | ||
326 | const path = '/api/v1/config/custom' | ||
327 | |||
328 | return this.deleteRequest({ | ||
329 | ...options, | ||
330 | |||
331 | path, | ||
332 | implicitToken: true, | ||
333 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
334 | }) | ||
335 | } | ||
336 | |||
337 | async updateExistingSubConfig (options: OverrideCommandOptions & { | ||
338 | newConfig: DeepPartial<CustomConfig> | ||
339 | }) { | ||
340 | const existing = await this.getCustomConfig({ ...options, expectedStatus: HttpStatusCode.OK_200 }) | ||
341 | |||
342 | return this.updateCustomConfig({ ...options, newCustomConfig: merge({}, existing, options.newConfig) }) | ||
343 | } | ||
344 | |||
345 | updateCustomSubConfig (options: OverrideCommandOptions & { | ||
346 | newConfig: DeepPartial<CustomConfig> | ||
347 | }) { | ||
348 | const newCustomConfig: CustomConfig = { | ||
349 | instance: { | ||
350 | name: 'PeerTube updated', | ||
351 | shortDescription: 'my short description', | ||
352 | description: 'my super description', | ||
353 | terms: 'my super terms', | ||
354 | codeOfConduct: 'my super coc', | ||
355 | |||
356 | creationReason: 'my super creation reason', | ||
357 | moderationInformation: 'my super moderation information', | ||
358 | administrator: 'Kuja', | ||
359 | maintenanceLifetime: 'forever', | ||
360 | businessModel: 'my super business model', | ||
361 | hardwareInformation: '2vCore 3GB RAM', | ||
362 | |||
363 | languages: [ 'en', 'es' ], | ||
364 | categories: [ 1, 2 ], | ||
365 | |||
366 | isNSFW: true, | ||
367 | defaultNSFWPolicy: 'blur', | ||
368 | |||
369 | defaultClientRoute: '/videos/recently-added', | ||
370 | |||
371 | customizations: { | ||
372 | javascript: 'alert("coucou")', | ||
373 | css: 'body { background-color: red; }' | ||
374 | } | ||
375 | }, | ||
376 | theme: { | ||
377 | default: 'default' | ||
378 | }, | ||
379 | services: { | ||
380 | twitter: { | ||
381 | username: '@MySuperUsername', | ||
382 | whitelisted: true | ||
383 | } | ||
384 | }, | ||
385 | client: { | ||
386 | videos: { | ||
387 | miniature: { | ||
388 | preferAuthorDisplayName: false | ||
389 | } | ||
390 | }, | ||
391 | menu: { | ||
392 | login: { | ||
393 | redirectOnSingleExternalAuth: false | ||
394 | } | ||
395 | } | ||
396 | }, | ||
397 | cache: { | ||
398 | previews: { | ||
399 | size: 2 | ||
400 | }, | ||
401 | captions: { | ||
402 | size: 3 | ||
403 | }, | ||
404 | torrents: { | ||
405 | size: 4 | ||
406 | }, | ||
407 | storyboards: { | ||
408 | size: 5 | ||
409 | } | ||
410 | }, | ||
411 | signup: { | ||
412 | enabled: false, | ||
413 | limit: 5, | ||
414 | requiresApproval: true, | ||
415 | requiresEmailVerification: false, | ||
416 | minimumAge: 16 | ||
417 | }, | ||
418 | admin: { | ||
419 | email: 'superadmin1@example.com' | ||
420 | }, | ||
421 | contactForm: { | ||
422 | enabled: true | ||
423 | }, | ||
424 | user: { | ||
425 | history: { | ||
426 | videos: { | ||
427 | enabled: true | ||
428 | } | ||
429 | }, | ||
430 | videoQuota: 5242881, | ||
431 | videoQuotaDaily: 318742 | ||
432 | }, | ||
433 | videoChannels: { | ||
434 | maxPerUser: 20 | ||
435 | }, | ||
436 | transcoding: { | ||
437 | enabled: true, | ||
438 | remoteRunners: { | ||
439 | enabled: false | ||
440 | }, | ||
441 | allowAdditionalExtensions: true, | ||
442 | allowAudioFiles: true, | ||
443 | threads: 1, | ||
444 | concurrency: 3, | ||
445 | profile: 'default', | ||
446 | resolutions: { | ||
447 | '0p': false, | ||
448 | '144p': false, | ||
449 | '240p': false, | ||
450 | '360p': true, | ||
451 | '480p': true, | ||
452 | '720p': false, | ||
453 | '1080p': false, | ||
454 | '1440p': false, | ||
455 | '2160p': false | ||
456 | }, | ||
457 | alwaysTranscodeOriginalResolution: true, | ||
458 | webVideos: { | ||
459 | enabled: true | ||
460 | }, | ||
461 | hls: { | ||
462 | enabled: false | ||
463 | } | ||
464 | }, | ||
465 | live: { | ||
466 | enabled: true, | ||
467 | allowReplay: false, | ||
468 | latencySetting: { | ||
469 | enabled: false | ||
470 | }, | ||
471 | maxDuration: -1, | ||
472 | maxInstanceLives: -1, | ||
473 | maxUserLives: 50, | ||
474 | transcoding: { | ||
475 | enabled: true, | ||
476 | remoteRunners: { | ||
477 | enabled: false | ||
478 | }, | ||
479 | threads: 4, | ||
480 | profile: 'default', | ||
481 | resolutions: { | ||
482 | '144p': true, | ||
483 | '240p': true, | ||
484 | '360p': true, | ||
485 | '480p': true, | ||
486 | '720p': true, | ||
487 | '1080p': true, | ||
488 | '1440p': true, | ||
489 | '2160p': true | ||
490 | }, | ||
491 | alwaysTranscodeOriginalResolution: true | ||
492 | } | ||
493 | }, | ||
494 | videoStudio: { | ||
495 | enabled: false, | ||
496 | remoteRunners: { | ||
497 | enabled: false | ||
498 | } | ||
499 | }, | ||
500 | videoFile: { | ||
501 | update: { | ||
502 | enabled: false | ||
503 | } | ||
504 | }, | ||
505 | import: { | ||
506 | videos: { | ||
507 | concurrency: 3, | ||
508 | http: { | ||
509 | enabled: false | ||
510 | }, | ||
511 | torrent: { | ||
512 | enabled: false | ||
513 | } | ||
514 | }, | ||
515 | videoChannelSynchronization: { | ||
516 | enabled: false, | ||
517 | maxPerUser: 10 | ||
518 | } | ||
519 | }, | ||
520 | trending: { | ||
521 | videos: { | ||
522 | algorithms: { | ||
523 | enabled: [ 'hot', 'most-viewed', 'most-liked' ], | ||
524 | default: 'hot' | ||
525 | } | ||
526 | } | ||
527 | }, | ||
528 | autoBlacklist: { | ||
529 | videos: { | ||
530 | ofUsers: { | ||
531 | enabled: false | ||
532 | } | ||
533 | } | ||
534 | }, | ||
535 | followers: { | ||
536 | instance: { | ||
537 | enabled: true, | ||
538 | manualApproval: false | ||
539 | } | ||
540 | }, | ||
541 | followings: { | ||
542 | instance: { | ||
543 | autoFollowBack: { | ||
544 | enabled: false | ||
545 | }, | ||
546 | autoFollowIndex: { | ||
547 | indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', | ||
548 | enabled: false | ||
549 | } | ||
550 | } | ||
551 | }, | ||
552 | broadcastMessage: { | ||
553 | enabled: true, | ||
554 | level: 'warning', | ||
555 | message: 'hello', | ||
556 | dismissable: true | ||
557 | }, | ||
558 | search: { | ||
559 | remoteUri: { | ||
560 | users: true, | ||
561 | anonymous: true | ||
562 | }, | ||
563 | searchIndex: { | ||
564 | enabled: true, | ||
565 | url: 'https://search.joinpeertube.org', | ||
566 | disableLocalSearch: true, | ||
567 | isDefaultSearch: true | ||
568 | } | ||
569 | } | ||
570 | } | ||
571 | |||
572 | merge(newCustomConfig, options.newConfig) | ||
573 | |||
574 | return this.updateCustomConfig({ ...options, newCustomConfig }) | ||
575 | } | ||
576 | } | ||
diff --git a/shared/server-commands/server/contact-form-command.ts b/shared/server-commands/server/contact-form-command.ts deleted file mode 100644 index 0e8fd6d84..000000000 --- a/shared/server-commands/server/contact-form-command.ts +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | import { HttpStatusCode } from '@shared/models' | ||
2 | import { ContactForm } from '../../models/server' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class ContactFormCommand extends AbstractCommand { | ||
6 | |||
7 | send (options: OverrideCommandOptions & { | ||
8 | fromEmail: string | ||
9 | fromName: string | ||
10 | subject: string | ||
11 | body: string | ||
12 | }) { | ||
13 | const path = '/api/v1/server/contact' | ||
14 | |||
15 | const body: ContactForm = { | ||
16 | fromEmail: options.fromEmail, | ||
17 | fromName: options.fromName, | ||
18 | subject: options.subject, | ||
19 | body: options.body | ||
20 | } | ||
21 | |||
22 | return this.postBodyRequest({ | ||
23 | ...options, | ||
24 | |||
25 | path, | ||
26 | fields: body, | ||
27 | implicitToken: false, | ||
28 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
29 | }) | ||
30 | } | ||
31 | } | ||
diff --git a/shared/server-commands/server/debug-command.ts b/shared/server-commands/server/debug-command.ts deleted file mode 100644 index 3c5a785bb..000000000 --- a/shared/server-commands/server/debug-command.ts +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | import { Debug, HttpStatusCode, SendDebugCommand } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class DebugCommand extends AbstractCommand { | ||
5 | |||
6 | getDebug (options: OverrideCommandOptions = {}) { | ||
7 | const path = '/api/v1/server/debug' | ||
8 | |||
9 | return this.getRequestBody<Debug>({ | ||
10 | ...options, | ||
11 | |||
12 | path, | ||
13 | implicitToken: true, | ||
14 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
15 | }) | ||
16 | } | ||
17 | |||
18 | sendCommand (options: OverrideCommandOptions & { | ||
19 | body: SendDebugCommand | ||
20 | }) { | ||
21 | const { body } = options | ||
22 | const path = '/api/v1/server/debug/run-command' | ||
23 | |||
24 | return this.postBodyRequest({ | ||
25 | ...options, | ||
26 | |||
27 | path, | ||
28 | fields: body, | ||
29 | implicitToken: true, | ||
30 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
31 | }) | ||
32 | } | ||
33 | } | ||
diff --git a/shared/server-commands/server/follows-command.ts b/shared/server-commands/server/follows-command.ts deleted file mode 100644 index 496e11df1..000000000 --- a/shared/server-commands/server/follows-command.ts +++ /dev/null | |||
@@ -1,139 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList, ServerFollowCreate } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | import { PeerTubeServer } from './server' | ||
5 | |||
6 | export class FollowsCommand extends AbstractCommand { | ||
7 | |||
8 | getFollowers (options: OverrideCommandOptions & { | ||
9 | start?: number | ||
10 | count?: number | ||
11 | sort?: string | ||
12 | search?: string | ||
13 | actorType?: ActivityPubActorType | ||
14 | state?: FollowState | ||
15 | } = {}) { | ||
16 | const path = '/api/v1/server/followers' | ||
17 | |||
18 | const query = pick(options, [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]) | ||
19 | |||
20 | return this.getRequestBody<ResultList<ActorFollow>>({ | ||
21 | ...options, | ||
22 | |||
23 | path, | ||
24 | query, | ||
25 | implicitToken: false, | ||
26 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
27 | }) | ||
28 | } | ||
29 | |||
30 | getFollowings (options: OverrideCommandOptions & { | ||
31 | start?: number | ||
32 | count?: number | ||
33 | sort?: string | ||
34 | search?: string | ||
35 | actorType?: ActivityPubActorType | ||
36 | state?: FollowState | ||
37 | } = {}) { | ||
38 | const path = '/api/v1/server/following' | ||
39 | |||
40 | const query = pick(options, [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]) | ||
41 | |||
42 | return this.getRequestBody<ResultList<ActorFollow>>({ | ||
43 | ...options, | ||
44 | |||
45 | path, | ||
46 | query, | ||
47 | implicitToken: false, | ||
48 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
49 | }) | ||
50 | } | ||
51 | |||
52 | follow (options: OverrideCommandOptions & { | ||
53 | hosts?: string[] | ||
54 | handles?: string[] | ||
55 | }) { | ||
56 | const path = '/api/v1/server/following' | ||
57 | |||
58 | const fields: ServerFollowCreate = {} | ||
59 | |||
60 | if (options.hosts) { | ||
61 | fields.hosts = options.hosts.map(f => f.replace(/^http:\/\//, '')) | ||
62 | } | ||
63 | |||
64 | if (options.handles) { | ||
65 | fields.handles = options.handles | ||
66 | } | ||
67 | |||
68 | return this.postBodyRequest({ | ||
69 | ...options, | ||
70 | |||
71 | path, | ||
72 | fields, | ||
73 | implicitToken: true, | ||
74 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
75 | }) | ||
76 | } | ||
77 | |||
78 | async unfollow (options: OverrideCommandOptions & { | ||
79 | target: PeerTubeServer | string | ||
80 | }) { | ||
81 | const { target } = options | ||
82 | |||
83 | const handle = typeof target === 'string' | ||
84 | ? target | ||
85 | : target.host | ||
86 | |||
87 | const path = '/api/v1/server/following/' + handle | ||
88 | |||
89 | return this.deleteRequest({ | ||
90 | ...options, | ||
91 | |||
92 | path, | ||
93 | implicitToken: true, | ||
94 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
95 | }) | ||
96 | } | ||
97 | |||
98 | acceptFollower (options: OverrideCommandOptions & { | ||
99 | follower: string | ||
100 | }) { | ||
101 | const path = '/api/v1/server/followers/' + options.follower + '/accept' | ||
102 | |||
103 | return this.postBodyRequest({ | ||
104 | ...options, | ||
105 | |||
106 | path, | ||
107 | implicitToken: true, | ||
108 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
109 | }) | ||
110 | } | ||
111 | |||
112 | rejectFollower (options: OverrideCommandOptions & { | ||
113 | follower: string | ||
114 | }) { | ||
115 | const path = '/api/v1/server/followers/' + options.follower + '/reject' | ||
116 | |||
117 | return this.postBodyRequest({ | ||
118 | ...options, | ||
119 | |||
120 | path, | ||
121 | implicitToken: true, | ||
122 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
123 | }) | ||
124 | } | ||
125 | |||
126 | removeFollower (options: OverrideCommandOptions & { | ||
127 | follower: PeerTubeServer | ||
128 | }) { | ||
129 | const path = '/api/v1/server/followers/peertube@' + options.follower.host | ||
130 | |||
131 | return this.deleteRequest({ | ||
132 | ...options, | ||
133 | |||
134 | path, | ||
135 | implicitToken: true, | ||
136 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
137 | }) | ||
138 | } | ||
139 | } | ||
diff --git a/shared/server-commands/server/follows.ts b/shared/server-commands/server/follows.ts deleted file mode 100644 index 698238f29..000000000 --- a/shared/server-commands/server/follows.ts +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | import { waitJobs } from './jobs' | ||
2 | import { PeerTubeServer } from './server' | ||
3 | |||
4 | async function doubleFollow (server1: PeerTubeServer, server2: PeerTubeServer) { | ||
5 | await Promise.all([ | ||
6 | server1.follows.follow({ hosts: [ server2.url ] }), | ||
7 | server2.follows.follow({ hosts: [ server1.url ] }) | ||
8 | ]) | ||
9 | |||
10 | // Wait request propagation | ||
11 | await waitJobs([ server1, server2 ]) | ||
12 | |||
13 | return true | ||
14 | } | ||
15 | |||
16 | // --------------------------------------------------------------------------- | ||
17 | |||
18 | export { | ||
19 | doubleFollow | ||
20 | } | ||
diff --git a/shared/server-commands/server/index.ts b/shared/server-commands/server/index.ts deleted file mode 100644 index 9a2fbf8d3..000000000 --- a/shared/server-commands/server/index.ts +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | export * from './config-command' | ||
2 | export * from './contact-form-command' | ||
3 | export * from './debug-command' | ||
4 | export * from './follows-command' | ||
5 | export * from './follows' | ||
6 | export * from './jobs' | ||
7 | export * from './jobs-command' | ||
8 | export * from './metrics-command' | ||
9 | export * from './object-storage-command' | ||
10 | export * from './plugins-command' | ||
11 | export * from './redundancy-command' | ||
12 | export * from './server' | ||
13 | export * from './servers-command' | ||
14 | export * from './servers' | ||
15 | export * from './stats-command' | ||
diff --git a/shared/server-commands/server/jobs-command.ts b/shared/server-commands/server/jobs-command.ts deleted file mode 100644 index b8790ea00..000000000 --- a/shared/server-commands/server/jobs-command.ts +++ /dev/null | |||
@@ -1,84 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { HttpStatusCode, Job, JobState, JobType, ResultList } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class JobsCommand extends AbstractCommand { | ||
6 | |||
7 | async getLatest (options: OverrideCommandOptions & { | ||
8 | jobType: JobType | ||
9 | }) { | ||
10 | const { data } = await this.list({ ...options, start: 0, count: 1, sort: '-createdAt' }) | ||
11 | |||
12 | if (data.length === 0) return undefined | ||
13 | |||
14 | return data[0] | ||
15 | } | ||
16 | |||
17 | pauseJobQueue (options: OverrideCommandOptions = {}) { | ||
18 | const path = '/api/v1/jobs/pause' | ||
19 | |||
20 | return this.postBodyRequest({ | ||
21 | ...options, | ||
22 | |||
23 | path, | ||
24 | implicitToken: true, | ||
25 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
26 | }) | ||
27 | } | ||
28 | |||
29 | resumeJobQueue (options: OverrideCommandOptions = {}) { | ||
30 | const path = '/api/v1/jobs/resume' | ||
31 | |||
32 | return this.postBodyRequest({ | ||
33 | ...options, | ||
34 | |||
35 | path, | ||
36 | implicitToken: true, | ||
37 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
38 | }) | ||
39 | } | ||
40 | |||
41 | list (options: OverrideCommandOptions & { | ||
42 | state?: JobState | ||
43 | jobType?: JobType | ||
44 | start?: number | ||
45 | count?: number | ||
46 | sort?: string | ||
47 | } = {}) { | ||
48 | const path = this.buildJobsUrl(options.state) | ||
49 | |||
50 | const query = pick(options, [ 'start', 'count', 'sort', 'jobType' ]) | ||
51 | |||
52 | return this.getRequestBody<ResultList<Job>>({ | ||
53 | ...options, | ||
54 | |||
55 | path, | ||
56 | query, | ||
57 | implicitToken: true, | ||
58 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
59 | }) | ||
60 | } | ||
61 | |||
62 | listFailed (options: OverrideCommandOptions & { | ||
63 | jobType?: JobType | ||
64 | }) { | ||
65 | const path = this.buildJobsUrl('failed') | ||
66 | |||
67 | return this.getRequestBody<ResultList<Job>>({ | ||
68 | ...options, | ||
69 | |||
70 | path, | ||
71 | query: { start: 0, count: 50 }, | ||
72 | implicitToken: true, | ||
73 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
74 | }) | ||
75 | } | ||
76 | |||
77 | private buildJobsUrl (state?: JobState) { | ||
78 | let path = '/api/v1/jobs' | ||
79 | |||
80 | if (state) path += '/' + state | ||
81 | |||
82 | return path | ||
83 | } | ||
84 | } | ||
diff --git a/shared/server-commands/server/jobs.ts b/shared/server-commands/server/jobs.ts deleted file mode 100644 index 8f131fba4..000000000 --- a/shared/server-commands/server/jobs.ts +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | |||
2 | import { expect } from 'chai' | ||
3 | import { wait } from '@shared/core-utils' | ||
4 | import { JobState, JobType, RunnerJobState } from '../../models' | ||
5 | import { PeerTubeServer } from './server' | ||
6 | |||
7 | async function waitJobs ( | ||
8 | serversArg: PeerTubeServer[] | PeerTubeServer, | ||
9 | options: { | ||
10 | skipDelayed?: boolean // default false | ||
11 | runnerJobs?: boolean // default false | ||
12 | } = {} | ||
13 | ) { | ||
14 | const { skipDelayed = false, runnerJobs = false } = options | ||
15 | |||
16 | const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT | ||
17 | ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) | ||
18 | : 250 | ||
19 | |||
20 | let servers: PeerTubeServer[] | ||
21 | |||
22 | if (Array.isArray(serversArg) === false) servers = [ serversArg as PeerTubeServer ] | ||
23 | else servers = serversArg as PeerTubeServer[] | ||
24 | |||
25 | const states: JobState[] = [ 'waiting', 'active' ] | ||
26 | if (!skipDelayed) states.push('delayed') | ||
27 | |||
28 | const repeatableJobs: JobType[] = [ 'videos-views-stats', 'activitypub-cleaner' ] | ||
29 | let pendingRequests: boolean | ||
30 | |||
31 | function tasksBuilder () { | ||
32 | const tasks: Promise<any>[] = [] | ||
33 | |||
34 | // Check if each server has pending request | ||
35 | for (const server of servers) { | ||
36 | if (process.env.DEBUG) console.log('Checking ' + server.url) | ||
37 | |||
38 | for (const state of states) { | ||
39 | |||
40 | const jobPromise = server.jobs.list({ | ||
41 | state, | ||
42 | start: 0, | ||
43 | count: 10, | ||
44 | sort: '-createdAt' | ||
45 | }).then(body => body.data) | ||
46 | .then(jobs => jobs.filter(j => !repeatableJobs.includes(j.type))) | ||
47 | .then(jobs => { | ||
48 | if (jobs.length !== 0) { | ||
49 | pendingRequests = true | ||
50 | |||
51 | if (process.env.DEBUG) { | ||
52 | console.log(jobs) | ||
53 | } | ||
54 | } | ||
55 | }) | ||
56 | |||
57 | tasks.push(jobPromise) | ||
58 | } | ||
59 | |||
60 | const debugPromise = server.debug.getDebug() | ||
61 | .then(obj => { | ||
62 | if (obj.activityPubMessagesWaiting !== 0) { | ||
63 | pendingRequests = true | ||
64 | |||
65 | if (process.env.DEBUG) { | ||
66 | console.log('AP messages waiting: ' + obj.activityPubMessagesWaiting) | ||
67 | } | ||
68 | } | ||
69 | }) | ||
70 | tasks.push(debugPromise) | ||
71 | |||
72 | if (runnerJobs) { | ||
73 | const runnerJobsPromise = server.runnerJobs.list({ count: 100 }) | ||
74 | .then(({ data }) => { | ||
75 | for (const job of data) { | ||
76 | if (job.state.id !== RunnerJobState.COMPLETED) { | ||
77 | pendingRequests = true | ||
78 | |||
79 | if (process.env.DEBUG) { | ||
80 | console.log(job) | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | }) | ||
85 | tasks.push(runnerJobsPromise) | ||
86 | } | ||
87 | } | ||
88 | |||
89 | return tasks | ||
90 | } | ||
91 | |||
92 | do { | ||
93 | pendingRequests = false | ||
94 | await Promise.all(tasksBuilder()) | ||
95 | |||
96 | // Retry, in case of new jobs were created | ||
97 | if (pendingRequests === false) { | ||
98 | await wait(pendingJobWait) | ||
99 | await Promise.all(tasksBuilder()) | ||
100 | } | ||
101 | |||
102 | if (pendingRequests) { | ||
103 | await wait(pendingJobWait) | ||
104 | } | ||
105 | } while (pendingRequests) | ||
106 | } | ||
107 | |||
108 | async function expectNoFailedTranscodingJob (server: PeerTubeServer) { | ||
109 | const { data } = await server.jobs.listFailed({ jobType: 'video-transcoding' }) | ||
110 | expect(data).to.have.lengthOf(0) | ||
111 | } | ||
112 | |||
113 | // --------------------------------------------------------------------------- | ||
114 | |||
115 | export { | ||
116 | waitJobs, | ||
117 | expectNoFailedTranscodingJob | ||
118 | } | ||
diff --git a/shared/server-commands/server/metrics-command.ts b/shared/server-commands/server/metrics-command.ts deleted file mode 100644 index d22b4833d..000000000 --- a/shared/server-commands/server/metrics-command.ts +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class MetricsCommand extends AbstractCommand { | ||
5 | |||
6 | addPlaybackMetric (options: OverrideCommandOptions & { metrics: PlaybackMetricCreate }) { | ||
7 | const path = '/api/v1/metrics/playback' | ||
8 | |||
9 | return this.postBodyRequest({ | ||
10 | ...options, | ||
11 | |||
12 | path, | ||
13 | fields: options.metrics, | ||
14 | implicitToken: false, | ||
15 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
16 | }) | ||
17 | } | ||
18 | } | ||
diff --git a/shared/server-commands/server/object-storage-command.ts b/shared/server-commands/server/object-storage-command.ts deleted file mode 100644 index 6bb232c36..000000000 --- a/shared/server-commands/server/object-storage-command.ts +++ /dev/null | |||
@@ -1,165 +0,0 @@ | |||
1 | import { randomInt } from 'crypto' | ||
2 | import { HttpStatusCode } from '@shared/models' | ||
3 | import { makePostBodyRequest } from '../requests' | ||
4 | |||
5 | export class ObjectStorageCommand { | ||
6 | static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test' | ||
7 | |||
8 | private readonly bucketsCreated: string[] = [] | ||
9 | private readonly seed: number | ||
10 | |||
11 | // --------------------------------------------------------------------------- | ||
12 | |||
13 | constructor () { | ||
14 | this.seed = randomInt(0, 10000) | ||
15 | } | ||
16 | |||
17 | static getMockCredentialsConfig () { | ||
18 | return { | ||
19 | access_key_id: 'AKIAIOSFODNN7EXAMPLE', | ||
20 | secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY' | ||
21 | } | ||
22 | } | ||
23 | |||
24 | static getMockEndpointHost () { | ||
25 | return 'localhost:9444' | ||
26 | } | ||
27 | |||
28 | static getMockRegion () { | ||
29 | return 'us-east-1' | ||
30 | } | ||
31 | |||
32 | getDefaultMockConfig () { | ||
33 | return { | ||
34 | object_storage: { | ||
35 | enabled: true, | ||
36 | endpoint: 'http://' + ObjectStorageCommand.getMockEndpointHost(), | ||
37 | region: ObjectStorageCommand.getMockRegion(), | ||
38 | |||
39 | credentials: ObjectStorageCommand.getMockCredentialsConfig(), | ||
40 | |||
41 | streaming_playlists: { | ||
42 | bucket_name: this.getMockStreamingPlaylistsBucketName() | ||
43 | }, | ||
44 | |||
45 | web_videos: { | ||
46 | bucket_name: this.getMockWebVideosBucketName() | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | |||
52 | getMockWebVideosBaseUrl () { | ||
53 | return `http://${this.getMockWebVideosBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/` | ||
54 | } | ||
55 | |||
56 | getMockPlaylistBaseUrl () { | ||
57 | return `http://${this.getMockStreamingPlaylistsBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/` | ||
58 | } | ||
59 | |||
60 | async prepareDefaultMockBuckets () { | ||
61 | await this.createMockBucket(this.getMockStreamingPlaylistsBucketName()) | ||
62 | await this.createMockBucket(this.getMockWebVideosBucketName()) | ||
63 | } | ||
64 | |||
65 | async createMockBucket (name: string) { | ||
66 | this.bucketsCreated.push(name) | ||
67 | |||
68 | await this.deleteMockBucket(name) | ||
69 | |||
70 | await makePostBodyRequest({ | ||
71 | url: ObjectStorageCommand.getMockEndpointHost(), | ||
72 | path: '/ui/' + name + '?create', | ||
73 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | ||
74 | }) | ||
75 | |||
76 | await makePostBodyRequest({ | ||
77 | url: ObjectStorageCommand.getMockEndpointHost(), | ||
78 | path: '/ui/' + name + '?make-public', | ||
79 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | ||
80 | }) | ||
81 | } | ||
82 | |||
83 | async cleanupMock () { | ||
84 | for (const name of this.bucketsCreated) { | ||
85 | await this.deleteMockBucket(name) | ||
86 | } | ||
87 | } | ||
88 | |||
89 | getMockStreamingPlaylistsBucketName (name = 'streaming-playlists') { | ||
90 | return this.getMockBucketName(name) | ||
91 | } | ||
92 | |||
93 | getMockWebVideosBucketName (name = 'web-videos') { | ||
94 | return this.getMockBucketName(name) | ||
95 | } | ||
96 | |||
97 | getMockBucketName (name: string) { | ||
98 | return `${this.seed}-${name}` | ||
99 | } | ||
100 | |||
101 | private async deleteMockBucket (name: string) { | ||
102 | await makePostBodyRequest({ | ||
103 | url: ObjectStorageCommand.getMockEndpointHost(), | ||
104 | path: '/ui/' + name + '?delete', | ||
105 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | ||
106 | }) | ||
107 | } | ||
108 | |||
109 | // --------------------------------------------------------------------------- | ||
110 | |||
111 | static getDefaultScalewayConfig (options: { | ||
112 | serverNumber: number | ||
113 | enablePrivateProxy?: boolean // default true | ||
114 | privateACL?: 'private' | 'public-read' // default 'private' | ||
115 | }) { | ||
116 | const { serverNumber, enablePrivateProxy = true, privateACL = 'private' } = options | ||
117 | |||
118 | return { | ||
119 | object_storage: { | ||
120 | enabled: true, | ||
121 | endpoint: this.getScalewayEndpointHost(), | ||
122 | region: this.getScalewayRegion(), | ||
123 | |||
124 | credentials: this.getScalewayCredentialsConfig(), | ||
125 | |||
126 | upload_acl: { | ||
127 | private: privateACL | ||
128 | }, | ||
129 | |||
130 | proxy: { | ||
131 | proxify_private_files: enablePrivateProxy | ||
132 | }, | ||
133 | |||
134 | streaming_playlists: { | ||
135 | bucket_name: this.DEFAULT_SCALEWAY_BUCKET, | ||
136 | prefix: `test:server-${serverNumber}-streaming-playlists:` | ||
137 | }, | ||
138 | |||
139 | web_videos: { | ||
140 | bucket_name: this.DEFAULT_SCALEWAY_BUCKET, | ||
141 | prefix: `test:server-${serverNumber}-web-videos:` | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
147 | static getScalewayCredentialsConfig () { | ||
148 | return { | ||
149 | access_key_id: process.env.OBJECT_STORAGE_SCALEWAY_KEY_ID, | ||
150 | secret_access_key: process.env.OBJECT_STORAGE_SCALEWAY_ACCESS_KEY | ||
151 | } | ||
152 | } | ||
153 | |||
154 | static getScalewayEndpointHost () { | ||
155 | return 's3.fr-par.scw.cloud' | ||
156 | } | ||
157 | |||
158 | static getScalewayRegion () { | ||
159 | return 'fr-par' | ||
160 | } | ||
161 | |||
162 | static getScalewayBaseUrl () { | ||
163 | return `https://${this.DEFAULT_SCALEWAY_BUCKET}.${this.getScalewayEndpointHost()}/` | ||
164 | } | ||
165 | } | ||
diff --git a/shared/server-commands/server/plugins-command.ts b/shared/server-commands/server/plugins-command.ts deleted file mode 100644 index bb1277a7c..000000000 --- a/shared/server-commands/server/plugins-command.ts +++ /dev/null | |||
@@ -1,257 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { readJSON, writeJSON } from 'fs-extra' | ||
4 | import { join } from 'path' | ||
5 | import { root } from '@shared/core-utils' | ||
6 | import { | ||
7 | HttpStatusCode, | ||
8 | PeerTubePlugin, | ||
9 | PeerTubePluginIndex, | ||
10 | PeertubePluginIndexList, | ||
11 | PluginPackageJSON, | ||
12 | PluginTranslation, | ||
13 | PluginType, | ||
14 | PublicServerSetting, | ||
15 | RegisteredServerSettings, | ||
16 | ResultList | ||
17 | } from '@shared/models' | ||
18 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
19 | |||
20 | export class PluginsCommand extends AbstractCommand { | ||
21 | |||
22 | static getPluginTestPath (suffix = '') { | ||
23 | return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix) | ||
24 | } | ||
25 | |||
26 | list (options: OverrideCommandOptions & { | ||
27 | start?: number | ||
28 | count?: number | ||
29 | sort?: string | ||
30 | pluginType?: PluginType | ||
31 | uninstalled?: boolean | ||
32 | }) { | ||
33 | const { start, count, sort, pluginType, uninstalled } = options | ||
34 | const path = '/api/v1/plugins' | ||
35 | |||
36 | return this.getRequestBody<ResultList<PeerTubePlugin>>({ | ||
37 | ...options, | ||
38 | |||
39 | path, | ||
40 | query: { | ||
41 | start, | ||
42 | count, | ||
43 | sort, | ||
44 | pluginType, | ||
45 | uninstalled | ||
46 | }, | ||
47 | implicitToken: true, | ||
48 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
49 | }) | ||
50 | } | ||
51 | |||
52 | listAvailable (options: OverrideCommandOptions & { | ||
53 | start?: number | ||
54 | count?: number | ||
55 | sort?: string | ||
56 | pluginType?: PluginType | ||
57 | currentPeerTubeEngine?: string | ||
58 | search?: string | ||
59 | expectedStatus?: HttpStatusCode | ||
60 | }) { | ||
61 | const { start, count, sort, pluginType, search, currentPeerTubeEngine } = options | ||
62 | const path = '/api/v1/plugins/available' | ||
63 | |||
64 | const query: PeertubePluginIndexList = { | ||
65 | start, | ||
66 | count, | ||
67 | sort, | ||
68 | pluginType, | ||
69 | currentPeerTubeEngine, | ||
70 | search | ||
71 | } | ||
72 | |||
73 | return this.getRequestBody<ResultList<PeerTubePluginIndex>>({ | ||
74 | ...options, | ||
75 | |||
76 | path, | ||
77 | query, | ||
78 | implicitToken: true, | ||
79 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
80 | }) | ||
81 | } | ||
82 | |||
83 | get (options: OverrideCommandOptions & { | ||
84 | npmName: string | ||
85 | }) { | ||
86 | const path = '/api/v1/plugins/' + options.npmName | ||
87 | |||
88 | return this.getRequestBody<PeerTubePlugin>({ | ||
89 | ...options, | ||
90 | |||
91 | path, | ||
92 | implicitToken: true, | ||
93 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
94 | }) | ||
95 | } | ||
96 | |||
97 | updateSettings (options: OverrideCommandOptions & { | ||
98 | npmName: string | ||
99 | settings: any | ||
100 | }) { | ||
101 | const { npmName, settings } = options | ||
102 | const path = '/api/v1/plugins/' + npmName + '/settings' | ||
103 | |||
104 | return this.putBodyRequest({ | ||
105 | ...options, | ||
106 | |||
107 | path, | ||
108 | fields: { settings }, | ||
109 | implicitToken: true, | ||
110 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
111 | }) | ||
112 | } | ||
113 | |||
114 | getRegisteredSettings (options: OverrideCommandOptions & { | ||
115 | npmName: string | ||
116 | }) { | ||
117 | const path = '/api/v1/plugins/' + options.npmName + '/registered-settings' | ||
118 | |||
119 | return this.getRequestBody<RegisteredServerSettings>({ | ||
120 | ...options, | ||
121 | |||
122 | path, | ||
123 | implicitToken: true, | ||
124 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
125 | }) | ||
126 | } | ||
127 | |||
128 | getPublicSettings (options: OverrideCommandOptions & { | ||
129 | npmName: string | ||
130 | }) { | ||
131 | const { npmName } = options | ||
132 | const path = '/api/v1/plugins/' + npmName + '/public-settings' | ||
133 | |||
134 | return this.getRequestBody<PublicServerSetting>({ | ||
135 | ...options, | ||
136 | |||
137 | path, | ||
138 | implicitToken: false, | ||
139 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
140 | }) | ||
141 | } | ||
142 | |||
143 | getTranslations (options: OverrideCommandOptions & { | ||
144 | locale: string | ||
145 | }) { | ||
146 | const { locale } = options | ||
147 | const path = '/plugins/translations/' + locale + '.json' | ||
148 | |||
149 | return this.getRequestBody<PluginTranslation>({ | ||
150 | ...options, | ||
151 | |||
152 | path, | ||
153 | implicitToken: false, | ||
154 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
155 | }) | ||
156 | } | ||
157 | |||
158 | install (options: OverrideCommandOptions & { | ||
159 | path?: string | ||
160 | npmName?: string | ||
161 | pluginVersion?: string | ||
162 | }) { | ||
163 | const { npmName, path, pluginVersion } = options | ||
164 | const apiPath = '/api/v1/plugins/install' | ||
165 | |||
166 | return this.postBodyRequest({ | ||
167 | ...options, | ||
168 | |||
169 | path: apiPath, | ||
170 | fields: { npmName, path, pluginVersion }, | ||
171 | implicitToken: true, | ||
172 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
173 | }) | ||
174 | } | ||
175 | |||
176 | update (options: OverrideCommandOptions & { | ||
177 | path?: string | ||
178 | npmName?: string | ||
179 | }) { | ||
180 | const { npmName, path } = options | ||
181 | const apiPath = '/api/v1/plugins/update' | ||
182 | |||
183 | return this.postBodyRequest({ | ||
184 | ...options, | ||
185 | |||
186 | path: apiPath, | ||
187 | fields: { npmName, path }, | ||
188 | implicitToken: true, | ||
189 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
190 | }) | ||
191 | } | ||
192 | |||
193 | uninstall (options: OverrideCommandOptions & { | ||
194 | npmName: string | ||
195 | }) { | ||
196 | const { npmName } = options | ||
197 | const apiPath = '/api/v1/plugins/uninstall' | ||
198 | |||
199 | return this.postBodyRequest({ | ||
200 | ...options, | ||
201 | |||
202 | path: apiPath, | ||
203 | fields: { npmName }, | ||
204 | implicitToken: true, | ||
205 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
206 | }) | ||
207 | } | ||
208 | |||
209 | getCSS (options: OverrideCommandOptions = {}) { | ||
210 | const path = '/plugins/global.css' | ||
211 | |||
212 | return this.getRequestText({ | ||
213 | ...options, | ||
214 | |||
215 | path, | ||
216 | implicitToken: false, | ||
217 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
218 | }) | ||
219 | } | ||
220 | |||
221 | getExternalAuth (options: OverrideCommandOptions & { | ||
222 | npmName: string | ||
223 | npmVersion: string | ||
224 | authName: string | ||
225 | query?: any | ||
226 | }) { | ||
227 | const { npmName, npmVersion, authName, query } = options | ||
228 | |||
229 | const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName | ||
230 | |||
231 | return this.getRequest({ | ||
232 | ...options, | ||
233 | |||
234 | path, | ||
235 | query, | ||
236 | implicitToken: false, | ||
237 | defaultExpectedStatus: HttpStatusCode.OK_200, | ||
238 | redirects: 0 | ||
239 | }) | ||
240 | } | ||
241 | |||
242 | updatePackageJSON (npmName: string, json: any) { | ||
243 | const path = this.getPackageJSONPath(npmName) | ||
244 | |||
245 | return writeJSON(path, json) | ||
246 | } | ||
247 | |||
248 | getPackageJSON (npmName: string): Promise<PluginPackageJSON> { | ||
249 | const path = this.getPackageJSONPath(npmName) | ||
250 | |||
251 | return readJSON(path) | ||
252 | } | ||
253 | |||
254 | private getPackageJSONPath (npmName: string) { | ||
255 | return this.server.servers.buildDirectory(join('plugins', 'node_modules', npmName, 'package.json')) | ||
256 | } | ||
257 | } | ||
diff --git a/shared/server-commands/server/redundancy-command.ts b/shared/server-commands/server/redundancy-command.ts deleted file mode 100644 index e7a8b3c29..000000000 --- a/shared/server-commands/server/redundancy-command.ts +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | import { HttpStatusCode, ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class RedundancyCommand extends AbstractCommand { | ||
5 | |||
6 | updateRedundancy (options: OverrideCommandOptions & { | ||
7 | host: string | ||
8 | redundancyAllowed: boolean | ||
9 | }) { | ||
10 | const { host, redundancyAllowed } = options | ||
11 | const path = '/api/v1/server/redundancy/' + host | ||
12 | |||
13 | return this.putBodyRequest({ | ||
14 | ...options, | ||
15 | |||
16 | path, | ||
17 | fields: { redundancyAllowed }, | ||
18 | implicitToken: true, | ||
19 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
20 | }) | ||
21 | } | ||
22 | |||
23 | listVideos (options: OverrideCommandOptions & { | ||
24 | target: VideoRedundanciesTarget | ||
25 | start?: number | ||
26 | count?: number | ||
27 | sort?: string | ||
28 | }) { | ||
29 | const path = '/api/v1/server/redundancy/videos' | ||
30 | |||
31 | const { target, start, count, sort } = options | ||
32 | |||
33 | return this.getRequestBody<ResultList<VideoRedundancy>>({ | ||
34 | ...options, | ||
35 | |||
36 | path, | ||
37 | |||
38 | query: { | ||
39 | start: start ?? 0, | ||
40 | count: count ?? 5, | ||
41 | sort: sort ?? 'name', | ||
42 | target | ||
43 | }, | ||
44 | |||
45 | implicitToken: true, | ||
46 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
47 | }) | ||
48 | } | ||
49 | |||
50 | addVideo (options: OverrideCommandOptions & { | ||
51 | videoId: number | ||
52 | }) { | ||
53 | const path = '/api/v1/server/redundancy/videos' | ||
54 | const { videoId } = options | ||
55 | |||
56 | return this.postBodyRequest({ | ||
57 | ...options, | ||
58 | |||
59 | path, | ||
60 | fields: { videoId }, | ||
61 | implicitToken: true, | ||
62 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
63 | }) | ||
64 | } | ||
65 | |||
66 | removeVideo (options: OverrideCommandOptions & { | ||
67 | redundancyId: number | ||
68 | }) { | ||
69 | const { redundancyId } = options | ||
70 | const path = '/api/v1/server/redundancy/videos/' + redundancyId | ||
71 | |||
72 | return this.deleteRequest({ | ||
73 | ...options, | ||
74 | |||
75 | path, | ||
76 | implicitToken: true, | ||
77 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
78 | }) | ||
79 | } | ||
80 | } | ||
diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts deleted file mode 100644 index 38568a890..000000000 --- a/shared/server-commands/server/server.ts +++ /dev/null | |||
@@ -1,450 +0,0 @@ | |||
1 | import { ChildProcess, fork } from 'child_process' | ||
2 | import { copy } from 'fs-extra' | ||
3 | import { join } from 'path' | ||
4 | import { parallelTests, randomInt, root } from '@shared/core-utils' | ||
5 | import { Video, VideoChannel, VideoChannelSync, VideoCreateResult, VideoDetails } from '@shared/models' | ||
6 | import { BulkCommand } from '../bulk' | ||
7 | import { CLICommand } from '../cli' | ||
8 | import { CustomPagesCommand } from '../custom-pages' | ||
9 | import { FeedCommand } from '../feeds' | ||
10 | import { LogsCommand } from '../logs' | ||
11 | import { AbusesCommand } from '../moderation' | ||
12 | import { OverviewsCommand } from '../overviews' | ||
13 | import { RunnerJobsCommand, RunnerRegistrationTokensCommand, RunnersCommand } from '../runners' | ||
14 | import { SearchCommand } from '../search' | ||
15 | import { SocketIOCommand } from '../socket' | ||
16 | import { | ||
17 | AccountsCommand, | ||
18 | BlocklistCommand, | ||
19 | LoginCommand, | ||
20 | NotificationsCommand, | ||
21 | RegistrationsCommand, | ||
22 | SubscriptionsCommand, | ||
23 | TwoFactorCommand, | ||
24 | UsersCommand | ||
25 | } from '../users' | ||
26 | import { | ||
27 | BlacklistCommand, | ||
28 | CaptionsCommand, | ||
29 | ChangeOwnershipCommand, | ||
30 | ChannelsCommand, | ||
31 | ChannelSyncsCommand, | ||
32 | HistoryCommand, | ||
33 | ImportsCommand, | ||
34 | LiveCommand, | ||
35 | VideoPasswordsCommand, | ||
36 | PlaylistsCommand, | ||
37 | ServicesCommand, | ||
38 | StoryboardCommand, | ||
39 | StreamingPlaylistsCommand, | ||
40 | VideosCommand, | ||
41 | VideoStudioCommand, | ||
42 | VideoTokenCommand, | ||
43 | ViewsCommand | ||
44 | } from '../videos' | ||
45 | import { CommentsCommand } from '../videos/comments-command' | ||
46 | import { VideoStatsCommand } from '../videos/video-stats-command' | ||
47 | import { ConfigCommand } from './config-command' | ||
48 | import { ContactFormCommand } from './contact-form-command' | ||
49 | import { DebugCommand } from './debug-command' | ||
50 | import { FollowsCommand } from './follows-command' | ||
51 | import { JobsCommand } from './jobs-command' | ||
52 | import { MetricsCommand } from './metrics-command' | ||
53 | import { PluginsCommand } from './plugins-command' | ||
54 | import { RedundancyCommand } from './redundancy-command' | ||
55 | import { ServersCommand } from './servers-command' | ||
56 | import { StatsCommand } from './stats-command' | ||
57 | |||
58 | export type RunServerOptions = { | ||
59 | hideLogs?: boolean | ||
60 | nodeArgs?: string[] | ||
61 | peertubeArgs?: string[] | ||
62 | env?: { [ id: string ]: string } | ||
63 | } | ||
64 | |||
65 | export class PeerTubeServer { | ||
66 | app?: ChildProcess | ||
67 | |||
68 | url: string | ||
69 | host?: string | ||
70 | hostname?: string | ||
71 | port?: number | ||
72 | |||
73 | rtmpPort?: number | ||
74 | rtmpsPort?: number | ||
75 | |||
76 | parallel?: boolean | ||
77 | internalServerNumber: number | ||
78 | |||
79 | serverNumber?: number | ||
80 | customConfigFile?: string | ||
81 | |||
82 | store?: { | ||
83 | client?: { | ||
84 | id?: string | ||
85 | secret?: string | ||
86 | } | ||
87 | |||
88 | user?: { | ||
89 | username: string | ||
90 | password: string | ||
91 | email?: string | ||
92 | } | ||
93 | |||
94 | channel?: VideoChannel | ||
95 | videoChannelSync?: Partial<VideoChannelSync> | ||
96 | |||
97 | video?: Video | ||
98 | videoCreated?: VideoCreateResult | ||
99 | videoDetails?: VideoDetails | ||
100 | |||
101 | videos?: { id: number, uuid: string }[] | ||
102 | } | ||
103 | |||
104 | accessToken?: string | ||
105 | refreshToken?: string | ||
106 | |||
107 | bulk?: BulkCommand | ||
108 | cli?: CLICommand | ||
109 | customPage?: CustomPagesCommand | ||
110 | feed?: FeedCommand | ||
111 | logs?: LogsCommand | ||
112 | abuses?: AbusesCommand | ||
113 | overviews?: OverviewsCommand | ||
114 | search?: SearchCommand | ||
115 | contactForm?: ContactFormCommand | ||
116 | debug?: DebugCommand | ||
117 | follows?: FollowsCommand | ||
118 | jobs?: JobsCommand | ||
119 | metrics?: MetricsCommand | ||
120 | plugins?: PluginsCommand | ||
121 | redundancy?: RedundancyCommand | ||
122 | stats?: StatsCommand | ||
123 | config?: ConfigCommand | ||
124 | socketIO?: SocketIOCommand | ||
125 | accounts?: AccountsCommand | ||
126 | blocklist?: BlocklistCommand | ||
127 | subscriptions?: SubscriptionsCommand | ||
128 | live?: LiveCommand | ||
129 | services?: ServicesCommand | ||
130 | blacklist?: BlacklistCommand | ||
131 | captions?: CaptionsCommand | ||
132 | changeOwnership?: ChangeOwnershipCommand | ||
133 | playlists?: PlaylistsCommand | ||
134 | history?: HistoryCommand | ||
135 | imports?: ImportsCommand | ||
136 | channelSyncs?: ChannelSyncsCommand | ||
137 | streamingPlaylists?: StreamingPlaylistsCommand | ||
138 | channels?: ChannelsCommand | ||
139 | comments?: CommentsCommand | ||
140 | notifications?: NotificationsCommand | ||
141 | servers?: ServersCommand | ||
142 | login?: LoginCommand | ||
143 | users?: UsersCommand | ||
144 | videoStudio?: VideoStudioCommand | ||
145 | videos?: VideosCommand | ||
146 | videoStats?: VideoStatsCommand | ||
147 | views?: ViewsCommand | ||
148 | twoFactor?: TwoFactorCommand | ||
149 | videoToken?: VideoTokenCommand | ||
150 | registrations?: RegistrationsCommand | ||
151 | videoPasswords?: VideoPasswordsCommand | ||
152 | |||
153 | storyboard?: StoryboardCommand | ||
154 | |||
155 | runners?: RunnersCommand | ||
156 | runnerRegistrationTokens?: RunnerRegistrationTokensCommand | ||
157 | runnerJobs?: RunnerJobsCommand | ||
158 | |||
159 | constructor (options: { serverNumber: number } | { url: string }) { | ||
160 | if ((options as any).url) { | ||
161 | this.setUrl((options as any).url) | ||
162 | } else { | ||
163 | this.setServerNumber((options as any).serverNumber) | ||
164 | } | ||
165 | |||
166 | this.store = { | ||
167 | client: { | ||
168 | id: null, | ||
169 | secret: null | ||
170 | }, | ||
171 | user: { | ||
172 | username: null, | ||
173 | password: null | ||
174 | } | ||
175 | } | ||
176 | |||
177 | this.assignCommands() | ||
178 | } | ||
179 | |||
180 | setServerNumber (serverNumber: number) { | ||
181 | this.serverNumber = serverNumber | ||
182 | |||
183 | this.parallel = parallelTests() | ||
184 | |||
185 | this.internalServerNumber = this.parallel ? this.randomServer() : this.serverNumber | ||
186 | this.rtmpPort = this.parallel ? this.randomRTMP() : 1936 | ||
187 | this.rtmpsPort = this.parallel ? this.randomRTMP() : 1937 | ||
188 | this.port = 9000 + this.internalServerNumber | ||
189 | |||
190 | this.url = `http://127.0.0.1:${this.port}` | ||
191 | this.host = `127.0.0.1:${this.port}` | ||
192 | this.hostname = '127.0.0.1' | ||
193 | } | ||
194 | |||
195 | setUrl (url: string) { | ||
196 | const parsed = new URL(url) | ||
197 | |||
198 | this.url = url | ||
199 | this.host = parsed.host | ||
200 | this.hostname = parsed.hostname | ||
201 | this.port = parseInt(parsed.port) | ||
202 | } | ||
203 | |||
204 | getDirectoryPath (directoryName: string) { | ||
205 | const testDirectory = 'test' + this.internalServerNumber | ||
206 | |||
207 | return join(root(), testDirectory, directoryName) | ||
208 | } | ||
209 | |||
210 | async flushAndRun (configOverride?: object, options: RunServerOptions = {}) { | ||
211 | await ServersCommand.flushTests(this.internalServerNumber) | ||
212 | |||
213 | return this.run(configOverride, options) | ||
214 | } | ||
215 | |||
216 | async run (configOverrideArg?: any, options: RunServerOptions = {}) { | ||
217 | // These actions are async so we need to be sure that they have both been done | ||
218 | const serverRunString = { | ||
219 | 'HTTP server listening': false | ||
220 | } | ||
221 | const key = 'Database peertube_test' + this.internalServerNumber + ' is ready' | ||
222 | serverRunString[key] = false | ||
223 | |||
224 | const regexps = { | ||
225 | client_id: 'Client id: (.+)', | ||
226 | client_secret: 'Client secret: (.+)', | ||
227 | user_username: 'Username: (.+)', | ||
228 | user_password: 'User password: (.+)' | ||
229 | } | ||
230 | |||
231 | await this.assignCustomConfigFile() | ||
232 | |||
233 | const configOverride = this.buildConfigOverride() | ||
234 | |||
235 | if (configOverrideArg !== undefined) { | ||
236 | Object.assign(configOverride, configOverrideArg) | ||
237 | } | ||
238 | |||
239 | // Share the environment | ||
240 | const env = { ...process.env } | ||
241 | env['NODE_ENV'] = 'test' | ||
242 | env['NODE_APP_INSTANCE'] = this.internalServerNumber.toString() | ||
243 | env['NODE_CONFIG'] = JSON.stringify(configOverride) | ||
244 | |||
245 | if (options.env) { | ||
246 | Object.assign(env, options.env) | ||
247 | } | ||
248 | |||
249 | const execArgv = options.nodeArgs || [] | ||
250 | // FIXME: too slow :/ | ||
251 | // execArgv.push('--enable-source-maps') | ||
252 | |||
253 | const forkOptions = { | ||
254 | silent: true, | ||
255 | env, | ||
256 | detached: false, | ||
257 | execArgv | ||
258 | } | ||
259 | |||
260 | const peertubeArgs = options.peertubeArgs || [] | ||
261 | |||
262 | return new Promise<void>((res, rej) => { | ||
263 | const self = this | ||
264 | let aggregatedLogs = '' | ||
265 | |||
266 | this.app = fork(join(root(), 'dist', 'server.js'), peertubeArgs, forkOptions) | ||
267 | |||
268 | const onPeerTubeExit = () => rej(new Error('Process exited:\n' + aggregatedLogs)) | ||
269 | const onParentExit = () => { | ||
270 | if (!this.app?.pid) return | ||
271 | |||
272 | try { | ||
273 | process.kill(self.app.pid) | ||
274 | } catch { /* empty */ } | ||
275 | } | ||
276 | |||
277 | this.app.on('exit', onPeerTubeExit) | ||
278 | process.on('exit', onParentExit) | ||
279 | |||
280 | this.app.stdout.on('data', function onStdout (data) { | ||
281 | let dontContinue = false | ||
282 | |||
283 | const log: string = data.toString() | ||
284 | aggregatedLogs += log | ||
285 | |||
286 | // Capture things if we want to | ||
287 | for (const key of Object.keys(regexps)) { | ||
288 | const regexp = regexps[key] | ||
289 | const matches = log.match(regexp) | ||
290 | if (matches !== null) { | ||
291 | if (key === 'client_id') self.store.client.id = matches[1] | ||
292 | else if (key === 'client_secret') self.store.client.secret = matches[1] | ||
293 | else if (key === 'user_username') self.store.user.username = matches[1] | ||
294 | else if (key === 'user_password') self.store.user.password = matches[1] | ||
295 | } | ||
296 | } | ||
297 | |||
298 | // Check if all required sentences are here | ||
299 | for (const key of Object.keys(serverRunString)) { | ||
300 | if (log.includes(key)) serverRunString[key] = true | ||
301 | if (serverRunString[key] === false) dontContinue = true | ||
302 | } | ||
303 | |||
304 | // If no, there is maybe one thing not already initialized (client/user credentials generation...) | ||
305 | if (dontContinue === true) return | ||
306 | |||
307 | if (options.hideLogs === false) { | ||
308 | console.log(log) | ||
309 | } else { | ||
310 | process.removeListener('exit', onParentExit) | ||
311 | self.app.stdout.removeListener('data', onStdout) | ||
312 | self.app.removeListener('exit', onPeerTubeExit) | ||
313 | } | ||
314 | |||
315 | res() | ||
316 | }) | ||
317 | }) | ||
318 | } | ||
319 | |||
320 | kill () { | ||
321 | if (!this.app) return Promise.resolve() | ||
322 | |||
323 | process.kill(this.app.pid) | ||
324 | |||
325 | this.app = null | ||
326 | |||
327 | return Promise.resolve() | ||
328 | } | ||
329 | |||
330 | private randomServer () { | ||
331 | const low = 2500 | ||
332 | const high = 10000 | ||
333 | |||
334 | return randomInt(low, high) | ||
335 | } | ||
336 | |||
337 | private randomRTMP () { | ||
338 | const low = 1900 | ||
339 | const high = 2100 | ||
340 | |||
341 | return randomInt(low, high) | ||
342 | } | ||
343 | |||
344 | private async assignCustomConfigFile () { | ||
345 | if (this.internalServerNumber === this.serverNumber) return | ||
346 | |||
347 | const basePath = join(root(), 'config') | ||
348 | |||
349 | const tmpConfigFile = join(basePath, `test-${this.internalServerNumber}.yaml`) | ||
350 | await copy(join(basePath, `test-${this.serverNumber}.yaml`), tmpConfigFile) | ||
351 | |||
352 | this.customConfigFile = tmpConfigFile | ||
353 | } | ||
354 | |||
355 | private buildConfigOverride () { | ||
356 | if (!this.parallel) return {} | ||
357 | |||
358 | return { | ||
359 | listen: { | ||
360 | port: this.port | ||
361 | }, | ||
362 | webserver: { | ||
363 | port: this.port | ||
364 | }, | ||
365 | database: { | ||
366 | suffix: '_test' + this.internalServerNumber | ||
367 | }, | ||
368 | storage: { | ||
369 | tmp: this.getDirectoryPath('tmp') + '/', | ||
370 | tmp_persistent: this.getDirectoryPath('tmp-persistent') + '/', | ||
371 | bin: this.getDirectoryPath('bin') + '/', | ||
372 | avatars: this.getDirectoryPath('avatars') + '/', | ||
373 | web_videos: this.getDirectoryPath('web-videos') + '/', | ||
374 | streaming_playlists: this.getDirectoryPath('streaming-playlists') + '/', | ||
375 | redundancy: this.getDirectoryPath('redundancy') + '/', | ||
376 | logs: this.getDirectoryPath('logs') + '/', | ||
377 | previews: this.getDirectoryPath('previews') + '/', | ||
378 | thumbnails: this.getDirectoryPath('thumbnails') + '/', | ||
379 | storyboards: this.getDirectoryPath('storyboards') + '/', | ||
380 | torrents: this.getDirectoryPath('torrents') + '/', | ||
381 | captions: this.getDirectoryPath('captions') + '/', | ||
382 | cache: this.getDirectoryPath('cache') + '/', | ||
383 | plugins: this.getDirectoryPath('plugins') + '/', | ||
384 | well_known: this.getDirectoryPath('well-known') + '/' | ||
385 | }, | ||
386 | admin: { | ||
387 | email: `admin${this.internalServerNumber}@example.com` | ||
388 | }, | ||
389 | live: { | ||
390 | rtmp: { | ||
391 | port: this.rtmpPort | ||
392 | } | ||
393 | } | ||
394 | } | ||
395 | } | ||
396 | |||
397 | private assignCommands () { | ||
398 | this.bulk = new BulkCommand(this) | ||
399 | this.cli = new CLICommand(this) | ||
400 | this.customPage = new CustomPagesCommand(this) | ||
401 | this.feed = new FeedCommand(this) | ||
402 | this.logs = new LogsCommand(this) | ||
403 | this.abuses = new AbusesCommand(this) | ||
404 | this.overviews = new OverviewsCommand(this) | ||
405 | this.search = new SearchCommand(this) | ||
406 | this.contactForm = new ContactFormCommand(this) | ||
407 | this.debug = new DebugCommand(this) | ||
408 | this.follows = new FollowsCommand(this) | ||
409 | this.jobs = new JobsCommand(this) | ||
410 | this.metrics = new MetricsCommand(this) | ||
411 | this.plugins = new PluginsCommand(this) | ||
412 | this.redundancy = new RedundancyCommand(this) | ||
413 | this.stats = new StatsCommand(this) | ||
414 | this.config = new ConfigCommand(this) | ||
415 | this.socketIO = new SocketIOCommand(this) | ||
416 | this.accounts = new AccountsCommand(this) | ||
417 | this.blocklist = new BlocklistCommand(this) | ||
418 | this.subscriptions = new SubscriptionsCommand(this) | ||
419 | this.live = new LiveCommand(this) | ||
420 | this.services = new ServicesCommand(this) | ||
421 | this.blacklist = new BlacklistCommand(this) | ||
422 | this.captions = new CaptionsCommand(this) | ||
423 | this.changeOwnership = new ChangeOwnershipCommand(this) | ||
424 | this.playlists = new PlaylistsCommand(this) | ||
425 | this.history = new HistoryCommand(this) | ||
426 | this.imports = new ImportsCommand(this) | ||
427 | this.channelSyncs = new ChannelSyncsCommand(this) | ||
428 | this.streamingPlaylists = new StreamingPlaylistsCommand(this) | ||
429 | this.channels = new ChannelsCommand(this) | ||
430 | this.comments = new CommentsCommand(this) | ||
431 | this.notifications = new NotificationsCommand(this) | ||
432 | this.servers = new ServersCommand(this) | ||
433 | this.login = new LoginCommand(this) | ||
434 | this.users = new UsersCommand(this) | ||
435 | this.videos = new VideosCommand(this) | ||
436 | this.videoStudio = new VideoStudioCommand(this) | ||
437 | this.videoStats = new VideoStatsCommand(this) | ||
438 | this.views = new ViewsCommand(this) | ||
439 | this.twoFactor = new TwoFactorCommand(this) | ||
440 | this.videoToken = new VideoTokenCommand(this) | ||
441 | this.registrations = new RegistrationsCommand(this) | ||
442 | |||
443 | this.storyboard = new StoryboardCommand(this) | ||
444 | |||
445 | this.runners = new RunnersCommand(this) | ||
446 | this.runnerRegistrationTokens = new RunnerRegistrationTokensCommand(this) | ||
447 | this.runnerJobs = new RunnerJobsCommand(this) | ||
448 | this.videoPasswords = new VideoPasswordsCommand(this) | ||
449 | } | ||
450 | } | ||
diff --git a/shared/server-commands/server/servers-command.ts b/shared/server-commands/server/servers-command.ts deleted file mode 100644 index 54e586a18..000000000 --- a/shared/server-commands/server/servers-command.ts +++ /dev/null | |||
@@ -1,103 +0,0 @@ | |||
1 | import { exec } from 'child_process' | ||
2 | import { copy, ensureDir, readFile, readdir, remove } from 'fs-extra' | ||
3 | import { basename, join } from 'path' | ||
4 | import { isGithubCI, root, wait } from '@shared/core-utils' | ||
5 | import { getFileSize } from '@shared/extra-utils' | ||
6 | import { HttpStatusCode } from '@shared/models' | ||
7 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
8 | |||
9 | export class ServersCommand extends AbstractCommand { | ||
10 | |||
11 | static flushTests (internalServerNumber: number) { | ||
12 | return new Promise<void>((res, rej) => { | ||
13 | const suffix = ` -- ${internalServerNumber}` | ||
14 | |||
15 | return exec('npm run clean:server:test' + suffix, (err, _stdout, stderr) => { | ||
16 | if (err || stderr) return rej(err || new Error(stderr)) | ||
17 | |||
18 | return res() | ||
19 | }) | ||
20 | }) | ||
21 | } | ||
22 | |||
23 | ping (options: OverrideCommandOptions = {}) { | ||
24 | return this.getRequestBody({ | ||
25 | ...options, | ||
26 | |||
27 | path: '/api/v1/ping', | ||
28 | implicitToken: false, | ||
29 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
30 | }) | ||
31 | } | ||
32 | |||
33 | cleanupTests () { | ||
34 | const promises: Promise<any>[] = [] | ||
35 | |||
36 | const saveGithubLogsIfNeeded = async () => { | ||
37 | if (!isGithubCI()) return | ||
38 | |||
39 | await ensureDir('artifacts') | ||
40 | |||
41 | const origin = this.buildDirectory('logs/peertube.log') | ||
42 | const destname = `peertube-${this.server.internalServerNumber}.log` | ||
43 | console.log('Saving logs %s.', destname) | ||
44 | |||
45 | await copy(origin, join('artifacts', destname)) | ||
46 | } | ||
47 | |||
48 | if (this.server.parallel) { | ||
49 | const promise = saveGithubLogsIfNeeded() | ||
50 | .then(() => ServersCommand.flushTests(this.server.internalServerNumber)) | ||
51 | |||
52 | promises.push(promise) | ||
53 | } | ||
54 | |||
55 | if (this.server.customConfigFile) { | ||
56 | promises.push(remove(this.server.customConfigFile)) | ||
57 | } | ||
58 | |||
59 | return promises | ||
60 | } | ||
61 | |||
62 | async waitUntilLog (str: string, count = 1, strictCount = true) { | ||
63 | const logfile = this.buildDirectory('logs/peertube.log') | ||
64 | |||
65 | while (true) { | ||
66 | const buf = await readFile(logfile) | ||
67 | |||
68 | const matches = buf.toString().match(new RegExp(str, 'g')) | ||
69 | if (matches && matches.length === count) return | ||
70 | if (matches && strictCount === false && matches.length >= count) return | ||
71 | |||
72 | await wait(1000) | ||
73 | } | ||
74 | } | ||
75 | |||
76 | buildDirectory (directory: string) { | ||
77 | return join(root(), 'test' + this.server.internalServerNumber, directory) | ||
78 | } | ||
79 | |||
80 | async countFiles (directory: string) { | ||
81 | const files = await readdir(this.buildDirectory(directory)) | ||
82 | |||
83 | return files.length | ||
84 | } | ||
85 | |||
86 | buildWebVideoFilePath (fileUrl: string) { | ||
87 | return this.buildDirectory(join('web-videos', basename(fileUrl))) | ||
88 | } | ||
89 | |||
90 | buildFragmentedFilePath (videoUUID: string, fileUrl: string) { | ||
91 | return this.buildDirectory(join('streaming-playlists', 'hls', videoUUID, basename(fileUrl))) | ||
92 | } | ||
93 | |||
94 | getLogContent () { | ||
95 | return readFile(this.buildDirectory('logs/peertube.log')) | ||
96 | } | ||
97 | |||
98 | async getServerFileSize (subPath: string) { | ||
99 | const path = this.server.servers.buildDirectory(subPath) | ||
100 | |||
101 | return getFileSize(path) | ||
102 | } | ||
103 | } | ||
diff --git a/shared/server-commands/server/servers.ts b/shared/server-commands/server/servers.ts deleted file mode 100644 index fe9da9e63..000000000 --- a/shared/server-commands/server/servers.ts +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | import { ensureDir } from 'fs-extra' | ||
2 | import { isGithubCI } from '@shared/core-utils' | ||
3 | import { PeerTubeServer, RunServerOptions } from './server' | ||
4 | |||
5 | async function createSingleServer (serverNumber: number, configOverride?: object, options: RunServerOptions = {}) { | ||
6 | const server = new PeerTubeServer({ serverNumber }) | ||
7 | |||
8 | await server.flushAndRun(configOverride, options) | ||
9 | |||
10 | return server | ||
11 | } | ||
12 | |||
13 | function createMultipleServers (totalServers: number, configOverride?: object, options: RunServerOptions = {}) { | ||
14 | const serverPromises: Promise<PeerTubeServer>[] = [] | ||
15 | |||
16 | for (let i = 1; i <= totalServers; i++) { | ||
17 | serverPromises.push(createSingleServer(i, configOverride, options)) | ||
18 | } | ||
19 | |||
20 | return Promise.all(serverPromises) | ||
21 | } | ||
22 | |||
23 | function killallServers (servers: PeerTubeServer[]) { | ||
24 | return Promise.all(servers.map(s => s.kill())) | ||
25 | } | ||
26 | |||
27 | async function cleanupTests (servers: PeerTubeServer[]) { | ||
28 | await killallServers(servers) | ||
29 | |||
30 | if (isGithubCI()) { | ||
31 | await ensureDir('artifacts') | ||
32 | } | ||
33 | |||
34 | let p: Promise<any>[] = [] | ||
35 | for (const server of servers) { | ||
36 | p = p.concat(server.servers.cleanupTests()) | ||
37 | } | ||
38 | |||
39 | return Promise.all(p) | ||
40 | } | ||
41 | |||
42 | function getServerImportConfig (mode: 'youtube-dl' | 'yt-dlp') { | ||
43 | return { | ||
44 | import: { | ||
45 | videos: { | ||
46 | http: { | ||
47 | youtube_dl_release: { | ||
48 | url: mode === 'youtube-dl' | ||
49 | ? 'https://yt-dl.org/downloads/latest/youtube-dl' | ||
50 | : 'https://api.github.com/repos/yt-dlp/yt-dlp/releases', | ||
51 | |||
52 | name: mode | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | |||
60 | // --------------------------------------------------------------------------- | ||
61 | |||
62 | export { | ||
63 | createSingleServer, | ||
64 | createMultipleServers, | ||
65 | cleanupTests, | ||
66 | killallServers, | ||
67 | getServerImportConfig | ||
68 | } | ||
diff --git a/shared/server-commands/server/stats-command.ts b/shared/server-commands/server/stats-command.ts deleted file mode 100644 index 64a452306..000000000 --- a/shared/server-commands/server/stats-command.ts +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | import { HttpStatusCode, ServerStats } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class StatsCommand extends AbstractCommand { | ||
5 | |||
6 | get (options: OverrideCommandOptions & { | ||
7 | useCache?: boolean // default false | ||
8 | } = {}) { | ||
9 | const { useCache = false } = options | ||
10 | const path = '/api/v1/server/stats' | ||
11 | |||
12 | const query = { | ||
13 | t: useCache ? undefined : new Date().getTime() | ||
14 | } | ||
15 | |||
16 | return this.getRequestBody<ServerStats>({ | ||
17 | ...options, | ||
18 | |||
19 | path, | ||
20 | query, | ||
21 | implicitToken: false, | ||
22 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
23 | }) | ||
24 | } | ||
25 | } | ||
diff --git a/shared/server-commands/shared/abstract-command.ts b/shared/server-commands/shared/abstract-command.ts deleted file mode 100644 index 463acc26b..000000000 --- a/shared/server-commands/shared/abstract-command.ts +++ /dev/null | |||
@@ -1,223 +0,0 @@ | |||
1 | import { isAbsolute, join } from 'path' | ||
2 | import { root } from '@shared/core-utils' | ||
3 | import { | ||
4 | makeDeleteRequest, | ||
5 | makeGetRequest, | ||
6 | makePostBodyRequest, | ||
7 | makePutBodyRequest, | ||
8 | makeUploadRequest, | ||
9 | unwrapBody, | ||
10 | unwrapText | ||
11 | } from '../requests/requests' | ||
12 | import { PeerTubeServer } from '../server/server' | ||
13 | |||
14 | export interface OverrideCommandOptions { | ||
15 | token?: string | ||
16 | expectedStatus?: number | ||
17 | } | ||
18 | |||
19 | interface InternalCommonCommandOptions extends OverrideCommandOptions { | ||
20 | // Default to server.url | ||
21 | url?: string | ||
22 | |||
23 | path: string | ||
24 | // If we automatically send the server token if the token is not provided | ||
25 | implicitToken: boolean | ||
26 | defaultExpectedStatus: number | ||
27 | |||
28 | // Common optional request parameters | ||
29 | contentType?: string | ||
30 | accept?: string | ||
31 | redirects?: number | ||
32 | range?: string | ||
33 | host?: string | ||
34 | headers?: { [ name: string ]: string } | ||
35 | requestType?: string | ||
36 | responseType?: string | ||
37 | xForwardedFor?: string | ||
38 | } | ||
39 | |||
40 | interface InternalGetCommandOptions extends InternalCommonCommandOptions { | ||
41 | query?: { [ id: string ]: any } | ||
42 | } | ||
43 | |||
44 | interface InternalDeleteCommandOptions extends InternalCommonCommandOptions { | ||
45 | query?: { [ id: string ]: any } | ||
46 | rawQuery?: string | ||
47 | } | ||
48 | |||
49 | abstract class AbstractCommand { | ||
50 | |||
51 | constructor ( | ||
52 | protected server: PeerTubeServer | ||
53 | ) { | ||
54 | |||
55 | } | ||
56 | |||
57 | protected getRequestBody <T> (options: InternalGetCommandOptions) { | ||
58 | return unwrapBody<T>(this.getRequest(options)) | ||
59 | } | ||
60 | |||
61 | protected getRequestText (options: InternalGetCommandOptions) { | ||
62 | return unwrapText(this.getRequest(options)) | ||
63 | } | ||
64 | |||
65 | protected getRawRequest (options: Omit<InternalGetCommandOptions, 'path'>) { | ||
66 | const { url, range } = options | ||
67 | const { host, protocol, pathname } = new URL(url) | ||
68 | |||
69 | return this.getRequest({ | ||
70 | ...options, | ||
71 | |||
72 | token: this.buildCommonRequestToken(options), | ||
73 | defaultExpectedStatus: this.buildExpectedStatus(options), | ||
74 | |||
75 | url: `${protocol}//${host}`, | ||
76 | path: pathname, | ||
77 | range | ||
78 | }) | ||
79 | } | ||
80 | |||
81 | protected getRequest (options: InternalGetCommandOptions) { | ||
82 | const { query } = options | ||
83 | |||
84 | return makeGetRequest({ | ||
85 | ...this.buildCommonRequestOptions(options), | ||
86 | |||
87 | query | ||
88 | }) | ||
89 | } | ||
90 | |||
91 | protected deleteRequest (options: InternalDeleteCommandOptions) { | ||
92 | const { query, rawQuery } = options | ||
93 | |||
94 | return makeDeleteRequest({ | ||
95 | ...this.buildCommonRequestOptions(options), | ||
96 | |||
97 | query, | ||
98 | rawQuery | ||
99 | }) | ||
100 | } | ||
101 | |||
102 | protected putBodyRequest (options: InternalCommonCommandOptions & { | ||
103 | fields?: { [ fieldName: string ]: any } | ||
104 | headers?: { [name: string]: string } | ||
105 | }) { | ||
106 | const { fields, headers } = options | ||
107 | |||
108 | return makePutBodyRequest({ | ||
109 | ...this.buildCommonRequestOptions(options), | ||
110 | |||
111 | fields, | ||
112 | headers | ||
113 | }) | ||
114 | } | ||
115 | |||
116 | protected postBodyRequest (options: InternalCommonCommandOptions & { | ||
117 | fields?: { [ fieldName: string ]: any } | ||
118 | headers?: { [name: string]: string } | ||
119 | }) { | ||
120 | const { fields, headers } = options | ||
121 | |||
122 | return makePostBodyRequest({ | ||
123 | ...this.buildCommonRequestOptions(options), | ||
124 | |||
125 | fields, | ||
126 | headers | ||
127 | }) | ||
128 | } | ||
129 | |||
130 | protected postUploadRequest (options: InternalCommonCommandOptions & { | ||
131 | fields?: { [ fieldName: string ]: any } | ||
132 | attaches?: { [ fieldName: string ]: any } | ||
133 | }) { | ||
134 | const { fields, attaches } = options | ||
135 | |||
136 | return makeUploadRequest({ | ||
137 | ...this.buildCommonRequestOptions(options), | ||
138 | |||
139 | method: 'POST', | ||
140 | fields, | ||
141 | attaches | ||
142 | }) | ||
143 | } | ||
144 | |||
145 | protected putUploadRequest (options: InternalCommonCommandOptions & { | ||
146 | fields?: { [ fieldName: string ]: any } | ||
147 | attaches?: { [ fieldName: string ]: any } | ||
148 | }) { | ||
149 | const { fields, attaches } = options | ||
150 | |||
151 | return makeUploadRequest({ | ||
152 | ...this.buildCommonRequestOptions(options), | ||
153 | |||
154 | method: 'PUT', | ||
155 | fields, | ||
156 | attaches | ||
157 | }) | ||
158 | } | ||
159 | |||
160 | protected updateImageRequest (options: InternalCommonCommandOptions & { | ||
161 | fixture: string | ||
162 | fieldname: string | ||
163 | }) { | ||
164 | const filePath = isAbsolute(options.fixture) | ||
165 | ? options.fixture | ||
166 | : join(root(), 'server', 'tests', 'fixtures', options.fixture) | ||
167 | |||
168 | return this.postUploadRequest({ | ||
169 | ...options, | ||
170 | |||
171 | fields: {}, | ||
172 | attaches: { [options.fieldname]: filePath } | ||
173 | }) | ||
174 | } | ||
175 | |||
176 | protected buildCommonRequestOptions (options: InternalCommonCommandOptions) { | ||
177 | const { url, path, redirects, contentType, accept, range, host, headers, requestType, xForwardedFor, responseType } = options | ||
178 | |||
179 | return { | ||
180 | url: url ?? this.server.url, | ||
181 | path, | ||
182 | |||
183 | token: this.buildCommonRequestToken(options), | ||
184 | expectedStatus: this.buildExpectedStatus(options), | ||
185 | |||
186 | redirects, | ||
187 | contentType, | ||
188 | range, | ||
189 | host, | ||
190 | accept, | ||
191 | headers, | ||
192 | type: requestType, | ||
193 | responseType, | ||
194 | xForwardedFor | ||
195 | } | ||
196 | } | ||
197 | |||
198 | protected buildCommonRequestToken (options: Pick<InternalCommonCommandOptions, 'token' | 'implicitToken'>) { | ||
199 | const { token } = options | ||
200 | |||
201 | const fallbackToken = options.implicitToken | ||
202 | ? this.server.accessToken | ||
203 | : undefined | ||
204 | |||
205 | return token !== undefined ? token : fallbackToken | ||
206 | } | ||
207 | |||
208 | protected buildExpectedStatus (options: Pick<InternalCommonCommandOptions, 'expectedStatus' | 'defaultExpectedStatus'>) { | ||
209 | const { expectedStatus, defaultExpectedStatus } = options | ||
210 | |||
211 | return expectedStatus !== undefined ? expectedStatus : defaultExpectedStatus | ||
212 | } | ||
213 | |||
214 | protected buildVideoPasswordHeader (videoPassword: string) { | ||
215 | return videoPassword !== undefined && videoPassword !== null | ||
216 | ? { 'x-peertube-video-password': videoPassword } | ||
217 | : undefined | ||
218 | } | ||
219 | } | ||
220 | |||
221 | export { | ||
222 | AbstractCommand | ||
223 | } | ||
diff --git a/shared/server-commands/shared/index.ts b/shared/server-commands/shared/index.ts deleted file mode 100644 index e807ab4f7..000000000 --- a/shared/server-commands/shared/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './abstract-command' | ||
diff --git a/shared/server-commands/socket/index.ts b/shared/server-commands/socket/index.ts deleted file mode 100644 index 594329b2f..000000000 --- a/shared/server-commands/socket/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './socket-io-command' | ||
diff --git a/shared/server-commands/socket/socket-io-command.ts b/shared/server-commands/socket/socket-io-command.ts deleted file mode 100644 index c28a86366..000000000 --- a/shared/server-commands/socket/socket-io-command.ts +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | import { io } from 'socket.io-client' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class SocketIOCommand extends AbstractCommand { | ||
5 | |||
6 | getUserNotificationSocket (options: OverrideCommandOptions = {}) { | ||
7 | return io(this.server.url + '/user-notifications', { | ||
8 | query: { accessToken: options.token ?? this.server.accessToken } | ||
9 | }) | ||
10 | } | ||
11 | |||
12 | getLiveNotificationSocket () { | ||
13 | return io(this.server.url + '/live-videos') | ||
14 | } | ||
15 | |||
16 | getRunnersSocket (options: { | ||
17 | runnerToken: string | ||
18 | }) { | ||
19 | return io(this.server.url + '/runners', { | ||
20 | reconnection: false, | ||
21 | auth: { runnerToken: options.runnerToken } | ||
22 | }) | ||
23 | } | ||
24 | } | ||
diff --git a/shared/server-commands/users/accounts-command.ts b/shared/server-commands/users/accounts-command.ts deleted file mode 100644 index 5844b330b..000000000 --- a/shared/server-commands/users/accounts-command.ts +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | import { Account, AccountVideoRate, ActorFollow, HttpStatusCode, ResultList, VideoRateType } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class AccountsCommand extends AbstractCommand { | ||
5 | |||
6 | list (options: OverrideCommandOptions & { | ||
7 | sort?: string // default -createdAt | ||
8 | } = {}) { | ||
9 | const { sort = '-createdAt' } = options | ||
10 | const path = '/api/v1/accounts' | ||
11 | |||
12 | return this.getRequestBody<ResultList<Account>>({ | ||
13 | ...options, | ||
14 | |||
15 | path, | ||
16 | query: { sort }, | ||
17 | implicitToken: false, | ||
18 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
19 | }) | ||
20 | } | ||
21 | |||
22 | get (options: OverrideCommandOptions & { | ||
23 | accountName: string | ||
24 | }) { | ||
25 | const path = '/api/v1/accounts/' + options.accountName | ||
26 | |||
27 | return this.getRequestBody<Account>({ | ||
28 | ...options, | ||
29 | |||
30 | path, | ||
31 | implicitToken: false, | ||
32 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
33 | }) | ||
34 | } | ||
35 | |||
36 | listRatings (options: OverrideCommandOptions & { | ||
37 | accountName: string | ||
38 | rating?: VideoRateType | ||
39 | }) { | ||
40 | const { rating, accountName } = options | ||
41 | const path = '/api/v1/accounts/' + accountName + '/ratings' | ||
42 | |||
43 | const query = { rating } | ||
44 | |||
45 | return this.getRequestBody<ResultList<AccountVideoRate>>({ | ||
46 | ...options, | ||
47 | |||
48 | path, | ||
49 | query, | ||
50 | implicitToken: true, | ||
51 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
52 | }) | ||
53 | } | ||
54 | |||
55 | listFollowers (options: OverrideCommandOptions & { | ||
56 | accountName: string | ||
57 | start?: number | ||
58 | count?: number | ||
59 | sort?: string | ||
60 | search?: string | ||
61 | }) { | ||
62 | const { accountName, start, count, sort, search } = options | ||
63 | const path = '/api/v1/accounts/' + accountName + '/followers' | ||
64 | |||
65 | const query = { start, count, sort, search } | ||
66 | |||
67 | return this.getRequestBody<ResultList<ActorFollow>>({ | ||
68 | ...options, | ||
69 | |||
70 | path, | ||
71 | query, | ||
72 | implicitToken: true, | ||
73 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
74 | }) | ||
75 | } | ||
76 | } | ||
diff --git a/shared/server-commands/users/accounts.ts b/shared/server-commands/users/accounts.ts deleted file mode 100644 index 6387891f4..000000000 --- a/shared/server-commands/users/accounts.ts +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | import { PeerTubeServer } from '../server/server' | ||
2 | |||
3 | async function setDefaultAccountAvatar (serversArg: PeerTubeServer | PeerTubeServer[], token?: string) { | ||
4 | const servers = Array.isArray(serversArg) | ||
5 | ? serversArg | ||
6 | : [ serversArg ] | ||
7 | |||
8 | for (const server of servers) { | ||
9 | await server.users.updateMyAvatar({ fixture: 'avatar.png', token }) | ||
10 | } | ||
11 | } | ||
12 | |||
13 | export { | ||
14 | setDefaultAccountAvatar | ||
15 | } | ||
diff --git a/shared/server-commands/users/blocklist-command.ts b/shared/server-commands/users/blocklist-command.ts deleted file mode 100644 index 862d8945e..000000000 --- a/shared/server-commands/users/blocklist-command.ts +++ /dev/null | |||
@@ -1,165 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { AccountBlock, BlockStatus, HttpStatusCode, ResultList, ServerBlock } from '@shared/models' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | type ListBlocklistOptions = OverrideCommandOptions & { | ||
7 | start: number | ||
8 | count: number | ||
9 | |||
10 | sort?: string // default -createdAt | ||
11 | |||
12 | search?: string | ||
13 | } | ||
14 | |||
15 | export class BlocklistCommand extends AbstractCommand { | ||
16 | |||
17 | listMyAccountBlocklist (options: ListBlocklistOptions) { | ||
18 | const path = '/api/v1/users/me/blocklist/accounts' | ||
19 | |||
20 | return this.listBlocklist<AccountBlock>(options, path) | ||
21 | } | ||
22 | |||
23 | listMyServerBlocklist (options: ListBlocklistOptions) { | ||
24 | const path = '/api/v1/users/me/blocklist/servers' | ||
25 | |||
26 | return this.listBlocklist<ServerBlock>(options, path) | ||
27 | } | ||
28 | |||
29 | listServerAccountBlocklist (options: ListBlocklistOptions) { | ||
30 | const path = '/api/v1/server/blocklist/accounts' | ||
31 | |||
32 | return this.listBlocklist<AccountBlock>(options, path) | ||
33 | } | ||
34 | |||
35 | listServerServerBlocklist (options: ListBlocklistOptions) { | ||
36 | const path = '/api/v1/server/blocklist/servers' | ||
37 | |||
38 | return this.listBlocklist<ServerBlock>(options, path) | ||
39 | } | ||
40 | |||
41 | // --------------------------------------------------------------------------- | ||
42 | |||
43 | getStatus (options: OverrideCommandOptions & { | ||
44 | accounts?: string[] | ||
45 | hosts?: string[] | ||
46 | }) { | ||
47 | const { accounts, hosts } = options | ||
48 | |||
49 | const path = '/api/v1/blocklist/status' | ||
50 | |||
51 | return this.getRequestBody<BlockStatus>({ | ||
52 | ...options, | ||
53 | |||
54 | path, | ||
55 | query: { | ||
56 | accounts, | ||
57 | hosts | ||
58 | }, | ||
59 | implicitToken: false, | ||
60 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
61 | }) | ||
62 | } | ||
63 | |||
64 | // --------------------------------------------------------------------------- | ||
65 | |||
66 | addToMyBlocklist (options: OverrideCommandOptions & { | ||
67 | account?: string | ||
68 | server?: string | ||
69 | }) { | ||
70 | const { account, server } = options | ||
71 | |||
72 | const path = account | ||
73 | ? '/api/v1/users/me/blocklist/accounts' | ||
74 | : '/api/v1/users/me/blocklist/servers' | ||
75 | |||
76 | return this.postBodyRequest({ | ||
77 | ...options, | ||
78 | |||
79 | path, | ||
80 | fields: { | ||
81 | accountName: account, | ||
82 | host: server | ||
83 | }, | ||
84 | implicitToken: true, | ||
85 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
86 | }) | ||
87 | } | ||
88 | |||
89 | addToServerBlocklist (options: OverrideCommandOptions & { | ||
90 | account?: string | ||
91 | server?: string | ||
92 | }) { | ||
93 | const { account, server } = options | ||
94 | |||
95 | const path = account | ||
96 | ? '/api/v1/server/blocklist/accounts' | ||
97 | : '/api/v1/server/blocklist/servers' | ||
98 | |||
99 | return this.postBodyRequest({ | ||
100 | ...options, | ||
101 | |||
102 | path, | ||
103 | fields: { | ||
104 | accountName: account, | ||
105 | host: server | ||
106 | }, | ||
107 | implicitToken: true, | ||
108 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
109 | }) | ||
110 | } | ||
111 | |||
112 | // --------------------------------------------------------------------------- | ||
113 | |||
114 | removeFromMyBlocklist (options: OverrideCommandOptions & { | ||
115 | account?: string | ||
116 | server?: string | ||
117 | }) { | ||
118 | const { account, server } = options | ||
119 | |||
120 | const path = account | ||
121 | ? '/api/v1/users/me/blocklist/accounts/' + account | ||
122 | : '/api/v1/users/me/blocklist/servers/' + server | ||
123 | |||
124 | return this.deleteRequest({ | ||
125 | ...options, | ||
126 | |||
127 | path, | ||
128 | implicitToken: true, | ||
129 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
130 | }) | ||
131 | } | ||
132 | |||
133 | removeFromServerBlocklist (options: OverrideCommandOptions & { | ||
134 | account?: string | ||
135 | server?: string | ||
136 | }) { | ||
137 | const { account, server } = options | ||
138 | |||
139 | const path = account | ||
140 | ? '/api/v1/server/blocklist/accounts/' + account | ||
141 | : '/api/v1/server/blocklist/servers/' + server | ||
142 | |||
143 | return this.deleteRequest({ | ||
144 | ...options, | ||
145 | |||
146 | path, | ||
147 | implicitToken: true, | ||
148 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
149 | }) | ||
150 | } | ||
151 | |||
152 | private listBlocklist <T> (options: ListBlocklistOptions, path: string) { | ||
153 | const { start, count, search, sort = '-createdAt' } = options | ||
154 | |||
155 | return this.getRequestBody<ResultList<T>>({ | ||
156 | ...options, | ||
157 | |||
158 | path, | ||
159 | query: { start, count, sort, search }, | ||
160 | implicitToken: true, | ||
161 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
162 | }) | ||
163 | } | ||
164 | |||
165 | } | ||
diff --git a/shared/server-commands/users/index.ts b/shared/server-commands/users/index.ts deleted file mode 100644 index 404756539..000000000 --- a/shared/server-commands/users/index.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | export * from './accounts-command' | ||
2 | export * from './accounts' | ||
3 | export * from './blocklist-command' | ||
4 | export * from './login' | ||
5 | export * from './login-command' | ||
6 | export * from './notifications-command' | ||
7 | export * from './registrations-command' | ||
8 | export * from './subscriptions-command' | ||
9 | export * from './two-factor-command' | ||
10 | export * from './users-command' | ||
diff --git a/shared/server-commands/users/login-command.ts b/shared/server-commands/users/login-command.ts deleted file mode 100644 index f2fc6d1c5..000000000 --- a/shared/server-commands/users/login-command.ts +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | import { HttpStatusCode, PeerTubeProblemDocument } from '@shared/models' | ||
2 | import { unwrapBody } from '../requests' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | type LoginOptions = OverrideCommandOptions & { | ||
6 | client?: { id?: string, secret?: string } | ||
7 | user?: { username: string, password?: string } | ||
8 | otpToken?: string | ||
9 | } | ||
10 | |||
11 | export class LoginCommand extends AbstractCommand { | ||
12 | |||
13 | async login (options: LoginOptions = {}) { | ||
14 | const res = await this._login(options) | ||
15 | |||
16 | return this.unwrapLoginBody(res.body) | ||
17 | } | ||
18 | |||
19 | async loginAndGetResponse (options: LoginOptions = {}) { | ||
20 | const res = await this._login(options) | ||
21 | |||
22 | return { | ||
23 | res, | ||
24 | body: this.unwrapLoginBody(res.body) | ||
25 | } | ||
26 | } | ||
27 | |||
28 | getAccessToken (arg1?: { username: string, password?: string }): Promise<string> | ||
29 | getAccessToken (arg1: string, password?: string): Promise<string> | ||
30 | async getAccessToken (arg1?: { username: string, password?: string } | string, password?: string) { | ||
31 | let user: { username: string, password?: string } | ||
32 | |||
33 | if (!arg1) user = this.server.store.user | ||
34 | else if (typeof arg1 === 'object') user = arg1 | ||
35 | else user = { username: arg1, password } | ||
36 | |||
37 | try { | ||
38 | const body = await this.login({ user }) | ||
39 | |||
40 | return body.access_token | ||
41 | } catch (err) { | ||
42 | throw new Error(`Cannot authenticate. Please check your username/password. (${err})`) | ||
43 | } | ||
44 | } | ||
45 | |||
46 | loginUsingExternalToken (options: OverrideCommandOptions & { | ||
47 | username: string | ||
48 | externalAuthToken: string | ||
49 | }) { | ||
50 | const { username, externalAuthToken } = options | ||
51 | const path = '/api/v1/users/token' | ||
52 | |||
53 | const body = { | ||
54 | client_id: this.server.store.client.id, | ||
55 | client_secret: this.server.store.client.secret, | ||
56 | username, | ||
57 | response_type: 'code', | ||
58 | grant_type: 'password', | ||
59 | scope: 'upload', | ||
60 | externalAuthToken | ||
61 | } | ||
62 | |||
63 | return this.postBodyRequest({ | ||
64 | ...options, | ||
65 | |||
66 | path, | ||
67 | requestType: 'form', | ||
68 | fields: body, | ||
69 | implicitToken: false, | ||
70 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
71 | }) | ||
72 | } | ||
73 | |||
74 | logout (options: OverrideCommandOptions & { | ||
75 | token: string | ||
76 | }) { | ||
77 | const path = '/api/v1/users/revoke-token' | ||
78 | |||
79 | return unwrapBody<{ redirectUrl: string }>(this.postBodyRequest({ | ||
80 | ...options, | ||
81 | |||
82 | path, | ||
83 | requestType: 'form', | ||
84 | implicitToken: false, | ||
85 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
86 | })) | ||
87 | } | ||
88 | |||
89 | refreshToken (options: OverrideCommandOptions & { | ||
90 | refreshToken: string | ||
91 | }) { | ||
92 | const path = '/api/v1/users/token' | ||
93 | |||
94 | const body = { | ||
95 | client_id: this.server.store.client.id, | ||
96 | client_secret: this.server.store.client.secret, | ||
97 | refresh_token: options.refreshToken, | ||
98 | response_type: 'code', | ||
99 | grant_type: 'refresh_token' | ||
100 | } | ||
101 | |||
102 | return this.postBodyRequest({ | ||
103 | ...options, | ||
104 | |||
105 | path, | ||
106 | requestType: 'form', | ||
107 | fields: body, | ||
108 | implicitToken: false, | ||
109 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
110 | }) | ||
111 | } | ||
112 | |||
113 | getClient (options: OverrideCommandOptions = {}) { | ||
114 | const path = '/api/v1/oauth-clients/local' | ||
115 | |||
116 | return this.getRequestBody<{ client_id: string, client_secret: string }>({ | ||
117 | ...options, | ||
118 | |||
119 | path, | ||
120 | host: this.server.host, | ||
121 | implicitToken: false, | ||
122 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
123 | }) | ||
124 | } | ||
125 | |||
126 | private _login (options: LoginOptions) { | ||
127 | const { client = this.server.store.client, user = this.server.store.user, otpToken } = options | ||
128 | const path = '/api/v1/users/token' | ||
129 | |||
130 | const body = { | ||
131 | client_id: client.id, | ||
132 | client_secret: client.secret, | ||
133 | username: user.username, | ||
134 | password: user.password ?? 'password', | ||
135 | response_type: 'code', | ||
136 | grant_type: 'password', | ||
137 | scope: 'upload' | ||
138 | } | ||
139 | |||
140 | const headers = otpToken | ||
141 | ? { 'x-peertube-otp': otpToken } | ||
142 | : {} | ||
143 | |||
144 | return this.postBodyRequest({ | ||
145 | ...options, | ||
146 | |||
147 | path, | ||
148 | headers, | ||
149 | requestType: 'form', | ||
150 | fields: body, | ||
151 | implicitToken: false, | ||
152 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
153 | }) | ||
154 | } | ||
155 | |||
156 | private unwrapLoginBody (body: any) { | ||
157 | return body as { access_token: string, refresh_token: string } & PeerTubeProblemDocument | ||
158 | } | ||
159 | } | ||
diff --git a/shared/server-commands/users/login.ts b/shared/server-commands/users/login.ts deleted file mode 100644 index f1df027d3..000000000 --- a/shared/server-commands/users/login.ts +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | import { PeerTubeServer } from '../server/server' | ||
2 | |||
3 | function setAccessTokensToServers (servers: PeerTubeServer[]) { | ||
4 | const tasks: Promise<any>[] = [] | ||
5 | |||
6 | for (const server of servers) { | ||
7 | const p = server.login.getAccessToken() | ||
8 | .then(t => { server.accessToken = t }) | ||
9 | tasks.push(p) | ||
10 | } | ||
11 | |||
12 | return Promise.all(tasks) | ||
13 | } | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | export { | ||
18 | setAccessTokensToServers | ||
19 | } | ||
diff --git a/shared/server-commands/users/notifications-command.ts b/shared/server-commands/users/notifications-command.ts deleted file mode 100644 index 6bd815daa..000000000 --- a/shared/server-commands/users/notifications-command.ts +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | import { HttpStatusCode, ResultList, UserNotification, UserNotificationSetting } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class NotificationsCommand extends AbstractCommand { | ||
5 | |||
6 | updateMySettings (options: OverrideCommandOptions & { | ||
7 | settings: UserNotificationSetting | ||
8 | }) { | ||
9 | const path = '/api/v1/users/me/notification-settings' | ||
10 | |||
11 | return this.putBodyRequest({ | ||
12 | ...options, | ||
13 | |||
14 | path, | ||
15 | fields: options.settings, | ||
16 | implicitToken: true, | ||
17 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | list (options: OverrideCommandOptions & { | ||
22 | start?: number | ||
23 | count?: number | ||
24 | unread?: boolean | ||
25 | sort?: string | ||
26 | }) { | ||
27 | const { start, count, unread, sort = '-createdAt' } = options | ||
28 | const path = '/api/v1/users/me/notifications' | ||
29 | |||
30 | return this.getRequestBody<ResultList<UserNotification>>({ | ||
31 | ...options, | ||
32 | |||
33 | path, | ||
34 | query: { | ||
35 | start, | ||
36 | count, | ||
37 | sort, | ||
38 | unread | ||
39 | }, | ||
40 | implicitToken: true, | ||
41 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
42 | }) | ||
43 | } | ||
44 | |||
45 | markAsRead (options: OverrideCommandOptions & { | ||
46 | ids: number[] | ||
47 | }) { | ||
48 | const { ids } = options | ||
49 | const path = '/api/v1/users/me/notifications/read' | ||
50 | |||
51 | return this.postBodyRequest({ | ||
52 | ...options, | ||
53 | |||
54 | path, | ||
55 | fields: { ids }, | ||
56 | implicitToken: true, | ||
57 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
58 | }) | ||
59 | } | ||
60 | |||
61 | markAsReadAll (options: OverrideCommandOptions) { | ||
62 | const path = '/api/v1/users/me/notifications/read-all' | ||
63 | |||
64 | return this.postBodyRequest({ | ||
65 | ...options, | ||
66 | |||
67 | path, | ||
68 | implicitToken: true, | ||
69 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
70 | }) | ||
71 | } | ||
72 | |||
73 | async getLatest (options: OverrideCommandOptions = {}) { | ||
74 | const { total, data } = await this.list({ | ||
75 | ...options, | ||
76 | start: 0, | ||
77 | count: 1, | ||
78 | sort: '-createdAt' | ||
79 | }) | ||
80 | |||
81 | if (total === 0) return undefined | ||
82 | |||
83 | return data[0] | ||
84 | } | ||
85 | } | ||
diff --git a/shared/server-commands/users/registrations-command.ts b/shared/server-commands/users/registrations-command.ts deleted file mode 100644 index f57f54b34..000000000 --- a/shared/server-commands/users/registrations-command.ts +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { HttpStatusCode, ResultList, UserRegistration, UserRegistrationRequest, UserRegistrationUpdateState } from '@shared/models' | ||
3 | import { unwrapBody } from '../requests' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class RegistrationsCommand extends AbstractCommand { | ||
7 | |||
8 | register (options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username'>) { | ||
9 | const { password = 'password', email = options.username + '@example.com' } = options | ||
10 | const path = '/api/v1/users/register' | ||
11 | |||
12 | return this.postBodyRequest({ | ||
13 | ...options, | ||
14 | |||
15 | path, | ||
16 | fields: { | ||
17 | ...pick(options, [ 'username', 'displayName', 'channel' ]), | ||
18 | |||
19 | password, | ||
20 | |||
21 | }, | ||
22 | implicitToken: false, | ||
23 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
24 | }) | ||
25 | } | ||
26 | |||
27 | requestRegistration ( | ||
28 | options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username' | 'registrationReason'> | ||
29 | ) { | ||
30 | const { password = 'password', email = options.username + '@example.com' } = options | ||
31 | const path = '/api/v1/users/registrations/request' | ||
32 | |||
33 | return unwrapBody<UserRegistration>(this.postBodyRequest({ | ||
34 | ...options, | ||
35 | |||
36 | path, | ||
37 | fields: { | ||
38 | ...pick(options, [ 'username', 'displayName', 'channel', 'registrationReason' ]), | ||
39 | |||
40 | password, | ||
41 | |||
42 | }, | ||
43 | implicitToken: false, | ||
44 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
45 | })) | ||
46 | } | ||
47 | |||
48 | // --------------------------------------------------------------------------- | ||
49 | |||
50 | accept (options: OverrideCommandOptions & { id: number } & UserRegistrationUpdateState) { | ||
51 | const { id } = options | ||
52 | const path = '/api/v1/users/registrations/' + id + '/accept' | ||
53 | |||
54 | return this.postBodyRequest({ | ||
55 | ...options, | ||
56 | |||
57 | path, | ||
58 | fields: pick(options, [ 'moderationResponse', 'preventEmailDelivery' ]), | ||
59 | implicitToken: true, | ||
60 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
61 | }) | ||
62 | } | ||
63 | |||
64 | reject (options: OverrideCommandOptions & { id: number } & UserRegistrationUpdateState) { | ||
65 | const { id } = options | ||
66 | const path = '/api/v1/users/registrations/' + id + '/reject' | ||
67 | |||
68 | return this.postBodyRequest({ | ||
69 | ...options, | ||
70 | |||
71 | path, | ||
72 | fields: pick(options, [ 'moderationResponse', 'preventEmailDelivery' ]), | ||
73 | implicitToken: true, | ||
74 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
75 | }) | ||
76 | } | ||
77 | |||
78 | // --------------------------------------------------------------------------- | ||
79 | |||
80 | delete (options: OverrideCommandOptions & { | ||
81 | id: number | ||
82 | }) { | ||
83 | const { id } = options | ||
84 | const path = '/api/v1/users/registrations/' + id | ||
85 | |||
86 | return this.deleteRequest({ | ||
87 | ...options, | ||
88 | |||
89 | path, | ||
90 | implicitToken: true, | ||
91 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
92 | }) | ||
93 | } | ||
94 | |||
95 | // --------------------------------------------------------------------------- | ||
96 | |||
97 | list (options: OverrideCommandOptions & { | ||
98 | start?: number | ||
99 | count?: number | ||
100 | sort?: string | ||
101 | search?: string | ||
102 | } = {}) { | ||
103 | const path = '/api/v1/users/registrations' | ||
104 | |||
105 | return this.getRequestBody<ResultList<UserRegistration>>({ | ||
106 | ...options, | ||
107 | |||
108 | path, | ||
109 | query: pick(options, [ 'start', 'count', 'sort', 'search' ]), | ||
110 | implicitToken: true, | ||
111 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
112 | }) | ||
113 | } | ||
114 | |||
115 | // --------------------------------------------------------------------------- | ||
116 | |||
117 | askSendVerifyEmail (options: OverrideCommandOptions & { | ||
118 | email: string | ||
119 | }) { | ||
120 | const { email } = options | ||
121 | const path = '/api/v1/users/registrations/ask-send-verify-email' | ||
122 | |||
123 | return this.postBodyRequest({ | ||
124 | ...options, | ||
125 | |||
126 | path, | ||
127 | fields: { email }, | ||
128 | implicitToken: false, | ||
129 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
130 | }) | ||
131 | } | ||
132 | |||
133 | verifyEmail (options: OverrideCommandOptions & { | ||
134 | registrationId: number | ||
135 | verificationString: string | ||
136 | }) { | ||
137 | const { registrationId, verificationString } = options | ||
138 | const path = '/api/v1/users/registrations/' + registrationId + '/verify-email' | ||
139 | |||
140 | return this.postBodyRequest({ | ||
141 | ...options, | ||
142 | |||
143 | path, | ||
144 | fields: { | ||
145 | verificationString | ||
146 | }, | ||
147 | implicitToken: false, | ||
148 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
149 | }) | ||
150 | } | ||
151 | } | ||
diff --git a/shared/server-commands/users/subscriptions-command.ts b/shared/server-commands/users/subscriptions-command.ts deleted file mode 100644 index b92f037f8..000000000 --- a/shared/server-commands/users/subscriptions-command.ts +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | import { HttpStatusCode, ResultList, VideoChannel } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class SubscriptionsCommand extends AbstractCommand { | ||
5 | |||
6 | add (options: OverrideCommandOptions & { | ||
7 | targetUri: string | ||
8 | }) { | ||
9 | const path = '/api/v1/users/me/subscriptions' | ||
10 | |||
11 | return this.postBodyRequest({ | ||
12 | ...options, | ||
13 | |||
14 | path, | ||
15 | fields: { uri: options.targetUri }, | ||
16 | implicitToken: true, | ||
17 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | list (options: OverrideCommandOptions & { | ||
22 | sort?: string // default -createdAt | ||
23 | search?: string | ||
24 | } = {}) { | ||
25 | const { sort = '-createdAt', search } = options | ||
26 | const path = '/api/v1/users/me/subscriptions' | ||
27 | |||
28 | return this.getRequestBody<ResultList<VideoChannel>>({ | ||
29 | ...options, | ||
30 | |||
31 | path, | ||
32 | query: { | ||
33 | sort, | ||
34 | search | ||
35 | }, | ||
36 | implicitToken: true, | ||
37 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
38 | }) | ||
39 | } | ||
40 | |||
41 | get (options: OverrideCommandOptions & { | ||
42 | uri: string | ||
43 | }) { | ||
44 | const path = '/api/v1/users/me/subscriptions/' + options.uri | ||
45 | |||
46 | return this.getRequestBody<VideoChannel>({ | ||
47 | ...options, | ||
48 | |||
49 | path, | ||
50 | implicitToken: true, | ||
51 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
52 | }) | ||
53 | } | ||
54 | |||
55 | remove (options: OverrideCommandOptions & { | ||
56 | uri: string | ||
57 | }) { | ||
58 | const path = '/api/v1/users/me/subscriptions/' + options.uri | ||
59 | |||
60 | return this.deleteRequest({ | ||
61 | ...options, | ||
62 | |||
63 | path, | ||
64 | implicitToken: true, | ||
65 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
66 | }) | ||
67 | } | ||
68 | |||
69 | exist (options: OverrideCommandOptions & { | ||
70 | uris: string[] | ||
71 | }) { | ||
72 | const path = '/api/v1/users/me/subscriptions/exist' | ||
73 | |||
74 | return this.getRequestBody<{ [id: string ]: boolean }>({ | ||
75 | ...options, | ||
76 | |||
77 | path, | ||
78 | query: { 'uris[]': options.uris }, | ||
79 | implicitToken: true, | ||
80 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
81 | }) | ||
82 | } | ||
83 | } | ||
diff --git a/shared/server-commands/users/two-factor-command.ts b/shared/server-commands/users/two-factor-command.ts deleted file mode 100644 index 5542acfda..000000000 --- a/shared/server-commands/users/two-factor-command.ts +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | import { TOTP } from 'otpauth' | ||
2 | import { HttpStatusCode, TwoFactorEnableResult } from '@shared/models' | ||
3 | import { unwrapBody } from '../requests' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class TwoFactorCommand extends AbstractCommand { | ||
7 | |||
8 | static buildOTP (options: { | ||
9 | secret: string | ||
10 | }) { | ||
11 | const { secret } = options | ||
12 | |||
13 | return new TOTP({ | ||
14 | issuer: 'PeerTube', | ||
15 | algorithm: 'SHA1', | ||
16 | digits: 6, | ||
17 | period: 30, | ||
18 | secret | ||
19 | }) | ||
20 | } | ||
21 | |||
22 | request (options: OverrideCommandOptions & { | ||
23 | userId: number | ||
24 | currentPassword?: string | ||
25 | }) { | ||
26 | const { currentPassword, userId } = options | ||
27 | |||
28 | const path = '/api/v1/users/' + userId + '/two-factor/request' | ||
29 | |||
30 | return unwrapBody<TwoFactorEnableResult>(this.postBodyRequest({ | ||
31 | ...options, | ||
32 | |||
33 | path, | ||
34 | fields: { currentPassword }, | ||
35 | implicitToken: true, | ||
36 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
37 | })) | ||
38 | } | ||
39 | |||
40 | confirmRequest (options: OverrideCommandOptions & { | ||
41 | userId: number | ||
42 | requestToken: string | ||
43 | otpToken: string | ||
44 | }) { | ||
45 | const { userId, requestToken, otpToken } = options | ||
46 | |||
47 | const path = '/api/v1/users/' + userId + '/two-factor/confirm-request' | ||
48 | |||
49 | return this.postBodyRequest({ | ||
50 | ...options, | ||
51 | |||
52 | path, | ||
53 | fields: { requestToken, otpToken }, | ||
54 | implicitToken: true, | ||
55 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
56 | }) | ||
57 | } | ||
58 | |||
59 | disable (options: OverrideCommandOptions & { | ||
60 | userId: number | ||
61 | currentPassword?: string | ||
62 | }) { | ||
63 | const { userId, currentPassword } = options | ||
64 | const path = '/api/v1/users/' + userId + '/two-factor/disable' | ||
65 | |||
66 | return this.postBodyRequest({ | ||
67 | ...options, | ||
68 | |||
69 | path, | ||
70 | fields: { currentPassword }, | ||
71 | implicitToken: true, | ||
72 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
73 | }) | ||
74 | } | ||
75 | |||
76 | async requestAndConfirm (options: OverrideCommandOptions & { | ||
77 | userId: number | ||
78 | currentPassword?: string | ||
79 | }) { | ||
80 | const { userId, currentPassword } = options | ||
81 | |||
82 | const { otpRequest } = await this.request({ userId, currentPassword }) | ||
83 | |||
84 | await this.confirmRequest({ | ||
85 | userId, | ||
86 | requestToken: otpRequest.requestToken, | ||
87 | otpToken: TwoFactorCommand.buildOTP({ secret: otpRequest.secret }).generate() | ||
88 | }) | ||
89 | |||
90 | return otpRequest | ||
91 | } | ||
92 | } | ||
diff --git a/shared/server-commands/users/users-command.ts b/shared/server-commands/users/users-command.ts deleted file mode 100644 index 5b39d3488..000000000 --- a/shared/server-commands/users/users-command.ts +++ /dev/null | |||
@@ -1,388 +0,0 @@ | |||
1 | import { omit, pick } from '@shared/core-utils' | ||
2 | import { | ||
3 | HttpStatusCode, | ||
4 | MyUser, | ||
5 | ResultList, | ||
6 | ScopedToken, | ||
7 | User, | ||
8 | UserAdminFlag, | ||
9 | UserCreateResult, | ||
10 | UserRole, | ||
11 | UserUpdate, | ||
12 | UserUpdateMe, | ||
13 | UserVideoQuota, | ||
14 | UserVideoRate | ||
15 | } from '@shared/models' | ||
16 | import { unwrapBody } from '../requests' | ||
17 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
18 | |||
19 | export class UsersCommand extends AbstractCommand { | ||
20 | |||
21 | askResetPassword (options: OverrideCommandOptions & { | ||
22 | email: string | ||
23 | }) { | ||
24 | const { email } = options | ||
25 | const path = '/api/v1/users/ask-reset-password' | ||
26 | |||
27 | return this.postBodyRequest({ | ||
28 | ...options, | ||
29 | |||
30 | path, | ||
31 | fields: { email }, | ||
32 | implicitToken: false, | ||
33 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
34 | }) | ||
35 | } | ||
36 | |||
37 | resetPassword (options: OverrideCommandOptions & { | ||
38 | userId: number | ||
39 | verificationString: string | ||
40 | password: string | ||
41 | }) { | ||
42 | const { userId, verificationString, password } = options | ||
43 | const path = '/api/v1/users/' + userId + '/reset-password' | ||
44 | |||
45 | return this.postBodyRequest({ | ||
46 | ...options, | ||
47 | |||
48 | path, | ||
49 | fields: { password, verificationString }, | ||
50 | implicitToken: false, | ||
51 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
52 | }) | ||
53 | } | ||
54 | |||
55 | // --------------------------------------------------------------------------- | ||
56 | |||
57 | askSendVerifyEmail (options: OverrideCommandOptions & { | ||
58 | email: string | ||
59 | }) { | ||
60 | const { email } = options | ||
61 | const path = '/api/v1/users/ask-send-verify-email' | ||
62 | |||
63 | return this.postBodyRequest({ | ||
64 | ...options, | ||
65 | |||
66 | path, | ||
67 | fields: { email }, | ||
68 | implicitToken: false, | ||
69 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
70 | }) | ||
71 | } | ||
72 | |||
73 | verifyEmail (options: OverrideCommandOptions & { | ||
74 | userId: number | ||
75 | verificationString: string | ||
76 | isPendingEmail?: boolean // default false | ||
77 | }) { | ||
78 | const { userId, verificationString, isPendingEmail = false } = options | ||
79 | const path = '/api/v1/users/' + userId + '/verify-email' | ||
80 | |||
81 | return this.postBodyRequest({ | ||
82 | ...options, | ||
83 | |||
84 | path, | ||
85 | fields: { | ||
86 | verificationString, | ||
87 | isPendingEmail | ||
88 | }, | ||
89 | implicitToken: false, | ||
90 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
91 | }) | ||
92 | } | ||
93 | |||
94 | // --------------------------------------------------------------------------- | ||
95 | |||
96 | banUser (options: OverrideCommandOptions & { | ||
97 | userId: number | ||
98 | reason?: string | ||
99 | }) { | ||
100 | const { userId, reason } = options | ||
101 | const path = '/api/v1/users' + '/' + userId + '/block' | ||
102 | |||
103 | return this.postBodyRequest({ | ||
104 | ...options, | ||
105 | |||
106 | path, | ||
107 | fields: { reason }, | ||
108 | implicitToken: true, | ||
109 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
110 | }) | ||
111 | } | ||
112 | |||
113 | unbanUser (options: OverrideCommandOptions & { | ||
114 | userId: number | ||
115 | }) { | ||
116 | const { userId } = options | ||
117 | const path = '/api/v1/users' + '/' + userId + '/unblock' | ||
118 | |||
119 | return this.postBodyRequest({ | ||
120 | ...options, | ||
121 | |||
122 | path, | ||
123 | implicitToken: true, | ||
124 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
125 | }) | ||
126 | } | ||
127 | |||
128 | // --------------------------------------------------------------------------- | ||
129 | |||
130 | getMyScopedTokens (options: OverrideCommandOptions = {}) { | ||
131 | const path = '/api/v1/users/scoped-tokens' | ||
132 | |||
133 | return this.getRequestBody<ScopedToken>({ | ||
134 | ...options, | ||
135 | |||
136 | path, | ||
137 | implicitToken: true, | ||
138 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
139 | }) | ||
140 | } | ||
141 | |||
142 | renewMyScopedTokens (options: OverrideCommandOptions = {}) { | ||
143 | const path = '/api/v1/users/scoped-tokens' | ||
144 | |||
145 | return this.postBodyRequest({ | ||
146 | ...options, | ||
147 | |||
148 | path, | ||
149 | implicitToken: true, | ||
150 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
151 | }) | ||
152 | } | ||
153 | |||
154 | // --------------------------------------------------------------------------- | ||
155 | |||
156 | create (options: OverrideCommandOptions & { | ||
157 | username: string | ||
158 | password?: string | ||
159 | videoQuota?: number | ||
160 | videoQuotaDaily?: number | ||
161 | role?: UserRole | ||
162 | adminFlags?: UserAdminFlag | ||
163 | }) { | ||
164 | const { | ||
165 | username, | ||
166 | adminFlags, | ||
167 | password = 'password', | ||
168 | videoQuota, | ||
169 | videoQuotaDaily, | ||
170 | role = UserRole.USER | ||
171 | } = options | ||
172 | |||
173 | const path = '/api/v1/users' | ||
174 | |||
175 | return unwrapBody<{ user: UserCreateResult }>(this.postBodyRequest({ | ||
176 | ...options, | ||
177 | |||
178 | path, | ||
179 | fields: { | ||
180 | username, | ||
181 | password, | ||
182 | role, | ||
183 | adminFlags, | ||
184 | email: username + '@example.com', | ||
185 | videoQuota, | ||
186 | videoQuotaDaily | ||
187 | }, | ||
188 | implicitToken: true, | ||
189 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
190 | })).then(res => res.user) | ||
191 | } | ||
192 | |||
193 | async generate (username: string, role?: UserRole) { | ||
194 | const password = 'password' | ||
195 | const user = await this.create({ username, password, role }) | ||
196 | |||
197 | const token = await this.server.login.getAccessToken({ username, password }) | ||
198 | |||
199 | const me = await this.getMyInfo({ token }) | ||
200 | |||
201 | return { | ||
202 | token, | ||
203 | userId: user.id, | ||
204 | userChannelId: me.videoChannels[0].id, | ||
205 | userChannelName: me.videoChannels[0].name, | ||
206 | password | ||
207 | } | ||
208 | } | ||
209 | |||
210 | async generateUserAndToken (username: string, role?: UserRole) { | ||
211 | const password = 'password' | ||
212 | await this.create({ username, password, role }) | ||
213 | |||
214 | return this.server.login.getAccessToken({ username, password }) | ||
215 | } | ||
216 | |||
217 | // --------------------------------------------------------------------------- | ||
218 | |||
219 | getMyInfo (options: OverrideCommandOptions = {}) { | ||
220 | const path = '/api/v1/users/me' | ||
221 | |||
222 | return this.getRequestBody<MyUser>({ | ||
223 | ...options, | ||
224 | |||
225 | path, | ||
226 | implicitToken: true, | ||
227 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
228 | }) | ||
229 | } | ||
230 | |||
231 | getMyQuotaUsed (options: OverrideCommandOptions = {}) { | ||
232 | const path = '/api/v1/users/me/video-quota-used' | ||
233 | |||
234 | return this.getRequestBody<UserVideoQuota>({ | ||
235 | ...options, | ||
236 | |||
237 | path, | ||
238 | implicitToken: true, | ||
239 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
240 | }) | ||
241 | } | ||
242 | |||
243 | getMyRating (options: OverrideCommandOptions & { | ||
244 | videoId: number | string | ||
245 | }) { | ||
246 | const { videoId } = options | ||
247 | const path = '/api/v1/users/me/videos/' + videoId + '/rating' | ||
248 | |||
249 | return this.getRequestBody<UserVideoRate>({ | ||
250 | ...options, | ||
251 | |||
252 | path, | ||
253 | implicitToken: true, | ||
254 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
255 | }) | ||
256 | } | ||
257 | |||
258 | deleteMe (options: OverrideCommandOptions = {}) { | ||
259 | const path = '/api/v1/users/me' | ||
260 | |||
261 | return this.deleteRequest({ | ||
262 | ...options, | ||
263 | |||
264 | path, | ||
265 | implicitToken: true, | ||
266 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
267 | }) | ||
268 | } | ||
269 | |||
270 | updateMe (options: OverrideCommandOptions & UserUpdateMe) { | ||
271 | const path = '/api/v1/users/me' | ||
272 | |||
273 | const toSend: UserUpdateMe = omit(options, [ 'expectedStatus', 'token' ]) | ||
274 | |||
275 | return this.putBodyRequest({ | ||
276 | ...options, | ||
277 | |||
278 | path, | ||
279 | fields: toSend, | ||
280 | implicitToken: true, | ||
281 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
282 | }) | ||
283 | } | ||
284 | |||
285 | updateMyAvatar (options: OverrideCommandOptions & { | ||
286 | fixture: string | ||
287 | }) { | ||
288 | const { fixture } = options | ||
289 | const path = '/api/v1/users/me/avatar/pick' | ||
290 | |||
291 | return this.updateImageRequest({ | ||
292 | ...options, | ||
293 | |||
294 | path, | ||
295 | fixture, | ||
296 | fieldname: 'avatarfile', | ||
297 | |||
298 | implicitToken: true, | ||
299 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
300 | }) | ||
301 | } | ||
302 | |||
303 | // --------------------------------------------------------------------------- | ||
304 | |||
305 | get (options: OverrideCommandOptions & { | ||
306 | userId: number | ||
307 | withStats?: boolean // default false | ||
308 | }) { | ||
309 | const { userId, withStats } = options | ||
310 | const path = '/api/v1/users/' + userId | ||
311 | |||
312 | return this.getRequestBody<User>({ | ||
313 | ...options, | ||
314 | |||
315 | path, | ||
316 | query: { withStats }, | ||
317 | implicitToken: true, | ||
318 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
319 | }) | ||
320 | } | ||
321 | |||
322 | list (options: OverrideCommandOptions & { | ||
323 | start?: number | ||
324 | count?: number | ||
325 | sort?: string | ||
326 | search?: string | ||
327 | blocked?: boolean | ||
328 | } = {}) { | ||
329 | const path = '/api/v1/users' | ||
330 | |||
331 | return this.getRequestBody<ResultList<User>>({ | ||
332 | ...options, | ||
333 | |||
334 | path, | ||
335 | query: pick(options, [ 'start', 'count', 'sort', 'search', 'blocked' ]), | ||
336 | implicitToken: true, | ||
337 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
338 | }) | ||
339 | } | ||
340 | |||
341 | remove (options: OverrideCommandOptions & { | ||
342 | userId: number | ||
343 | }) { | ||
344 | const { userId } = options | ||
345 | const path = '/api/v1/users/' + userId | ||
346 | |||
347 | return this.deleteRequest({ | ||
348 | ...options, | ||
349 | |||
350 | path, | ||
351 | implicitToken: true, | ||
352 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
353 | }) | ||
354 | } | ||
355 | |||
356 | update (options: OverrideCommandOptions & { | ||
357 | userId: number | ||
358 | email?: string | ||
359 | emailVerified?: boolean | ||
360 | videoQuota?: number | ||
361 | videoQuotaDaily?: number | ||
362 | password?: string | ||
363 | adminFlags?: UserAdminFlag | ||
364 | pluginAuth?: string | ||
365 | role?: UserRole | ||
366 | }) { | ||
367 | const path = '/api/v1/users/' + options.userId | ||
368 | |||
369 | const toSend: UserUpdate = {} | ||
370 | if (options.password !== undefined && options.password !== null) toSend.password = options.password | ||
371 | if (options.email !== undefined && options.email !== null) toSend.email = options.email | ||
372 | if (options.emailVerified !== undefined && options.emailVerified !== null) toSend.emailVerified = options.emailVerified | ||
373 | if (options.videoQuota !== undefined && options.videoQuota !== null) toSend.videoQuota = options.videoQuota | ||
374 | if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend.videoQuotaDaily = options.videoQuotaDaily | ||
375 | if (options.role !== undefined && options.role !== null) toSend.role = options.role | ||
376 | if (options.adminFlags !== undefined && options.adminFlags !== null) toSend.adminFlags = options.adminFlags | ||
377 | if (options.pluginAuth !== undefined) toSend.pluginAuth = options.pluginAuth | ||
378 | |||
379 | return this.putBodyRequest({ | ||
380 | ...options, | ||
381 | |||
382 | path, | ||
383 | fields: toSend, | ||
384 | implicitToken: true, | ||
385 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
386 | }) | ||
387 | } | ||
388 | } | ||
diff --git a/shared/server-commands/videos/blacklist-command.ts b/shared/server-commands/videos/blacklist-command.ts deleted file mode 100644 index 47e23ebc8..000000000 --- a/shared/server-commands/videos/blacklist-command.ts +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
1 | |||
2 | import { HttpStatusCode, ResultList, VideoBlacklist, VideoBlacklistType } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class BlacklistCommand extends AbstractCommand { | ||
6 | |||
7 | add (options: OverrideCommandOptions & { | ||
8 | videoId: number | string | ||
9 | reason?: string | ||
10 | unfederate?: boolean | ||
11 | }) { | ||
12 | const { videoId, reason, unfederate } = options | ||
13 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
14 | |||
15 | return this.postBodyRequest({ | ||
16 | ...options, | ||
17 | |||
18 | path, | ||
19 | fields: { reason, unfederate }, | ||
20 | implicitToken: true, | ||
21 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | update (options: OverrideCommandOptions & { | ||
26 | videoId: number | string | ||
27 | reason?: string | ||
28 | }) { | ||
29 | const { videoId, reason } = options | ||
30 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
31 | |||
32 | return this.putBodyRequest({ | ||
33 | ...options, | ||
34 | |||
35 | path, | ||
36 | fields: { reason }, | ||
37 | implicitToken: true, | ||
38 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
39 | }) | ||
40 | } | ||
41 | |||
42 | remove (options: OverrideCommandOptions & { | ||
43 | videoId: number | string | ||
44 | }) { | ||
45 | const { videoId } = options | ||
46 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
47 | |||
48 | return this.deleteRequest({ | ||
49 | ...options, | ||
50 | |||
51 | path, | ||
52 | implicitToken: true, | ||
53 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
54 | }) | ||
55 | } | ||
56 | |||
57 | list (options: OverrideCommandOptions & { | ||
58 | sort?: string | ||
59 | type?: VideoBlacklistType | ||
60 | } = {}) { | ||
61 | const { sort, type } = options | ||
62 | const path = '/api/v1/videos/blacklist/' | ||
63 | |||
64 | const query = { sort, type } | ||
65 | |||
66 | return this.getRequestBody<ResultList<VideoBlacklist>>({ | ||
67 | ...options, | ||
68 | |||
69 | path, | ||
70 | query, | ||
71 | implicitToken: true, | ||
72 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
73 | }) | ||
74 | } | ||
75 | } | ||
diff --git a/shared/server-commands/videos/captions-command.ts b/shared/server-commands/videos/captions-command.ts deleted file mode 100644 index a26fcb57d..000000000 --- a/shared/server-commands/videos/captions-command.ts +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | import { buildAbsoluteFixturePath } from '@shared/core-utils' | ||
2 | import { HttpStatusCode, ResultList, VideoCaption } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class CaptionsCommand extends AbstractCommand { | ||
6 | |||
7 | add (options: OverrideCommandOptions & { | ||
8 | videoId: string | number | ||
9 | language: string | ||
10 | fixture: string | ||
11 | mimeType?: string | ||
12 | }) { | ||
13 | const { videoId, language, fixture, mimeType } = options | ||
14 | |||
15 | const path = '/api/v1/videos/' + videoId + '/captions/' + language | ||
16 | |||
17 | const captionfile = buildAbsoluteFixturePath(fixture) | ||
18 | const captionfileAttach = mimeType | ||
19 | ? [ captionfile, { contentType: mimeType } ] | ||
20 | : captionfile | ||
21 | |||
22 | return this.putUploadRequest({ | ||
23 | ...options, | ||
24 | |||
25 | path, | ||
26 | fields: {}, | ||
27 | attaches: { | ||
28 | captionfile: captionfileAttach | ||
29 | }, | ||
30 | implicitToken: true, | ||
31 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
32 | }) | ||
33 | } | ||
34 | |||
35 | list (options: OverrideCommandOptions & { | ||
36 | videoId: string | number | ||
37 | videoPassword?: string | ||
38 | }) { | ||
39 | const { videoId, videoPassword } = options | ||
40 | const path = '/api/v1/videos/' + videoId + '/captions' | ||
41 | |||
42 | return this.getRequestBody<ResultList<VideoCaption>>({ | ||
43 | ...options, | ||
44 | |||
45 | path, | ||
46 | headers: this.buildVideoPasswordHeader(videoPassword), | ||
47 | implicitToken: false, | ||
48 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
49 | }) | ||
50 | } | ||
51 | |||
52 | delete (options: OverrideCommandOptions & { | ||
53 | videoId: string | number | ||
54 | language: string | ||
55 | }) { | ||
56 | const { videoId, language } = options | ||
57 | const path = '/api/v1/videos/' + videoId + '/captions/' + language | ||
58 | |||
59 | return this.deleteRequest({ | ||
60 | ...options, | ||
61 | |||
62 | path, | ||
63 | implicitToken: true, | ||
64 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
65 | }) | ||
66 | } | ||
67 | } | ||
diff --git a/shared/server-commands/videos/change-ownership-command.ts b/shared/server-commands/videos/change-ownership-command.ts deleted file mode 100644 index ad4c726ef..000000000 --- a/shared/server-commands/videos/change-ownership-command.ts +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | |||
2 | import { HttpStatusCode, ResultList, VideoChangeOwnership } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class ChangeOwnershipCommand extends AbstractCommand { | ||
6 | |||
7 | create (options: OverrideCommandOptions & { | ||
8 | videoId: number | string | ||
9 | username: string | ||
10 | }) { | ||
11 | const { videoId, username } = options | ||
12 | const path = '/api/v1/videos/' + videoId + '/give-ownership' | ||
13 | |||
14 | return this.postBodyRequest({ | ||
15 | ...options, | ||
16 | |||
17 | path, | ||
18 | fields: { username }, | ||
19 | implicitToken: true, | ||
20 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
21 | }) | ||
22 | } | ||
23 | |||
24 | list (options: OverrideCommandOptions = {}) { | ||
25 | const path = '/api/v1/videos/ownership' | ||
26 | |||
27 | return this.getRequestBody<ResultList<VideoChangeOwnership>>({ | ||
28 | ...options, | ||
29 | |||
30 | path, | ||
31 | query: { sort: '-createdAt' }, | ||
32 | implicitToken: true, | ||
33 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
34 | }) | ||
35 | } | ||
36 | |||
37 | accept (options: OverrideCommandOptions & { | ||
38 | ownershipId: number | ||
39 | channelId: number | ||
40 | }) { | ||
41 | const { ownershipId, channelId } = options | ||
42 | const path = '/api/v1/videos/ownership/' + ownershipId + '/accept' | ||
43 | |||
44 | return this.postBodyRequest({ | ||
45 | ...options, | ||
46 | |||
47 | path, | ||
48 | fields: { channelId }, | ||
49 | implicitToken: true, | ||
50 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
51 | }) | ||
52 | } | ||
53 | |||
54 | refuse (options: OverrideCommandOptions & { | ||
55 | ownershipId: number | ||
56 | }) { | ||
57 | const { ownershipId } = options | ||
58 | const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse' | ||
59 | |||
60 | return this.postBodyRequest({ | ||
61 | ...options, | ||
62 | |||
63 | path, | ||
64 | implicitToken: true, | ||
65 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
66 | }) | ||
67 | } | ||
68 | } | ||
diff --git a/shared/server-commands/videos/channel-syncs-command.ts b/shared/server-commands/videos/channel-syncs-command.ts deleted file mode 100644 index de4a160ec..000000000 --- a/shared/server-commands/videos/channel-syncs-command.ts +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | import { HttpStatusCode, ResultList, VideoChannelSync, VideoChannelSyncCreate } from '@shared/models' | ||
2 | import { pick } from '@shared/core-utils' | ||
3 | import { unwrapBody } from '../requests' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class ChannelSyncsCommand extends AbstractCommand { | ||
7 | private static readonly API_PATH = '/api/v1/video-channel-syncs' | ||
8 | |||
9 | listByAccount (options: OverrideCommandOptions & { | ||
10 | accountName: string | ||
11 | start?: number | ||
12 | count?: number | ||
13 | sort?: string | ||
14 | }) { | ||
15 | const { accountName, sort = 'createdAt' } = options | ||
16 | |||
17 | const path = `/api/v1/accounts/${accountName}/video-channel-syncs` | ||
18 | |||
19 | return this.getRequestBody<ResultList<VideoChannelSync>>({ | ||
20 | ...options, | ||
21 | |||
22 | path, | ||
23 | query: { sort, ...pick(options, [ 'start', 'count' ]) }, | ||
24 | implicitToken: true, | ||
25 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
26 | }) | ||
27 | } | ||
28 | |||
29 | async create (options: OverrideCommandOptions & { | ||
30 | attributes: VideoChannelSyncCreate | ||
31 | }) { | ||
32 | return unwrapBody<{ videoChannelSync: VideoChannelSync }>(this.postBodyRequest({ | ||
33 | ...options, | ||
34 | |||
35 | path: ChannelSyncsCommand.API_PATH, | ||
36 | fields: options.attributes, | ||
37 | implicitToken: true, | ||
38 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
39 | })) | ||
40 | } | ||
41 | |||
42 | delete (options: OverrideCommandOptions & { | ||
43 | channelSyncId: number | ||
44 | }) { | ||
45 | const path = `${ChannelSyncsCommand.API_PATH}/${options.channelSyncId}` | ||
46 | |||
47 | return this.deleteRequest({ | ||
48 | ...options, | ||
49 | |||
50 | path, | ||
51 | implicitToken: true, | ||
52 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
53 | }) | ||
54 | } | ||
55 | } | ||
diff --git a/shared/server-commands/videos/channels-command.ts b/shared/server-commands/videos/channels-command.ts deleted file mode 100644 index 385d0fe73..000000000 --- a/shared/server-commands/videos/channels-command.ts +++ /dev/null | |||
@@ -1,202 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { | ||
3 | ActorFollow, | ||
4 | HttpStatusCode, | ||
5 | ResultList, | ||
6 | VideoChannel, | ||
7 | VideoChannelCreate, | ||
8 | VideoChannelCreateResult, | ||
9 | VideoChannelUpdate, | ||
10 | VideosImportInChannelCreate | ||
11 | } from '@shared/models' | ||
12 | import { unwrapBody } from '../requests' | ||
13 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
14 | |||
15 | export class ChannelsCommand extends AbstractCommand { | ||
16 | |||
17 | list (options: OverrideCommandOptions & { | ||
18 | start?: number | ||
19 | count?: number | ||
20 | sort?: string | ||
21 | withStats?: boolean | ||
22 | } = {}) { | ||
23 | const path = '/api/v1/video-channels' | ||
24 | |||
25 | return this.getRequestBody<ResultList<VideoChannel>>({ | ||
26 | ...options, | ||
27 | |||
28 | path, | ||
29 | query: pick(options, [ 'start', 'count', 'sort', 'withStats' ]), | ||
30 | implicitToken: false, | ||
31 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
32 | }) | ||
33 | } | ||
34 | |||
35 | listByAccount (options: OverrideCommandOptions & { | ||
36 | accountName: string | ||
37 | start?: number | ||
38 | count?: number | ||
39 | sort?: string | ||
40 | withStats?: boolean | ||
41 | search?: string | ||
42 | }) { | ||
43 | const { accountName, sort = 'createdAt' } = options | ||
44 | const path = '/api/v1/accounts/' + accountName + '/video-channels' | ||
45 | |||
46 | return this.getRequestBody<ResultList<VideoChannel>>({ | ||
47 | ...options, | ||
48 | |||
49 | path, | ||
50 | query: { sort, ...pick(options, [ 'start', 'count', 'withStats', 'search' ]) }, | ||
51 | implicitToken: false, | ||
52 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
53 | }) | ||
54 | } | ||
55 | |||
56 | async create (options: OverrideCommandOptions & { | ||
57 | attributes: Partial<VideoChannelCreate> | ||
58 | }) { | ||
59 | const path = '/api/v1/video-channels/' | ||
60 | |||
61 | // Default attributes | ||
62 | const defaultAttributes = { | ||
63 | displayName: 'my super video channel', | ||
64 | description: 'my super channel description', | ||
65 | support: 'my super channel support' | ||
66 | } | ||
67 | const attributes = { ...defaultAttributes, ...options.attributes } | ||
68 | |||
69 | const body = await unwrapBody<{ videoChannel: VideoChannelCreateResult }>(this.postBodyRequest({ | ||
70 | ...options, | ||
71 | |||
72 | path, | ||
73 | fields: attributes, | ||
74 | implicitToken: true, | ||
75 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
76 | })) | ||
77 | |||
78 | return body.videoChannel | ||
79 | } | ||
80 | |||
81 | update (options: OverrideCommandOptions & { | ||
82 | channelName: string | ||
83 | attributes: VideoChannelUpdate | ||
84 | }) { | ||
85 | const { channelName, attributes } = options | ||
86 | const path = '/api/v1/video-channels/' + channelName | ||
87 | |||
88 | return this.putBodyRequest({ | ||
89 | ...options, | ||
90 | |||
91 | path, | ||
92 | fields: attributes, | ||
93 | implicitToken: true, | ||
94 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
95 | }) | ||
96 | } | ||
97 | |||
98 | delete (options: OverrideCommandOptions & { | ||
99 | channelName: string | ||
100 | }) { | ||
101 | const path = '/api/v1/video-channels/' + options.channelName | ||
102 | |||
103 | return this.deleteRequest({ | ||
104 | ...options, | ||
105 | |||
106 | path, | ||
107 | implicitToken: true, | ||
108 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
109 | }) | ||
110 | } | ||
111 | |||
112 | get (options: OverrideCommandOptions & { | ||
113 | channelName: string | ||
114 | }) { | ||
115 | const path = '/api/v1/video-channels/' + options.channelName | ||
116 | |||
117 | return this.getRequestBody<VideoChannel>({ | ||
118 | ...options, | ||
119 | |||
120 | path, | ||
121 | implicitToken: false, | ||
122 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
123 | }) | ||
124 | } | ||
125 | |||
126 | updateImage (options: OverrideCommandOptions & { | ||
127 | fixture: string | ||
128 | channelName: string | number | ||
129 | type: 'avatar' | 'banner' | ||
130 | }) { | ||
131 | const { channelName, fixture, type } = options | ||
132 | |||
133 | const path = `/api/v1/video-channels/${channelName}/${type}/pick` | ||
134 | |||
135 | return this.updateImageRequest({ | ||
136 | ...options, | ||
137 | |||
138 | path, | ||
139 | fixture, | ||
140 | fieldname: type + 'file', | ||
141 | |||
142 | implicitToken: true, | ||
143 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
144 | }) | ||
145 | } | ||
146 | |||
147 | deleteImage (options: OverrideCommandOptions & { | ||
148 | channelName: string | number | ||
149 | type: 'avatar' | 'banner' | ||
150 | }) { | ||
151 | const { channelName, type } = options | ||
152 | |||
153 | const path = `/api/v1/video-channels/${channelName}/${type}` | ||
154 | |||
155 | return this.deleteRequest({ | ||
156 | ...options, | ||
157 | |||
158 | path, | ||
159 | implicitToken: true, | ||
160 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
161 | }) | ||
162 | } | ||
163 | |||
164 | listFollowers (options: OverrideCommandOptions & { | ||
165 | channelName: string | ||
166 | start?: number | ||
167 | count?: number | ||
168 | sort?: string | ||
169 | search?: string | ||
170 | }) { | ||
171 | const { channelName, start, count, sort, search } = options | ||
172 | const path = '/api/v1/video-channels/' + channelName + '/followers' | ||
173 | |||
174 | const query = { start, count, sort, search } | ||
175 | |||
176 | return this.getRequestBody<ResultList<ActorFollow>>({ | ||
177 | ...options, | ||
178 | |||
179 | path, | ||
180 | query, | ||
181 | implicitToken: true, | ||
182 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
183 | }) | ||
184 | } | ||
185 | |||
186 | importVideos (options: OverrideCommandOptions & VideosImportInChannelCreate & { | ||
187 | channelName: string | ||
188 | }) { | ||
189 | const { channelName, externalChannelUrl, videoChannelSyncId } = options | ||
190 | |||
191 | const path = `/api/v1/video-channels/${channelName}/import-videos` | ||
192 | |||
193 | return this.postBodyRequest({ | ||
194 | ...options, | ||
195 | |||
196 | path, | ||
197 | fields: { externalChannelUrl, videoChannelSyncId }, | ||
198 | implicitToken: true, | ||
199 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
200 | }) | ||
201 | } | ||
202 | } | ||
diff --git a/shared/server-commands/videos/channels.ts b/shared/server-commands/videos/channels.ts deleted file mode 100644 index 3c0d4b723..000000000 --- a/shared/server-commands/videos/channels.ts +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | import { PeerTubeServer } from '../server/server' | ||
2 | |||
3 | function setDefaultVideoChannel (servers: PeerTubeServer[]) { | ||
4 | const tasks: Promise<any>[] = [] | ||
5 | |||
6 | for (const server of servers) { | ||
7 | const p = server.users.getMyInfo() | ||
8 | .then(user => { server.store.channel = user.videoChannels[0] }) | ||
9 | |||
10 | tasks.push(p) | ||
11 | } | ||
12 | |||
13 | return Promise.all(tasks) | ||
14 | } | ||
15 | |||
16 | async function setDefaultChannelAvatar (serversArg: PeerTubeServer | PeerTubeServer[], channelName: string = 'root_channel') { | ||
17 | const servers = Array.isArray(serversArg) | ||
18 | ? serversArg | ||
19 | : [ serversArg ] | ||
20 | |||
21 | for (const server of servers) { | ||
22 | await server.channels.updateImage({ channelName, fixture: 'avatar.png', type: 'avatar' }) | ||
23 | } | ||
24 | } | ||
25 | |||
26 | export { | ||
27 | setDefaultVideoChannel, | ||
28 | setDefaultChannelAvatar | ||
29 | } | ||
diff --git a/shared/server-commands/videos/comments-command.ts b/shared/server-commands/videos/comments-command.ts deleted file mode 100644 index 0dab1b66a..000000000 --- a/shared/server-commands/videos/comments-command.ts +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { HttpStatusCode, ResultList, VideoComment, VideoCommentThreads, VideoCommentThreadTree } from '@shared/models' | ||
3 | import { unwrapBody } from '../requests' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class CommentsCommand extends AbstractCommand { | ||
7 | |||
8 | private lastVideoId: number | string | ||
9 | private lastThreadId: number | ||
10 | private lastReplyId: number | ||
11 | |||
12 | listForAdmin (options: OverrideCommandOptions & { | ||
13 | start?: number | ||
14 | count?: number | ||
15 | sort?: string | ||
16 | isLocal?: boolean | ||
17 | onLocalVideo?: boolean | ||
18 | search?: string | ||
19 | searchAccount?: string | ||
20 | searchVideo?: string | ||
21 | } = {}) { | ||
22 | const { sort = '-createdAt' } = options | ||
23 | const path = '/api/v1/videos/comments' | ||
24 | |||
25 | const query = { sort, ...pick(options, [ 'start', 'count', 'isLocal', 'onLocalVideo', 'search', 'searchAccount', 'searchVideo' ]) } | ||
26 | |||
27 | return this.getRequestBody<ResultList<VideoComment>>({ | ||
28 | ...options, | ||
29 | |||
30 | path, | ||
31 | query, | ||
32 | implicitToken: true, | ||
33 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
34 | }) | ||
35 | } | ||
36 | |||
37 | listThreads (options: OverrideCommandOptions & { | ||
38 | videoId: number | string | ||
39 | videoPassword?: string | ||
40 | start?: number | ||
41 | count?: number | ||
42 | sort?: string | ||
43 | }) { | ||
44 | const { start, count, sort, videoId, videoPassword } = options | ||
45 | const path = '/api/v1/videos/' + videoId + '/comment-threads' | ||
46 | |||
47 | return this.getRequestBody<VideoCommentThreads>({ | ||
48 | ...options, | ||
49 | |||
50 | path, | ||
51 | query: { start, count, sort }, | ||
52 | headers: this.buildVideoPasswordHeader(videoPassword), | ||
53 | implicitToken: false, | ||
54 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | getThread (options: OverrideCommandOptions & { | ||
59 | videoId: number | string | ||
60 | threadId: number | ||
61 | }) { | ||
62 | const { videoId, threadId } = options | ||
63 | const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId | ||
64 | |||
65 | return this.getRequestBody<VideoCommentThreadTree>({ | ||
66 | ...options, | ||
67 | |||
68 | path, | ||
69 | implicitToken: false, | ||
70 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
71 | }) | ||
72 | } | ||
73 | |||
74 | async createThread (options: OverrideCommandOptions & { | ||
75 | videoId: number | string | ||
76 | text: string | ||
77 | videoPassword?: string | ||
78 | }) { | ||
79 | const { videoId, text, videoPassword } = options | ||
80 | const path = '/api/v1/videos/' + videoId + '/comment-threads' | ||
81 | |||
82 | const body = await unwrapBody<{ comment: VideoComment }>(this.postBodyRequest({ | ||
83 | ...options, | ||
84 | |||
85 | path, | ||
86 | fields: { text }, | ||
87 | headers: this.buildVideoPasswordHeader(videoPassword), | ||
88 | implicitToken: true, | ||
89 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
90 | })) | ||
91 | |||
92 | this.lastThreadId = body.comment?.id | ||
93 | this.lastVideoId = videoId | ||
94 | |||
95 | return body.comment | ||
96 | } | ||
97 | |||
98 | async addReply (options: OverrideCommandOptions & { | ||
99 | videoId: number | string | ||
100 | toCommentId: number | ||
101 | text: string | ||
102 | videoPassword?: string | ||
103 | }) { | ||
104 | const { videoId, toCommentId, text, videoPassword } = options | ||
105 | const path = '/api/v1/videos/' + videoId + '/comments/' + toCommentId | ||
106 | |||
107 | const body = await unwrapBody<{ comment: VideoComment }>(this.postBodyRequest({ | ||
108 | ...options, | ||
109 | |||
110 | path, | ||
111 | fields: { text }, | ||
112 | headers: this.buildVideoPasswordHeader(videoPassword), | ||
113 | implicitToken: true, | ||
114 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
115 | })) | ||
116 | |||
117 | this.lastReplyId = body.comment?.id | ||
118 | |||
119 | return body.comment | ||
120 | } | ||
121 | |||
122 | async addReplyToLastReply (options: OverrideCommandOptions & { | ||
123 | text: string | ||
124 | }) { | ||
125 | return this.addReply({ ...options, videoId: this.lastVideoId, toCommentId: this.lastReplyId }) | ||
126 | } | ||
127 | |||
128 | async addReplyToLastThread (options: OverrideCommandOptions & { | ||
129 | text: string | ||
130 | }) { | ||
131 | return this.addReply({ ...options, videoId: this.lastVideoId, toCommentId: this.lastThreadId }) | ||
132 | } | ||
133 | |||
134 | async findCommentId (options: OverrideCommandOptions & { | ||
135 | videoId: number | string | ||
136 | text: string | ||
137 | }) { | ||
138 | const { videoId, text } = options | ||
139 | const { data } = await this.listThreads({ videoId, count: 25, sort: '-createdAt' }) | ||
140 | |||
141 | return data.find(c => c.text === text).id | ||
142 | } | ||
143 | |||
144 | delete (options: OverrideCommandOptions & { | ||
145 | videoId: number | string | ||
146 | commentId: number | ||
147 | }) { | ||
148 | const { videoId, commentId } = options | ||
149 | const path = '/api/v1/videos/' + videoId + '/comments/' + commentId | ||
150 | |||
151 | return this.deleteRequest({ | ||
152 | ...options, | ||
153 | |||
154 | path, | ||
155 | implicitToken: true, | ||
156 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
157 | }) | ||
158 | } | ||
159 | } | ||
diff --git a/shared/server-commands/videos/history-command.ts b/shared/server-commands/videos/history-command.ts deleted file mode 100644 index d27afcff2..000000000 --- a/shared/server-commands/videos/history-command.ts +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | import { HttpStatusCode, ResultList, Video } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class HistoryCommand extends AbstractCommand { | ||
5 | |||
6 | list (options: OverrideCommandOptions & { | ||
7 | search?: string | ||
8 | } = {}) { | ||
9 | const { search } = options | ||
10 | const path = '/api/v1/users/me/history/videos' | ||
11 | |||
12 | return this.getRequestBody<ResultList<Video>>({ | ||
13 | ...options, | ||
14 | |||
15 | path, | ||
16 | query: { | ||
17 | search | ||
18 | }, | ||
19 | implicitToken: true, | ||
20 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
21 | }) | ||
22 | } | ||
23 | |||
24 | removeElement (options: OverrideCommandOptions & { | ||
25 | videoId: number | ||
26 | }) { | ||
27 | const { videoId } = options | ||
28 | const path = '/api/v1/users/me/history/videos/' + videoId | ||
29 | |||
30 | return this.deleteRequest({ | ||
31 | ...options, | ||
32 | |||
33 | path, | ||
34 | implicitToken: true, | ||
35 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
36 | }) | ||
37 | } | ||
38 | |||
39 | removeAll (options: OverrideCommandOptions & { | ||
40 | beforeDate?: string | ||
41 | } = {}) { | ||
42 | const { beforeDate } = options | ||
43 | const path = '/api/v1/users/me/history/videos/remove' | ||
44 | |||
45 | return this.postBodyRequest({ | ||
46 | ...options, | ||
47 | |||
48 | path, | ||
49 | fields: { beforeDate }, | ||
50 | implicitToken: true, | ||
51 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
52 | }) | ||
53 | } | ||
54 | } | ||
diff --git a/shared/server-commands/videos/imports-command.ts b/shared/server-commands/videos/imports-command.ts deleted file mode 100644 index e307a79be..000000000 --- a/shared/server-commands/videos/imports-command.ts +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | |||
2 | import { HttpStatusCode, ResultList } from '@shared/models' | ||
3 | import { VideoImport, VideoImportCreate } from '../../models/videos' | ||
4 | import { unwrapBody } from '../requests' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export class ImportsCommand extends AbstractCommand { | ||
8 | |||
9 | importVideo (options: OverrideCommandOptions & { | ||
10 | attributes: (VideoImportCreate | { torrentfile?: string, previewfile?: string, thumbnailfile?: string }) | ||
11 | }) { | ||
12 | const { attributes } = options | ||
13 | const path = '/api/v1/videos/imports' | ||
14 | |||
15 | let attaches: any = {} | ||
16 | if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile } | ||
17 | if (attributes.thumbnailfile) attaches = { thumbnailfile: attributes.thumbnailfile } | ||
18 | if (attributes.previewfile) attaches = { previewfile: attributes.previewfile } | ||
19 | |||
20 | return unwrapBody<VideoImport>(this.postUploadRequest({ | ||
21 | ...options, | ||
22 | |||
23 | path, | ||
24 | attaches, | ||
25 | fields: options.attributes, | ||
26 | implicitToken: true, | ||
27 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
28 | })) | ||
29 | } | ||
30 | |||
31 | delete (options: OverrideCommandOptions & { | ||
32 | importId: number | ||
33 | }) { | ||
34 | const path = '/api/v1/videos/imports/' + options.importId | ||
35 | |||
36 | return this.deleteRequest({ | ||
37 | ...options, | ||
38 | |||
39 | path, | ||
40 | implicitToken: true, | ||
41 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
42 | }) | ||
43 | } | ||
44 | |||
45 | cancel (options: OverrideCommandOptions & { | ||
46 | importId: number | ||
47 | }) { | ||
48 | const path = '/api/v1/videos/imports/' + options.importId + '/cancel' | ||
49 | |||
50 | return this.postBodyRequest({ | ||
51 | ...options, | ||
52 | |||
53 | path, | ||
54 | implicitToken: true, | ||
55 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
56 | }) | ||
57 | } | ||
58 | |||
59 | getMyVideoImports (options: OverrideCommandOptions & { | ||
60 | sort?: string | ||
61 | targetUrl?: string | ||
62 | videoChannelSyncId?: number | ||
63 | search?: string | ||
64 | } = {}) { | ||
65 | const { sort, targetUrl, videoChannelSyncId, search } = options | ||
66 | const path = '/api/v1/users/me/videos/imports' | ||
67 | |||
68 | return this.getRequestBody<ResultList<VideoImport>>({ | ||
69 | ...options, | ||
70 | |||
71 | path, | ||
72 | query: { sort, targetUrl, videoChannelSyncId, search }, | ||
73 | implicitToken: true, | ||
74 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
75 | }) | ||
76 | } | ||
77 | } | ||
diff --git a/shared/server-commands/videos/index.ts b/shared/server-commands/videos/index.ts deleted file mode 100644 index 106d80af0..000000000 --- a/shared/server-commands/videos/index.ts +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | export * from './blacklist-command' | ||
2 | export * from './captions-command' | ||
3 | export * from './change-ownership-command' | ||
4 | export * from './channels' | ||
5 | export * from './channels-command' | ||
6 | export * from './channel-syncs-command' | ||
7 | export * from './comments-command' | ||
8 | export * from './history-command' | ||
9 | export * from './imports-command' | ||
10 | export * from './live-command' | ||
11 | export * from './live' | ||
12 | export * from './playlists-command' | ||
13 | export * from './services-command' | ||
14 | export * from './storyboard-command' | ||
15 | export * from './streaming-playlists-command' | ||
16 | export * from './comments-command' | ||
17 | export * from './video-studio-command' | ||
18 | export * from './video-token-command' | ||
19 | export * from './views-command' | ||
20 | export * from './videos-command' | ||
21 | export * from './video-passwords-command' | ||
diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts deleted file mode 100644 index 6006d9fe9..000000000 --- a/shared/server-commands/videos/live-command.ts +++ /dev/null | |||
@@ -1,337 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { readdir } from 'fs-extra' | ||
4 | import { join } from 'path' | ||
5 | import { omit, wait } from '@shared/core-utils' | ||
6 | import { | ||
7 | HttpStatusCode, | ||
8 | LiveVideo, | ||
9 | LiveVideoCreate, | ||
10 | LiveVideoSession, | ||
11 | LiveVideoUpdate, | ||
12 | ResultList, | ||
13 | VideoCreateResult, | ||
14 | VideoDetails, | ||
15 | VideoPrivacy, | ||
16 | VideoState | ||
17 | } from '@shared/models' | ||
18 | import { unwrapBody } from '../requests' | ||
19 | import { ObjectStorageCommand, PeerTubeServer } from '../server' | ||
20 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
21 | import { sendRTMPStream, testFfmpegStreamError } from './live' | ||
22 | |||
23 | export class LiveCommand extends AbstractCommand { | ||
24 | |||
25 | get (options: OverrideCommandOptions & { | ||
26 | videoId: number | string | ||
27 | }) { | ||
28 | const path = '/api/v1/videos/live' | ||
29 | |||
30 | return this.getRequestBody<LiveVideo>({ | ||
31 | ...options, | ||
32 | |||
33 | path: path + '/' + options.videoId, | ||
34 | implicitToken: true, | ||
35 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
36 | }) | ||
37 | } | ||
38 | |||
39 | // --------------------------------------------------------------------------- | ||
40 | |||
41 | listSessions (options: OverrideCommandOptions & { | ||
42 | videoId: number | string | ||
43 | }) { | ||
44 | const path = `/api/v1/videos/live/${options.videoId}/sessions` | ||
45 | |||
46 | return this.getRequestBody<ResultList<LiveVideoSession>>({ | ||
47 | ...options, | ||
48 | |||
49 | path, | ||
50 | implicitToken: true, | ||
51 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
52 | }) | ||
53 | } | ||
54 | |||
55 | async findLatestSession (options: OverrideCommandOptions & { | ||
56 | videoId: number | string | ||
57 | }) { | ||
58 | const { data: sessions } = await this.listSessions(options) | ||
59 | |||
60 | return sessions[sessions.length - 1] | ||
61 | } | ||
62 | |||
63 | getReplaySession (options: OverrideCommandOptions & { | ||
64 | videoId: number | string | ||
65 | }) { | ||
66 | const path = `/api/v1/videos/${options.videoId}/live-session` | ||
67 | |||
68 | return this.getRequestBody<LiveVideoSession>({ | ||
69 | ...options, | ||
70 | |||
71 | path, | ||
72 | implicitToken: true, | ||
73 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
74 | }) | ||
75 | } | ||
76 | |||
77 | // --------------------------------------------------------------------------- | ||
78 | |||
79 | update (options: OverrideCommandOptions & { | ||
80 | videoId: number | string | ||
81 | fields: LiveVideoUpdate | ||
82 | }) { | ||
83 | const { videoId, fields } = options | ||
84 | const path = '/api/v1/videos/live' | ||
85 | |||
86 | return this.putBodyRequest({ | ||
87 | ...options, | ||
88 | |||
89 | path: path + '/' + videoId, | ||
90 | fields, | ||
91 | implicitToken: true, | ||
92 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
93 | }) | ||
94 | } | ||
95 | |||
96 | async create (options: OverrideCommandOptions & { | ||
97 | fields: LiveVideoCreate | ||
98 | }) { | ||
99 | const { fields } = options | ||
100 | const path = '/api/v1/videos/live' | ||
101 | |||
102 | const attaches: any = {} | ||
103 | if (fields.thumbnailfile) attaches.thumbnailfile = fields.thumbnailfile | ||
104 | if (fields.previewfile) attaches.previewfile = fields.previewfile | ||
105 | |||
106 | const body = await unwrapBody<{ video: VideoCreateResult }>(this.postUploadRequest({ | ||
107 | ...options, | ||
108 | |||
109 | path, | ||
110 | attaches, | ||
111 | fields: omit(fields, [ 'thumbnailfile', 'previewfile' ]), | ||
112 | implicitToken: true, | ||
113 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
114 | })) | ||
115 | |||
116 | return body.video | ||
117 | } | ||
118 | |||
119 | async quickCreate (options: OverrideCommandOptions & { | ||
120 | saveReplay: boolean | ||
121 | permanentLive: boolean | ||
122 | privacy?: VideoPrivacy | ||
123 | videoPasswords?: string[] | ||
124 | }) { | ||
125 | const { saveReplay, permanentLive, privacy = VideoPrivacy.PUBLIC, videoPasswords } = options | ||
126 | |||
127 | const replaySettings = privacy === VideoPrivacy.PASSWORD_PROTECTED | ||
128 | ? { privacy: VideoPrivacy.PRIVATE } | ||
129 | : { privacy } | ||
130 | |||
131 | const { uuid } = await this.create({ | ||
132 | ...options, | ||
133 | |||
134 | fields: { | ||
135 | name: 'live', | ||
136 | permanentLive, | ||
137 | saveReplay, | ||
138 | replaySettings, | ||
139 | channelId: this.server.store.channel.id, | ||
140 | privacy, | ||
141 | videoPasswords | ||
142 | } | ||
143 | }) | ||
144 | |||
145 | const video = await this.server.videos.getWithToken({ id: uuid }) | ||
146 | const live = await this.get({ videoId: uuid }) | ||
147 | |||
148 | return { video, live } | ||
149 | } | ||
150 | |||
151 | // --------------------------------------------------------------------------- | ||
152 | |||
153 | async sendRTMPStreamInVideo (options: OverrideCommandOptions & { | ||
154 | videoId: number | string | ||
155 | fixtureName?: string | ||
156 | copyCodecs?: boolean | ||
157 | }) { | ||
158 | const { videoId, fixtureName, copyCodecs } = options | ||
159 | const videoLive = await this.get({ videoId }) | ||
160 | |||
161 | return sendRTMPStream({ rtmpBaseUrl: videoLive.rtmpUrl, streamKey: videoLive.streamKey, fixtureName, copyCodecs }) | ||
162 | } | ||
163 | |||
164 | async runAndTestStreamError (options: OverrideCommandOptions & { | ||
165 | videoId: number | string | ||
166 | shouldHaveError: boolean | ||
167 | }) { | ||
168 | const command = await this.sendRTMPStreamInVideo(options) | ||
169 | |||
170 | return testFfmpegStreamError(command, options.shouldHaveError) | ||
171 | } | ||
172 | |||
173 | // --------------------------------------------------------------------------- | ||
174 | |||
175 | waitUntilPublished (options: OverrideCommandOptions & { | ||
176 | videoId: number | string | ||
177 | }) { | ||
178 | const { videoId } = options | ||
179 | return this.waitUntilState({ videoId, state: VideoState.PUBLISHED }) | ||
180 | } | ||
181 | |||
182 | waitUntilWaiting (options: OverrideCommandOptions & { | ||
183 | videoId: number | string | ||
184 | }) { | ||
185 | const { videoId } = options | ||
186 | return this.waitUntilState({ videoId, state: VideoState.WAITING_FOR_LIVE }) | ||
187 | } | ||
188 | |||
189 | waitUntilEnded (options: OverrideCommandOptions & { | ||
190 | videoId: number | string | ||
191 | }) { | ||
192 | const { videoId } = options | ||
193 | return this.waitUntilState({ videoId, state: VideoState.LIVE_ENDED }) | ||
194 | } | ||
195 | |||
196 | async waitUntilSegmentGeneration (options: OverrideCommandOptions & { | ||
197 | server: PeerTubeServer | ||
198 | videoUUID: string | ||
199 | playlistNumber: number | ||
200 | segment: number | ||
201 | objectStorage?: ObjectStorageCommand | ||
202 | objectStorageBaseUrl?: string | ||
203 | }) { | ||
204 | const { | ||
205 | server, | ||
206 | objectStorage, | ||
207 | playlistNumber, | ||
208 | segment, | ||
209 | videoUUID, | ||
210 | objectStorageBaseUrl | ||
211 | } = options | ||
212 | |||
213 | const segmentName = `${playlistNumber}-00000${segment}.ts` | ||
214 | const baseUrl = objectStorage | ||
215 | ? join(objectStorageBaseUrl || objectStorage.getMockPlaylistBaseUrl(), 'hls') | ||
216 | : server.url + '/static/streaming-playlists/hls' | ||
217 | |||
218 | let error = true | ||
219 | |||
220 | while (error) { | ||
221 | try { | ||
222 | // Check fragment exists | ||
223 | await this.getRawRequest({ | ||
224 | ...options, | ||
225 | |||
226 | url: `${baseUrl}/${videoUUID}/${segmentName}`, | ||
227 | implicitToken: false, | ||
228 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
229 | }) | ||
230 | |||
231 | const video = await server.videos.get({ id: videoUUID }) | ||
232 | const hlsPlaylist = video.streamingPlaylists[0] | ||
233 | |||
234 | // Check SHA generation | ||
235 | const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: !!objectStorage }) | ||
236 | if (!shaBody[segmentName]) { | ||
237 | throw new Error('Segment SHA does not exist') | ||
238 | } | ||
239 | |||
240 | // Check fragment is in m3u8 playlist | ||
241 | const subPlaylist = await server.streamingPlaylists.get({ url: `${baseUrl}/${video.uuid}/${playlistNumber}.m3u8` }) | ||
242 | if (!subPlaylist.includes(segmentName)) throw new Error('Fragment does not exist in playlist') | ||
243 | |||
244 | error = false | ||
245 | } catch { | ||
246 | error = true | ||
247 | await wait(100) | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | |||
252 | async waitUntilReplacedByReplay (options: OverrideCommandOptions & { | ||
253 | videoId: number | string | ||
254 | }) { | ||
255 | let video: VideoDetails | ||
256 | |||
257 | do { | ||
258 | video = await this.server.videos.getWithToken({ token: options.token, id: options.videoId }) | ||
259 | |||
260 | await wait(500) | ||
261 | } while (video.isLive === true || video.state.id !== VideoState.PUBLISHED) | ||
262 | } | ||
263 | |||
264 | // --------------------------------------------------------------------------- | ||
265 | |||
266 | getSegmentFile (options: OverrideCommandOptions & { | ||
267 | videoUUID: string | ||
268 | playlistNumber: number | ||
269 | segment: number | ||
270 | objectStorage?: ObjectStorageCommand | ||
271 | }) { | ||
272 | const { playlistNumber, segment, videoUUID, objectStorage } = options | ||
273 | |||
274 | const segmentName = `${playlistNumber}-00000${segment}.ts` | ||
275 | const baseUrl = objectStorage | ||
276 | ? objectStorage.getMockPlaylistBaseUrl() | ||
277 | : `${this.server.url}/static/streaming-playlists/hls` | ||
278 | |||
279 | const url = `${baseUrl}/${videoUUID}/${segmentName}` | ||
280 | |||
281 | return this.getRawRequest({ | ||
282 | ...options, | ||
283 | |||
284 | url, | ||
285 | implicitToken: false, | ||
286 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
287 | }) | ||
288 | } | ||
289 | |||
290 | getPlaylistFile (options: OverrideCommandOptions & { | ||
291 | videoUUID: string | ||
292 | playlistName: string | ||
293 | objectStorage?: ObjectStorageCommand | ||
294 | }) { | ||
295 | const { playlistName, videoUUID, objectStorage } = options | ||
296 | |||
297 | const baseUrl = objectStorage | ||
298 | ? objectStorage.getMockPlaylistBaseUrl() | ||
299 | : `${this.server.url}/static/streaming-playlists/hls` | ||
300 | |||
301 | const url = `${baseUrl}/${videoUUID}/${playlistName}` | ||
302 | |||
303 | return this.getRawRequest({ | ||
304 | ...options, | ||
305 | |||
306 | url, | ||
307 | implicitToken: false, | ||
308 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
309 | }) | ||
310 | } | ||
311 | |||
312 | // --------------------------------------------------------------------------- | ||
313 | |||
314 | async countPlaylists (options: OverrideCommandOptions & { | ||
315 | videoUUID: string | ||
316 | }) { | ||
317 | const basePath = this.server.servers.buildDirectory('streaming-playlists') | ||
318 | const hlsPath = join(basePath, 'hls', options.videoUUID) | ||
319 | |||
320 | const files = await readdir(hlsPath) | ||
321 | |||
322 | return files.filter(f => f.endsWith('.m3u8')).length | ||
323 | } | ||
324 | |||
325 | private async waitUntilState (options: OverrideCommandOptions & { | ||
326 | videoId: number | string | ||
327 | state: VideoState | ||
328 | }) { | ||
329 | let video: VideoDetails | ||
330 | |||
331 | do { | ||
332 | video = await this.server.videos.getWithToken({ token: options.token, id: options.videoId }) | ||
333 | |||
334 | await wait(500) | ||
335 | } while (video.state.id !== options.state) | ||
336 | } | ||
337 | } | ||
diff --git a/shared/server-commands/videos/live.ts b/shared/server-commands/videos/live.ts deleted file mode 100644 index cebadb1db..000000000 --- a/shared/server-commands/videos/live.ts +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg' | ||
2 | import { truncate } from 'lodash' | ||
3 | import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' | ||
4 | import { VideoDetails, VideoInclude, VideoPrivacy } from '@shared/models' | ||
5 | import { PeerTubeServer } from '../server/server' | ||
6 | |||
7 | function sendRTMPStream (options: { | ||
8 | rtmpBaseUrl: string | ||
9 | streamKey: string | ||
10 | fixtureName?: string // default video_short.mp4 | ||
11 | copyCodecs?: boolean // default false | ||
12 | }) { | ||
13 | const { rtmpBaseUrl, streamKey, fixtureName = 'video_short.mp4', copyCodecs = false } = options | ||
14 | |||
15 | const fixture = buildAbsoluteFixturePath(fixtureName) | ||
16 | |||
17 | const command = ffmpeg(fixture) | ||
18 | command.inputOption('-stream_loop -1') | ||
19 | command.inputOption('-re') | ||
20 | |||
21 | if (copyCodecs) { | ||
22 | command.outputOption('-c copy') | ||
23 | } else { | ||
24 | command.outputOption('-c:v libx264') | ||
25 | command.outputOption('-g 120') | ||
26 | command.outputOption('-x264-params "no-scenecut=1"') | ||
27 | command.outputOption('-r 60') | ||
28 | } | ||
29 | |||
30 | command.outputOption('-f flv') | ||
31 | |||
32 | const rtmpUrl = rtmpBaseUrl + '/' + streamKey | ||
33 | command.output(rtmpUrl) | ||
34 | |||
35 | command.on('error', err => { | ||
36 | if (err?.message?.includes('Exiting normally')) return | ||
37 | |||
38 | if (process.env.DEBUG) console.error(err) | ||
39 | }) | ||
40 | |||
41 | if (process.env.DEBUG) { | ||
42 | command.on('stderr', data => console.log(data)) | ||
43 | command.on('stdout', data => console.log(data)) | ||
44 | } | ||
45 | |||
46 | command.run() | ||
47 | |||
48 | return command | ||
49 | } | ||
50 | |||
51 | function waitFfmpegUntilError (command: FfmpegCommand, successAfterMS = 10000) { | ||
52 | return new Promise<void>((res, rej) => { | ||
53 | command.on('error', err => { | ||
54 | return rej(err) | ||
55 | }) | ||
56 | |||
57 | setTimeout(() => { | ||
58 | res() | ||
59 | }, successAfterMS) | ||
60 | }) | ||
61 | } | ||
62 | |||
63 | async function testFfmpegStreamError (command: FfmpegCommand, shouldHaveError: boolean) { | ||
64 | let error: Error | ||
65 | |||
66 | try { | ||
67 | await waitFfmpegUntilError(command, 45000) | ||
68 | } catch (err) { | ||
69 | error = err | ||
70 | } | ||
71 | |||
72 | await stopFfmpeg(command) | ||
73 | |||
74 | if (shouldHaveError && !error) throw new Error('Ffmpeg did not have an error') | ||
75 | if (!shouldHaveError && error) throw error | ||
76 | } | ||
77 | |||
78 | async function stopFfmpeg (command: FfmpegCommand) { | ||
79 | command.kill('SIGINT') | ||
80 | |||
81 | await wait(500) | ||
82 | } | ||
83 | |||
84 | async function waitUntilLivePublishedOnAllServers (servers: PeerTubeServer[], videoId: string) { | ||
85 | for (const server of servers) { | ||
86 | await server.live.waitUntilPublished({ videoId }) | ||
87 | } | ||
88 | } | ||
89 | |||
90 | async function waitUntilLiveWaitingOnAllServers (servers: PeerTubeServer[], videoId: string) { | ||
91 | for (const server of servers) { | ||
92 | await server.live.waitUntilWaiting({ videoId }) | ||
93 | } | ||
94 | } | ||
95 | |||
96 | async function waitUntilLiveReplacedByReplayOnAllServers (servers: PeerTubeServer[], videoId: string) { | ||
97 | for (const server of servers) { | ||
98 | await server.live.waitUntilReplacedByReplay({ videoId }) | ||
99 | } | ||
100 | } | ||
101 | |||
102 | async function findExternalSavedVideo (server: PeerTubeServer, liveDetails: VideoDetails) { | ||
103 | const include = VideoInclude.BLACKLISTED | ||
104 | const privacyOneOf = [ VideoPrivacy.INTERNAL, VideoPrivacy.PRIVATE, VideoPrivacy.PUBLIC, VideoPrivacy.UNLISTED ] | ||
105 | |||
106 | const { data } = await server.videos.list({ token: server.accessToken, sort: '-publishedAt', include, privacyOneOf }) | ||
107 | |||
108 | const videoNameSuffix = ` - ${new Date(liveDetails.publishedAt).toLocaleString()}` | ||
109 | const truncatedVideoName = truncate(liveDetails.name, { | ||
110 | length: 120 - videoNameSuffix.length | ||
111 | }) | ||
112 | const toFind = truncatedVideoName + videoNameSuffix | ||
113 | |||
114 | return data.find(v => v.name === toFind) | ||
115 | } | ||
116 | |||
117 | export { | ||
118 | sendRTMPStream, | ||
119 | waitFfmpegUntilError, | ||
120 | testFfmpegStreamError, | ||
121 | stopFfmpeg, | ||
122 | |||
123 | waitUntilLivePublishedOnAllServers, | ||
124 | waitUntilLiveReplacedByReplayOnAllServers, | ||
125 | waitUntilLiveWaitingOnAllServers, | ||
126 | |||
127 | findExternalSavedVideo | ||
128 | } | ||
diff --git a/shared/server-commands/videos/playlists-command.ts b/shared/server-commands/videos/playlists-command.ts deleted file mode 100644 index da3bef7b0..000000000 --- a/shared/server-commands/videos/playlists-command.ts +++ /dev/null | |||
@@ -1,281 +0,0 @@ | |||
1 | import { omit, pick } from '@shared/core-utils' | ||
2 | import { | ||
3 | BooleanBothQuery, | ||
4 | HttpStatusCode, | ||
5 | ResultList, | ||
6 | VideoExistInPlaylist, | ||
7 | VideoPlaylist, | ||
8 | VideoPlaylistCreate, | ||
9 | VideoPlaylistCreateResult, | ||
10 | VideoPlaylistElement, | ||
11 | VideoPlaylistElementCreate, | ||
12 | VideoPlaylistElementCreateResult, | ||
13 | VideoPlaylistElementUpdate, | ||
14 | VideoPlaylistReorder, | ||
15 | VideoPlaylistType, | ||
16 | VideoPlaylistUpdate | ||
17 | } from '@shared/models' | ||
18 | import { unwrapBody } from '../requests' | ||
19 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
20 | |||
21 | export class PlaylistsCommand extends AbstractCommand { | ||
22 | |||
23 | list (options: OverrideCommandOptions & { | ||
24 | start?: number | ||
25 | count?: number | ||
26 | sort?: string | ||
27 | playlistType?: VideoPlaylistType | ||
28 | }) { | ||
29 | const path = '/api/v1/video-playlists' | ||
30 | const query = pick(options, [ 'start', 'count', 'sort', 'playlistType' ]) | ||
31 | |||
32 | return this.getRequestBody<ResultList<VideoPlaylist>>({ | ||
33 | ...options, | ||
34 | |||
35 | path, | ||
36 | query, | ||
37 | implicitToken: false, | ||
38 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
39 | }) | ||
40 | } | ||
41 | |||
42 | listByChannel (options: OverrideCommandOptions & { | ||
43 | handle: string | ||
44 | start?: number | ||
45 | count?: number | ||
46 | sort?: string | ||
47 | playlistType?: VideoPlaylistType | ||
48 | }) { | ||
49 | const path = '/api/v1/video-channels/' + options.handle + '/video-playlists' | ||
50 | const query = pick(options, [ 'start', 'count', 'sort', 'playlistType' ]) | ||
51 | |||
52 | return this.getRequestBody<ResultList<VideoPlaylist>>({ | ||
53 | ...options, | ||
54 | |||
55 | path, | ||
56 | query, | ||
57 | implicitToken: false, | ||
58 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
59 | }) | ||
60 | } | ||
61 | |||
62 | listByAccount (options: OverrideCommandOptions & { | ||
63 | handle: string | ||
64 | start?: number | ||
65 | count?: number | ||
66 | sort?: string | ||
67 | search?: string | ||
68 | playlistType?: VideoPlaylistType | ||
69 | }) { | ||
70 | const path = '/api/v1/accounts/' + options.handle + '/video-playlists' | ||
71 | const query = pick(options, [ 'start', 'count', 'sort', 'search', 'playlistType' ]) | ||
72 | |||
73 | return this.getRequestBody<ResultList<VideoPlaylist>>({ | ||
74 | ...options, | ||
75 | |||
76 | path, | ||
77 | query, | ||
78 | implicitToken: false, | ||
79 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
80 | }) | ||
81 | } | ||
82 | |||
83 | get (options: OverrideCommandOptions & { | ||
84 | playlistId: number | string | ||
85 | }) { | ||
86 | const { playlistId } = options | ||
87 | const path = '/api/v1/video-playlists/' + playlistId | ||
88 | |||
89 | return this.getRequestBody<VideoPlaylist>({ | ||
90 | ...options, | ||
91 | |||
92 | path, | ||
93 | implicitToken: false, | ||
94 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
95 | }) | ||
96 | } | ||
97 | |||
98 | listVideos (options: OverrideCommandOptions & { | ||
99 | playlistId: number | string | ||
100 | start?: number | ||
101 | count?: number | ||
102 | query?: { nsfw?: BooleanBothQuery } | ||
103 | }) { | ||
104 | const path = '/api/v1/video-playlists/' + options.playlistId + '/videos' | ||
105 | const query = options.query ?? {} | ||
106 | |||
107 | return this.getRequestBody<ResultList<VideoPlaylistElement>>({ | ||
108 | ...options, | ||
109 | |||
110 | path, | ||
111 | query: { | ||
112 | ...query, | ||
113 | start: options.start, | ||
114 | count: options.count | ||
115 | }, | ||
116 | implicitToken: true, | ||
117 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
118 | }) | ||
119 | } | ||
120 | |||
121 | delete (options: OverrideCommandOptions & { | ||
122 | playlistId: number | string | ||
123 | }) { | ||
124 | const path = '/api/v1/video-playlists/' + options.playlistId | ||
125 | |||
126 | return this.deleteRequest({ | ||
127 | ...options, | ||
128 | |||
129 | path, | ||
130 | implicitToken: true, | ||
131 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
132 | }) | ||
133 | } | ||
134 | |||
135 | async create (options: OverrideCommandOptions & { | ||
136 | attributes: VideoPlaylistCreate | ||
137 | }) { | ||
138 | const path = '/api/v1/video-playlists' | ||
139 | |||
140 | const fields = omit(options.attributes, [ 'thumbnailfile' ]) | ||
141 | |||
142 | const attaches = options.attributes.thumbnailfile | ||
143 | ? { thumbnailfile: options.attributes.thumbnailfile } | ||
144 | : {} | ||
145 | |||
146 | const body = await unwrapBody<{ videoPlaylist: VideoPlaylistCreateResult }>(this.postUploadRequest({ | ||
147 | ...options, | ||
148 | |||
149 | path, | ||
150 | fields, | ||
151 | attaches, | ||
152 | implicitToken: true, | ||
153 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
154 | })) | ||
155 | |||
156 | return body.videoPlaylist | ||
157 | } | ||
158 | |||
159 | update (options: OverrideCommandOptions & { | ||
160 | attributes: VideoPlaylistUpdate | ||
161 | playlistId: number | string | ||
162 | }) { | ||
163 | const path = '/api/v1/video-playlists/' + options.playlistId | ||
164 | |||
165 | const fields = omit(options.attributes, [ 'thumbnailfile' ]) | ||
166 | |||
167 | const attaches = options.attributes.thumbnailfile | ||
168 | ? { thumbnailfile: options.attributes.thumbnailfile } | ||
169 | : {} | ||
170 | |||
171 | return this.putUploadRequest({ | ||
172 | ...options, | ||
173 | |||
174 | path, | ||
175 | fields, | ||
176 | attaches, | ||
177 | implicitToken: true, | ||
178 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
179 | }) | ||
180 | } | ||
181 | |||
182 | async addElement (options: OverrideCommandOptions & { | ||
183 | playlistId: number | string | ||
184 | attributes: VideoPlaylistElementCreate | { videoId: string } | ||
185 | }) { | ||
186 | const attributes = { | ||
187 | ...options.attributes, | ||
188 | |||
189 | videoId: await this.server.videos.getId({ ...options, uuid: options.attributes.videoId }) | ||
190 | } | ||
191 | |||
192 | const path = '/api/v1/video-playlists/' + options.playlistId + '/videos' | ||
193 | |||
194 | const body = await unwrapBody<{ videoPlaylistElement: VideoPlaylistElementCreateResult }>(this.postBodyRequest({ | ||
195 | ...options, | ||
196 | |||
197 | path, | ||
198 | fields: attributes, | ||
199 | implicitToken: true, | ||
200 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
201 | })) | ||
202 | |||
203 | return body.videoPlaylistElement | ||
204 | } | ||
205 | |||
206 | updateElement (options: OverrideCommandOptions & { | ||
207 | playlistId: number | string | ||
208 | elementId: number | string | ||
209 | attributes: VideoPlaylistElementUpdate | ||
210 | }) { | ||
211 | const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/' + options.elementId | ||
212 | |||
213 | return this.putBodyRequest({ | ||
214 | ...options, | ||
215 | |||
216 | path, | ||
217 | fields: options.attributes, | ||
218 | implicitToken: true, | ||
219 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
220 | }) | ||
221 | } | ||
222 | |||
223 | removeElement (options: OverrideCommandOptions & { | ||
224 | playlistId: number | string | ||
225 | elementId: number | ||
226 | }) { | ||
227 | const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/' + options.elementId | ||
228 | |||
229 | return this.deleteRequest({ | ||
230 | ...options, | ||
231 | |||
232 | path, | ||
233 | implicitToken: true, | ||
234 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
235 | }) | ||
236 | } | ||
237 | |||
238 | reorderElements (options: OverrideCommandOptions & { | ||
239 | playlistId: number | string | ||
240 | attributes: VideoPlaylistReorder | ||
241 | }) { | ||
242 | const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/reorder' | ||
243 | |||
244 | return this.postBodyRequest({ | ||
245 | ...options, | ||
246 | |||
247 | path, | ||
248 | fields: options.attributes, | ||
249 | implicitToken: true, | ||
250 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
251 | }) | ||
252 | } | ||
253 | |||
254 | getPrivacies (options: OverrideCommandOptions = {}) { | ||
255 | const path = '/api/v1/video-playlists/privacies' | ||
256 | |||
257 | return this.getRequestBody<{ [ id: number ]: string }>({ | ||
258 | ...options, | ||
259 | |||
260 | path, | ||
261 | implicitToken: false, | ||
262 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
263 | }) | ||
264 | } | ||
265 | |||
266 | videosExist (options: OverrideCommandOptions & { | ||
267 | videoIds: number[] | ||
268 | }) { | ||
269 | const { videoIds } = options | ||
270 | const path = '/api/v1/users/me/video-playlists/videos-exist' | ||
271 | |||
272 | return this.getRequestBody<VideoExistInPlaylist>({ | ||
273 | ...options, | ||
274 | |||
275 | path, | ||
276 | query: { videoIds }, | ||
277 | implicitToken: true, | ||
278 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
279 | }) | ||
280 | } | ||
281 | } | ||
diff --git a/shared/server-commands/videos/services-command.ts b/shared/server-commands/videos/services-command.ts deleted file mode 100644 index 06760df42..000000000 --- a/shared/server-commands/videos/services-command.ts +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | import { HttpStatusCode } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class ServicesCommand extends AbstractCommand { | ||
5 | |||
6 | getOEmbed (options: OverrideCommandOptions & { | ||
7 | oembedUrl: string | ||
8 | format?: string | ||
9 | maxHeight?: number | ||
10 | maxWidth?: number | ||
11 | }) { | ||
12 | const path = '/services/oembed' | ||
13 | const query = { | ||
14 | url: options.oembedUrl, | ||
15 | format: options.format, | ||
16 | maxheight: options.maxHeight, | ||
17 | maxwidth: options.maxWidth | ||
18 | } | ||
19 | |||
20 | return this.getRequest({ | ||
21 | ...options, | ||
22 | |||
23 | path, | ||
24 | query, | ||
25 | implicitToken: false, | ||
26 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
27 | }) | ||
28 | } | ||
29 | } | ||
diff --git a/shared/server-commands/videos/storyboard-command.ts b/shared/server-commands/videos/storyboard-command.ts deleted file mode 100644 index 06d90fc12..000000000 --- a/shared/server-commands/videos/storyboard-command.ts +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | import { HttpStatusCode, Storyboard } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class StoryboardCommand extends AbstractCommand { | ||
5 | |||
6 | list (options: OverrideCommandOptions & { | ||
7 | id: number | string | ||
8 | }) { | ||
9 | const path = '/api/v1/videos/' + options.id + '/storyboards' | ||
10 | |||
11 | return this.getRequestBody<{ storyboards: Storyboard[] }>({ | ||
12 | ...options, | ||
13 | |||
14 | path, | ||
15 | implicitToken: true, | ||
16 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
17 | }) | ||
18 | } | ||
19 | } | ||
diff --git a/shared/server-commands/videos/streaming-playlists-command.ts b/shared/server-commands/videos/streaming-playlists-command.ts deleted file mode 100644 index b988ac4b2..000000000 --- a/shared/server-commands/videos/streaming-playlists-command.ts +++ /dev/null | |||
@@ -1,119 +0,0 @@ | |||
1 | import { wait } from '@shared/core-utils' | ||
2 | import { HttpStatusCode } from '@shared/models' | ||
3 | import { unwrapBody, unwrapBodyOrDecodeToJSON, unwrapTextOrDecode } from '../requests' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class StreamingPlaylistsCommand extends AbstractCommand { | ||
7 | |||
8 | async get (options: OverrideCommandOptions & { | ||
9 | url: string | ||
10 | |||
11 | videoFileToken?: string | ||
12 | reinjectVideoFileToken?: boolean | ||
13 | |||
14 | withRetry?: boolean // default false | ||
15 | currentRetry?: number | ||
16 | }): Promise<string> { | ||
17 | const { videoFileToken, reinjectVideoFileToken, expectedStatus, withRetry = false, currentRetry = 1 } = options | ||
18 | |||
19 | try { | ||
20 | const result = await unwrapTextOrDecode(this.getRawRequest({ | ||
21 | ...options, | ||
22 | |||
23 | url: options.url, | ||
24 | query: { | ||
25 | videoFileToken, | ||
26 | reinjectVideoFileToken | ||
27 | }, | ||
28 | implicitToken: false, | ||
29 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
30 | })) | ||
31 | |||
32 | // master.m3u8 could be empty | ||
33 | if (!result && (!expectedStatus || expectedStatus === HttpStatusCode.OK_200)) { | ||
34 | throw new Error('Empty result') | ||
35 | } | ||
36 | |||
37 | return result | ||
38 | } catch (err) { | ||
39 | if (!withRetry || currentRetry > 10) throw err | ||
40 | |||
41 | await wait(250) | ||
42 | |||
43 | return this.get({ | ||
44 | ...options, | ||
45 | |||
46 | withRetry, | ||
47 | currentRetry: currentRetry + 1 | ||
48 | }) | ||
49 | } | ||
50 | } | ||
51 | |||
52 | async getFragmentedSegment (options: OverrideCommandOptions & { | ||
53 | url: string | ||
54 | range?: string | ||
55 | |||
56 | withRetry?: boolean // default false | ||
57 | currentRetry?: number | ||
58 | }) { | ||
59 | const { withRetry = false, currentRetry = 1 } = options | ||
60 | |||
61 | try { | ||
62 | const result = await unwrapBody<Buffer>(this.getRawRequest({ | ||
63 | ...options, | ||
64 | |||
65 | url: options.url, | ||
66 | range: options.range, | ||
67 | implicitToken: false, | ||
68 | responseType: 'application/octet-stream', | ||
69 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
70 | })) | ||
71 | |||
72 | return result | ||
73 | } catch (err) { | ||
74 | if (!withRetry || currentRetry > 10) throw err | ||
75 | |||
76 | await wait(250) | ||
77 | |||
78 | return this.getFragmentedSegment({ | ||
79 | ...options, | ||
80 | |||
81 | withRetry, | ||
82 | currentRetry: currentRetry + 1 | ||
83 | }) | ||
84 | } | ||
85 | } | ||
86 | |||
87 | async getSegmentSha256 (options: OverrideCommandOptions & { | ||
88 | url: string | ||
89 | |||
90 | withRetry?: boolean // default false | ||
91 | currentRetry?: number | ||
92 | }) { | ||
93 | const { withRetry = false, currentRetry = 1 } = options | ||
94 | |||
95 | try { | ||
96 | const result = await unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({ | ||
97 | ...options, | ||
98 | |||
99 | url: options.url, | ||
100 | contentType: 'application/json', | ||
101 | implicitToken: false, | ||
102 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
103 | })) | ||
104 | |||
105 | return result | ||
106 | } catch (err) { | ||
107 | if (!withRetry || currentRetry > 10) throw err | ||
108 | |||
109 | await wait(250) | ||
110 | |||
111 | return this.getSegmentSha256({ | ||
112 | ...options, | ||
113 | |||
114 | withRetry, | ||
115 | currentRetry: currentRetry + 1 | ||
116 | }) | ||
117 | } | ||
118 | } | ||
119 | } | ||
diff --git a/shared/server-commands/videos/video-passwords-command.ts b/shared/server-commands/videos/video-passwords-command.ts deleted file mode 100644 index bf10335b4..000000000 --- a/shared/server-commands/videos/video-passwords-command.ts +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | import { HttpStatusCode, ResultList, VideoPassword } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | export class VideoPasswordsCommand extends AbstractCommand { | ||
4 | |||
5 | list (options: OverrideCommandOptions & { | ||
6 | videoId: number | string | ||
7 | start?: number | ||
8 | count?: number | ||
9 | sort?: string | ||
10 | }) { | ||
11 | const { start, count, sort, videoId } = options | ||
12 | const path = '/api/v1/videos/' + videoId + '/passwords' | ||
13 | |||
14 | return this.getRequestBody<ResultList<VideoPassword>>({ | ||
15 | ...options, | ||
16 | |||
17 | path, | ||
18 | query: { start, count, sort }, | ||
19 | implicitToken: true, | ||
20 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
21 | }) | ||
22 | } | ||
23 | |||
24 | updateAll (options: OverrideCommandOptions & { | ||
25 | videoId: number | string | ||
26 | passwords: string[] | ||
27 | }) { | ||
28 | const { videoId, passwords } = options | ||
29 | const path = `/api/v1/videos/${videoId}/passwords` | ||
30 | |||
31 | return this.putBodyRequest({ | ||
32 | ...options, | ||
33 | path, | ||
34 | fields: { passwords }, | ||
35 | implicitToken: true, | ||
36 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
37 | }) | ||
38 | } | ||
39 | |||
40 | remove (options: OverrideCommandOptions & { | ||
41 | id: number | ||
42 | videoId: number | string | ||
43 | }) { | ||
44 | const { id, videoId } = options | ||
45 | const path = `/api/v1/videos/${videoId}/passwords/${id}` | ||
46 | |||
47 | return this.deleteRequest({ | ||
48 | ...options, | ||
49 | |||
50 | path, | ||
51 | implicitToken: true, | ||
52 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
53 | }) | ||
54 | } | ||
55 | } | ||
diff --git a/shared/server-commands/videos/video-stats-command.ts b/shared/server-commands/videos/video-stats-command.ts deleted file mode 100644 index b9b99bfb5..000000000 --- a/shared/server-commands/videos/video-stats-command.ts +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { HttpStatusCode, VideoStatsOverall, VideoStatsRetention, VideoStatsTimeserie, VideoStatsTimeserieMetric } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class VideoStatsCommand extends AbstractCommand { | ||
6 | |||
7 | getOverallStats (options: OverrideCommandOptions & { | ||
8 | videoId: number | string | ||
9 | startDate?: string | ||
10 | endDate?: string | ||
11 | }) { | ||
12 | const path = '/api/v1/videos/' + options.videoId + '/stats/overall' | ||
13 | |||
14 | return this.getRequestBody<VideoStatsOverall>({ | ||
15 | ...options, | ||
16 | path, | ||
17 | |||
18 | query: pick(options, [ 'startDate', 'endDate' ]), | ||
19 | |||
20 | implicitToken: true, | ||
21 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | getTimeserieStats (options: OverrideCommandOptions & { | ||
26 | videoId: number | string | ||
27 | metric: VideoStatsTimeserieMetric | ||
28 | startDate?: Date | ||
29 | endDate?: Date | ||
30 | }) { | ||
31 | const path = '/api/v1/videos/' + options.videoId + '/stats/timeseries/' + options.metric | ||
32 | |||
33 | return this.getRequestBody<VideoStatsTimeserie>({ | ||
34 | ...options, | ||
35 | path, | ||
36 | |||
37 | query: pick(options, [ 'startDate', 'endDate' ]), | ||
38 | implicitToken: true, | ||
39 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
40 | }) | ||
41 | } | ||
42 | |||
43 | getRetentionStats (options: OverrideCommandOptions & { | ||
44 | videoId: number | string | ||
45 | }) { | ||
46 | const path = '/api/v1/videos/' + options.videoId + '/stats/retention' | ||
47 | |||
48 | return this.getRequestBody<VideoStatsRetention>({ | ||
49 | ...options, | ||
50 | path, | ||
51 | |||
52 | implicitToken: true, | ||
53 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
54 | }) | ||
55 | } | ||
56 | } | ||
diff --git a/shared/server-commands/videos/video-studio-command.ts b/shared/server-commands/videos/video-studio-command.ts deleted file mode 100644 index 675cd84b7..000000000 --- a/shared/server-commands/videos/video-studio-command.ts +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | import { HttpStatusCode, VideoStudioTask } from '@shared/models' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export class VideoStudioCommand extends AbstractCommand { | ||
5 | |||
6 | static getComplexTask (): VideoStudioTask[] { | ||
7 | return [ | ||
8 | // Total duration: 2 | ||
9 | { | ||
10 | name: 'cut', | ||
11 | options: { | ||
12 | start: 1, | ||
13 | end: 3 | ||
14 | } | ||
15 | }, | ||
16 | |||
17 | // Total duration: 7 | ||
18 | { | ||
19 | name: 'add-outro', | ||
20 | options: { | ||
21 | file: 'video_short.webm' | ||
22 | } | ||
23 | }, | ||
24 | |||
25 | { | ||
26 | name: 'add-watermark', | ||
27 | options: { | ||
28 | file: 'custom-thumbnail.png' | ||
29 | } | ||
30 | }, | ||
31 | |||
32 | // Total duration: 9 | ||
33 | { | ||
34 | name: 'add-intro', | ||
35 | options: { | ||
36 | file: 'video_very_short_240p.mp4' | ||
37 | } | ||
38 | } | ||
39 | ] | ||
40 | } | ||
41 | |||
42 | createEditionTasks (options: OverrideCommandOptions & { | ||
43 | videoId: number | string | ||
44 | tasks: VideoStudioTask[] | ||
45 | }) { | ||
46 | const path = '/api/v1/videos/' + options.videoId + '/studio/edit' | ||
47 | const attaches: { [id: string]: any } = {} | ||
48 | |||
49 | for (let i = 0; i < options.tasks.length; i++) { | ||
50 | const task = options.tasks[i] | ||
51 | |||
52 | if (task.name === 'add-intro' || task.name === 'add-outro' || task.name === 'add-watermark') { | ||
53 | attaches[`tasks[${i}][options][file]`] = task.options.file | ||
54 | } | ||
55 | } | ||
56 | |||
57 | return this.postUploadRequest({ | ||
58 | ...options, | ||
59 | |||
60 | path, | ||
61 | attaches, | ||
62 | fields: { tasks: options.tasks }, | ||
63 | implicitToken: true, | ||
64 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
65 | }) | ||
66 | } | ||
67 | } | ||
diff --git a/shared/server-commands/videos/video-token-command.ts b/shared/server-commands/videos/video-token-command.ts deleted file mode 100644 index c4ed29a8c..000000000 --- a/shared/server-commands/videos/video-token-command.ts +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ | ||
2 | |||
3 | import { HttpStatusCode, VideoToken } from '@shared/models' | ||
4 | import { unwrapBody } from '../requests' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export class VideoTokenCommand extends AbstractCommand { | ||
8 | |||
9 | create (options: OverrideCommandOptions & { | ||
10 | videoId: number | string | ||
11 | videoPassword?: string | ||
12 | }) { | ||
13 | const { videoId, videoPassword } = options | ||
14 | const path = '/api/v1/videos/' + videoId + '/token' | ||
15 | |||
16 | return unwrapBody<VideoToken>(this.postBodyRequest({ | ||
17 | ...options, | ||
18 | headers: this.buildVideoPasswordHeader(videoPassword), | ||
19 | |||
20 | path, | ||
21 | implicitToken: true, | ||
22 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
23 | })) | ||
24 | } | ||
25 | |||
26 | async getVideoFileToken (options: OverrideCommandOptions & { | ||
27 | videoId: number | string | ||
28 | videoPassword?: string | ||
29 | }) { | ||
30 | const { files } = await this.create(options) | ||
31 | |||
32 | return files.token | ||
33 | } | ||
34 | } | ||
diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts deleted file mode 100644 index 4c3513ed4..000000000 --- a/shared/server-commands/videos/videos-command.ts +++ /dev/null | |||
@@ -1,829 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { createReadStream, stat } from 'fs-extra' | ||
5 | import got, { Response as GotResponse } from 'got' | ||
6 | import validator from 'validator' | ||
7 | import { buildAbsoluteFixturePath, getAllPrivacies, omit, pick, wait } from '@shared/core-utils' | ||
8 | import { buildUUID } from '@shared/extra-utils' | ||
9 | import { | ||
10 | HttpStatusCode, | ||
11 | ResultList, | ||
12 | UserVideoRateType, | ||
13 | Video, | ||
14 | VideoCreate, | ||
15 | VideoCreateResult, | ||
16 | VideoDetails, | ||
17 | VideoFileMetadata, | ||
18 | VideoInclude, | ||
19 | VideoPrivacy, | ||
20 | VideosCommonQuery, | ||
21 | VideoTranscodingCreate | ||
22 | } from '@shared/models' | ||
23 | import { VideoSource } from '@shared/models/videos/video-source' | ||
24 | import { unwrapBody } from '../requests' | ||
25 | import { waitJobs } from '../server' | ||
26 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
27 | |||
28 | export type VideoEdit = Partial<Omit<VideoCreate, 'thumbnailfile' | 'previewfile'>> & { | ||
29 | fixture?: string | ||
30 | thumbnailfile?: string | ||
31 | previewfile?: string | ||
32 | } | ||
33 | |||
34 | export class VideosCommand extends AbstractCommand { | ||
35 | |||
36 | getCategories (options: OverrideCommandOptions = {}) { | ||
37 | const path = '/api/v1/videos/categories' | ||
38 | |||
39 | return this.getRequestBody<{ [id: number]: string }>({ | ||
40 | ...options, | ||
41 | path, | ||
42 | |||
43 | implicitToken: false, | ||
44 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
45 | }) | ||
46 | } | ||
47 | |||
48 | getLicences (options: OverrideCommandOptions = {}) { | ||
49 | const path = '/api/v1/videos/licences' | ||
50 | |||
51 | return this.getRequestBody<{ [id: number]: string }>({ | ||
52 | ...options, | ||
53 | path, | ||
54 | |||
55 | implicitToken: false, | ||
56 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
57 | }) | ||
58 | } | ||
59 | |||
60 | getLanguages (options: OverrideCommandOptions = {}) { | ||
61 | const path = '/api/v1/videos/languages' | ||
62 | |||
63 | return this.getRequestBody<{ [id: string]: string }>({ | ||
64 | ...options, | ||
65 | path, | ||
66 | |||
67 | implicitToken: false, | ||
68 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
69 | }) | ||
70 | } | ||
71 | |||
72 | getPrivacies (options: OverrideCommandOptions = {}) { | ||
73 | const path = '/api/v1/videos/privacies' | ||
74 | |||
75 | return this.getRequestBody<{ [id in VideoPrivacy]: string }>({ | ||
76 | ...options, | ||
77 | path, | ||
78 | |||
79 | implicitToken: false, | ||
80 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
81 | }) | ||
82 | } | ||
83 | |||
84 | // --------------------------------------------------------------------------- | ||
85 | |||
86 | getDescription (options: OverrideCommandOptions & { | ||
87 | descriptionPath: string | ||
88 | }) { | ||
89 | return this.getRequestBody<{ description: string }>({ | ||
90 | ...options, | ||
91 | path: options.descriptionPath, | ||
92 | |||
93 | implicitToken: false, | ||
94 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
95 | }) | ||
96 | } | ||
97 | |||
98 | getFileMetadata (options: OverrideCommandOptions & { | ||
99 | url: string | ||
100 | }) { | ||
101 | return unwrapBody<VideoFileMetadata>(this.getRawRequest({ | ||
102 | ...options, | ||
103 | |||
104 | url: options.url, | ||
105 | implicitToken: false, | ||
106 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
107 | })) | ||
108 | } | ||
109 | |||
110 | // --------------------------------------------------------------------------- | ||
111 | |||
112 | rate (options: OverrideCommandOptions & { | ||
113 | id: number | string | ||
114 | rating: UserVideoRateType | ||
115 | videoPassword?: string | ||
116 | }) { | ||
117 | const { id, rating, videoPassword } = options | ||
118 | const path = '/api/v1/videos/' + id + '/rate' | ||
119 | |||
120 | return this.putBodyRequest({ | ||
121 | ...options, | ||
122 | |||
123 | path, | ||
124 | fields: { rating }, | ||
125 | headers: this.buildVideoPasswordHeader(videoPassword), | ||
126 | implicitToken: true, | ||
127 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
128 | }) | ||
129 | } | ||
130 | |||
131 | // --------------------------------------------------------------------------- | ||
132 | |||
133 | get (options: OverrideCommandOptions & { | ||
134 | id: number | string | ||
135 | }) { | ||
136 | const path = '/api/v1/videos/' + options.id | ||
137 | |||
138 | return this.getRequestBody<VideoDetails>({ | ||
139 | ...options, | ||
140 | |||
141 | path, | ||
142 | implicitToken: false, | ||
143 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
144 | }) | ||
145 | } | ||
146 | |||
147 | getWithToken (options: OverrideCommandOptions & { | ||
148 | id: number | string | ||
149 | }) { | ||
150 | return this.get({ | ||
151 | ...options, | ||
152 | |||
153 | token: this.buildCommonRequestToken({ ...options, implicitToken: true }) | ||
154 | }) | ||
155 | } | ||
156 | |||
157 | getWithPassword (options: OverrideCommandOptions & { | ||
158 | id: number | string | ||
159 | password?: string | ||
160 | }) { | ||
161 | const path = '/api/v1/videos/' + options.id | ||
162 | |||
163 | return this.getRequestBody<VideoDetails>({ | ||
164 | ...options, | ||
165 | headers:{ | ||
166 | 'x-peertube-video-password': options.password | ||
167 | }, | ||
168 | path, | ||
169 | implicitToken: false, | ||
170 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
171 | }) | ||
172 | } | ||
173 | |||
174 | getSource (options: OverrideCommandOptions & { | ||
175 | id: number | string | ||
176 | }) { | ||
177 | const path = '/api/v1/videos/' + options.id + '/source' | ||
178 | |||
179 | return this.getRequestBody<VideoSource>({ | ||
180 | ...options, | ||
181 | |||
182 | path, | ||
183 | implicitToken: true, | ||
184 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
185 | }) | ||
186 | } | ||
187 | |||
188 | async getId (options: OverrideCommandOptions & { | ||
189 | uuid: number | string | ||
190 | }) { | ||
191 | const { uuid } = options | ||
192 | |||
193 | if (validator.isUUID('' + uuid) === false) return uuid as number | ||
194 | |||
195 | const { id } = await this.get({ ...options, id: uuid }) | ||
196 | |||
197 | return id | ||
198 | } | ||
199 | |||
200 | async listFiles (options: OverrideCommandOptions & { | ||
201 | id: number | string | ||
202 | }) { | ||
203 | const video = await this.get(options) | ||
204 | |||
205 | const files = video.files || [] | ||
206 | const hlsFiles = video.streamingPlaylists[0]?.files || [] | ||
207 | |||
208 | return files.concat(hlsFiles) | ||
209 | } | ||
210 | |||
211 | // --------------------------------------------------------------------------- | ||
212 | |||
213 | listMyVideos (options: OverrideCommandOptions & { | ||
214 | start?: number | ||
215 | count?: number | ||
216 | sort?: string | ||
217 | search?: string | ||
218 | isLive?: boolean | ||
219 | channelId?: number | ||
220 | } = {}) { | ||
221 | const path = '/api/v1/users/me/videos' | ||
222 | |||
223 | return this.getRequestBody<ResultList<Video>>({ | ||
224 | ...options, | ||
225 | |||
226 | path, | ||
227 | query: pick(options, [ 'start', 'count', 'sort', 'search', 'isLive', 'channelId' ]), | ||
228 | implicitToken: true, | ||
229 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
230 | }) | ||
231 | } | ||
232 | |||
233 | listMySubscriptionVideos (options: OverrideCommandOptions & VideosCommonQuery = {}) { | ||
234 | const { sort = '-createdAt' } = options | ||
235 | const path = '/api/v1/users/me/subscriptions/videos' | ||
236 | |||
237 | return this.getRequestBody<ResultList<Video>>({ | ||
238 | ...options, | ||
239 | |||
240 | path, | ||
241 | query: { sort, ...this.buildListQuery(options) }, | ||
242 | implicitToken: true, | ||
243 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
244 | }) | ||
245 | } | ||
246 | |||
247 | // --------------------------------------------------------------------------- | ||
248 | |||
249 | list (options: OverrideCommandOptions & VideosCommonQuery = {}) { | ||
250 | const path = '/api/v1/videos' | ||
251 | |||
252 | const query = this.buildListQuery(options) | ||
253 | |||
254 | return this.getRequestBody<ResultList<Video>>({ | ||
255 | ...options, | ||
256 | |||
257 | path, | ||
258 | query: { sort: 'name', ...query }, | ||
259 | implicitToken: false, | ||
260 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
261 | }) | ||
262 | } | ||
263 | |||
264 | listWithToken (options: OverrideCommandOptions & VideosCommonQuery = {}) { | ||
265 | return this.list({ | ||
266 | ...options, | ||
267 | |||
268 | token: this.buildCommonRequestToken({ ...options, implicitToken: true }) | ||
269 | }) | ||
270 | } | ||
271 | |||
272 | listAllForAdmin (options: OverrideCommandOptions & VideosCommonQuery = {}) { | ||
273 | const include = VideoInclude.NOT_PUBLISHED_STATE | VideoInclude.BLACKLISTED | VideoInclude.BLOCKED_OWNER | ||
274 | const nsfw = 'both' | ||
275 | const privacyOneOf = getAllPrivacies() | ||
276 | |||
277 | return this.list({ | ||
278 | ...options, | ||
279 | |||
280 | include, | ||
281 | nsfw, | ||
282 | privacyOneOf, | ||
283 | |||
284 | token: this.buildCommonRequestToken({ ...options, implicitToken: true }) | ||
285 | }) | ||
286 | } | ||
287 | |||
288 | listByAccount (options: OverrideCommandOptions & VideosCommonQuery & { | ||
289 | handle: string | ||
290 | }) { | ||
291 | const { handle, search } = options | ||
292 | const path = '/api/v1/accounts/' + handle + '/videos' | ||
293 | |||
294 | return this.getRequestBody<ResultList<Video>>({ | ||
295 | ...options, | ||
296 | |||
297 | path, | ||
298 | query: { search, ...this.buildListQuery(options) }, | ||
299 | implicitToken: true, | ||
300 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
301 | }) | ||
302 | } | ||
303 | |||
304 | listByChannel (options: OverrideCommandOptions & VideosCommonQuery & { | ||
305 | handle: string | ||
306 | }) { | ||
307 | const { handle } = options | ||
308 | const path = '/api/v1/video-channels/' + handle + '/videos' | ||
309 | |||
310 | return this.getRequestBody<ResultList<Video>>({ | ||
311 | ...options, | ||
312 | |||
313 | path, | ||
314 | query: this.buildListQuery(options), | ||
315 | implicitToken: true, | ||
316 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
317 | }) | ||
318 | } | ||
319 | |||
320 | // --------------------------------------------------------------------------- | ||
321 | |||
322 | async find (options: OverrideCommandOptions & { | ||
323 | name: string | ||
324 | }) { | ||
325 | const { data } = await this.list(options) | ||
326 | |||
327 | return data.find(v => v.name === options.name) | ||
328 | } | ||
329 | |||
330 | // --------------------------------------------------------------------------- | ||
331 | |||
332 | update (options: OverrideCommandOptions & { | ||
333 | id: number | string | ||
334 | attributes?: VideoEdit | ||
335 | }) { | ||
336 | const { id, attributes = {} } = options | ||
337 | const path = '/api/v1/videos/' + id | ||
338 | |||
339 | // Upload request | ||
340 | if (attributes.thumbnailfile || attributes.previewfile) { | ||
341 | const attaches: any = {} | ||
342 | if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile | ||
343 | if (attributes.previewfile) attaches.previewfile = attributes.previewfile | ||
344 | |||
345 | return this.putUploadRequest({ | ||
346 | ...options, | ||
347 | |||
348 | path, | ||
349 | fields: options.attributes, | ||
350 | attaches: { | ||
351 | thumbnailfile: attributes.thumbnailfile, | ||
352 | previewfile: attributes.previewfile | ||
353 | }, | ||
354 | implicitToken: true, | ||
355 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
356 | }) | ||
357 | } | ||
358 | |||
359 | return this.putBodyRequest({ | ||
360 | ...options, | ||
361 | |||
362 | path, | ||
363 | fields: options.attributes, | ||
364 | implicitToken: true, | ||
365 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
366 | }) | ||
367 | } | ||
368 | |||
369 | remove (options: OverrideCommandOptions & { | ||
370 | id: number | string | ||
371 | }) { | ||
372 | const path = '/api/v1/videos/' + options.id | ||
373 | |||
374 | return unwrapBody(this.deleteRequest({ | ||
375 | ...options, | ||
376 | |||
377 | path, | ||
378 | implicitToken: true, | ||
379 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
380 | })) | ||
381 | } | ||
382 | |||
383 | async removeAll () { | ||
384 | const { data } = await this.list() | ||
385 | |||
386 | for (const v of data) { | ||
387 | await this.remove({ id: v.id }) | ||
388 | } | ||
389 | } | ||
390 | |||
391 | // --------------------------------------------------------------------------- | ||
392 | |||
393 | async upload (options: OverrideCommandOptions & { | ||
394 | attributes?: VideoEdit | ||
395 | mode?: 'legacy' | 'resumable' // default legacy | ||
396 | waitTorrentGeneration?: boolean // default true | ||
397 | completedExpectedStatus?: HttpStatusCode | ||
398 | } = {}) { | ||
399 | const { mode = 'legacy', waitTorrentGeneration = true } = options | ||
400 | let defaultChannelId = 1 | ||
401 | |||
402 | try { | ||
403 | const { videoChannels } = await this.server.users.getMyInfo({ token: options.token }) | ||
404 | defaultChannelId = videoChannels[0].id | ||
405 | } catch (e) { /* empty */ } | ||
406 | |||
407 | // Override default attributes | ||
408 | const attributes = { | ||
409 | name: 'my super video', | ||
410 | category: 5, | ||
411 | licence: 4, | ||
412 | language: 'zh', | ||
413 | channelId: defaultChannelId, | ||
414 | nsfw: true, | ||
415 | waitTranscoding: false, | ||
416 | description: 'my super description', | ||
417 | support: 'my super support text', | ||
418 | tags: [ 'tag' ], | ||
419 | privacy: VideoPrivacy.PUBLIC, | ||
420 | commentsEnabled: true, | ||
421 | downloadEnabled: true, | ||
422 | fixture: 'video_short.webm', | ||
423 | |||
424 | ...options.attributes | ||
425 | } | ||
426 | |||
427 | const created = mode === 'legacy' | ||
428 | ? await this.buildLegacyUpload({ ...options, attributes }) | ||
429 | : await this.buildResumeUpload({ ...options, path: '/api/v1/videos/upload-resumable', attributes }) | ||
430 | |||
431 | // Wait torrent generation | ||
432 | const expectedStatus = this.buildExpectedStatus({ ...options, defaultExpectedStatus: HttpStatusCode.OK_200 }) | ||
433 | if (expectedStatus === HttpStatusCode.OK_200 && waitTorrentGeneration) { | ||
434 | let video: VideoDetails | ||
435 | |||
436 | do { | ||
437 | video = await this.getWithToken({ ...options, id: created.uuid }) | ||
438 | |||
439 | await wait(50) | ||
440 | } while (!video.files[0].torrentUrl) | ||
441 | } | ||
442 | |||
443 | return created | ||
444 | } | ||
445 | |||
446 | async buildLegacyUpload (options: OverrideCommandOptions & { | ||
447 | attributes: VideoEdit | ||
448 | }): Promise<VideoCreateResult> { | ||
449 | const path = '/api/v1/videos/upload' | ||
450 | |||
451 | return unwrapBody<{ video: VideoCreateResult }>(this.postUploadRequest({ | ||
452 | ...options, | ||
453 | |||
454 | path, | ||
455 | fields: this.buildUploadFields(options.attributes), | ||
456 | attaches: this.buildUploadAttaches(options.attributes), | ||
457 | implicitToken: true, | ||
458 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
459 | })).then(body => body.video || body as any) | ||
460 | } | ||
461 | |||
462 | async buildResumeUpload (options: OverrideCommandOptions & { | ||
463 | path: string | ||
464 | attributes: { fixture?: string } & { [id: string]: any } | ||
465 | completedExpectedStatus?: HttpStatusCode // When the upload is finished | ||
466 | }): Promise<VideoCreateResult> { | ||
467 | const { path, attributes, expectedStatus = HttpStatusCode.OK_200, completedExpectedStatus } = options | ||
468 | |||
469 | let size = 0 | ||
470 | let videoFilePath: string | ||
471 | let mimetype = 'video/mp4' | ||
472 | |||
473 | if (attributes.fixture) { | ||
474 | videoFilePath = buildAbsoluteFixturePath(attributes.fixture) | ||
475 | size = (await stat(videoFilePath)).size | ||
476 | |||
477 | if (videoFilePath.endsWith('.mkv')) { | ||
478 | mimetype = 'video/x-matroska' | ||
479 | } else if (videoFilePath.endsWith('.webm')) { | ||
480 | mimetype = 'video/webm' | ||
481 | } | ||
482 | } | ||
483 | |||
484 | // Do not check status automatically, we'll check it manually | ||
485 | const initializeSessionRes = await this.prepareResumableUpload({ | ||
486 | ...options, | ||
487 | |||
488 | path, | ||
489 | expectedStatus: null, | ||
490 | attributes, | ||
491 | size, | ||
492 | mimetype | ||
493 | }) | ||
494 | const initStatus = initializeSessionRes.status | ||
495 | |||
496 | if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) { | ||
497 | const locationHeader = initializeSessionRes.header['location'] | ||
498 | expect(locationHeader).to.not.be.undefined | ||
499 | |||
500 | const pathUploadId = locationHeader.split('?')[1] | ||
501 | |||
502 | const result = await this.sendResumableChunks({ | ||
503 | ...options, | ||
504 | |||
505 | path, | ||
506 | pathUploadId, | ||
507 | videoFilePath, | ||
508 | size, | ||
509 | expectedStatus: completedExpectedStatus | ||
510 | }) | ||
511 | |||
512 | if (result.statusCode === HttpStatusCode.OK_200) { | ||
513 | await this.endResumableUpload({ | ||
514 | ...options, | ||
515 | |||
516 | expectedStatus: HttpStatusCode.NO_CONTENT_204, | ||
517 | path, | ||
518 | pathUploadId | ||
519 | }) | ||
520 | } | ||
521 | |||
522 | return result.body?.video || result.body as any | ||
523 | } | ||
524 | |||
525 | const expectedInitStatus = expectedStatus === HttpStatusCode.OK_200 | ||
526 | ? HttpStatusCode.CREATED_201 | ||
527 | : expectedStatus | ||
528 | |||
529 | expect(initStatus).to.equal(expectedInitStatus) | ||
530 | |||
531 | return initializeSessionRes.body.video || initializeSessionRes.body | ||
532 | } | ||
533 | |||
534 | async prepareResumableUpload (options: OverrideCommandOptions & { | ||
535 | path: string | ||
536 | attributes: { fixture?: string } & { [id: string]: any } | ||
537 | size: number | ||
538 | mimetype: string | ||
539 | |||
540 | originalName?: string | ||
541 | lastModified?: number | ||
542 | }) { | ||
543 | const { path, attributes, originalName, lastModified, size, mimetype } = options | ||
544 | |||
545 | const attaches = this.buildUploadAttaches(omit(options.attributes, [ 'fixture' ])) | ||
546 | |||
547 | const uploadOptions = { | ||
548 | ...options, | ||
549 | |||
550 | path, | ||
551 | headers: { | ||
552 | 'X-Upload-Content-Type': mimetype, | ||
553 | 'X-Upload-Content-Length': size.toString() | ||
554 | }, | ||
555 | fields: { | ||
556 | filename: attributes.fixture, | ||
557 | originalName, | ||
558 | lastModified, | ||
559 | |||
560 | ...this.buildUploadFields(options.attributes) | ||
561 | }, | ||
562 | |||
563 | // Fixture will be sent later | ||
564 | attaches: this.buildUploadAttaches(omit(options.attributes, [ 'fixture' ])), | ||
565 | implicitToken: true, | ||
566 | |||
567 | defaultExpectedStatus: null | ||
568 | } | ||
569 | |||
570 | if (Object.keys(attaches).length === 0) return this.postBodyRequest(uploadOptions) | ||
571 | |||
572 | return this.postUploadRequest(uploadOptions) | ||
573 | } | ||
574 | |||
575 | sendResumableChunks (options: OverrideCommandOptions & { | ||
576 | pathUploadId: string | ||
577 | path: string | ||
578 | videoFilePath: string | ||
579 | size: number | ||
580 | contentLength?: number | ||
581 | contentRangeBuilder?: (start: number, chunk: any) => string | ||
582 | digestBuilder?: (chunk: any) => string | ||
583 | }) { | ||
584 | const { | ||
585 | path, | ||
586 | pathUploadId, | ||
587 | videoFilePath, | ||
588 | size, | ||
589 | contentLength, | ||
590 | contentRangeBuilder, | ||
591 | digestBuilder, | ||
592 | expectedStatus = HttpStatusCode.OK_200 | ||
593 | } = options | ||
594 | |||
595 | let start = 0 | ||
596 | |||
597 | const token = this.buildCommonRequestToken({ ...options, implicitToken: true }) | ||
598 | const url = this.server.url | ||
599 | |||
600 | const readable = createReadStream(videoFilePath, { highWaterMark: 8 * 1024 }) | ||
601 | return new Promise<GotResponse<{ video: VideoCreateResult }>>((resolve, reject) => { | ||
602 | readable.on('data', async function onData (chunk) { | ||
603 | try { | ||
604 | readable.pause() | ||
605 | |||
606 | const byterangeStart = start + chunk.length - 1 | ||
607 | |||
608 | const headers = { | ||
609 | 'Authorization': 'Bearer ' + token, | ||
610 | 'Content-Type': 'application/octet-stream', | ||
611 | 'Content-Range': contentRangeBuilder | ||
612 | ? contentRangeBuilder(start, chunk) | ||
613 | : `bytes ${start}-${byterangeStart}/${size}`, | ||
614 | 'Content-Length': contentLength ? contentLength + '' : chunk.length + '' | ||
615 | } | ||
616 | |||
617 | if (digestBuilder) { | ||
618 | Object.assign(headers, { digest: digestBuilder(chunk) }) | ||
619 | } | ||
620 | |||
621 | const res = await got<{ video: VideoCreateResult }>({ | ||
622 | url, | ||
623 | method: 'put', | ||
624 | headers, | ||
625 | path: path + '?' + pathUploadId, | ||
626 | body: chunk, | ||
627 | responseType: 'json', | ||
628 | throwHttpErrors: false | ||
629 | }) | ||
630 | |||
631 | start += chunk.length | ||
632 | |||
633 | // Last request, check final status | ||
634 | if (byterangeStart + 1 === size) { | ||
635 | if (res.statusCode === expectedStatus) { | ||
636 | return resolve(res) | ||
637 | } | ||
638 | |||
639 | if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) { | ||
640 | readable.off('data', onData) | ||
641 | |||
642 | // eslint-disable-next-line max-len | ||
643 | const message = `Incorrect transient behaviour sending intermediary chunks. Status code is ${res.statusCode} instead of ${expectedStatus}` | ||
644 | return reject(new Error(message)) | ||
645 | } | ||
646 | } | ||
647 | |||
648 | readable.resume() | ||
649 | } catch (err) { | ||
650 | reject(err) | ||
651 | } | ||
652 | }) | ||
653 | }) | ||
654 | } | ||
655 | |||
656 | endResumableUpload (options: OverrideCommandOptions & { | ||
657 | path: string | ||
658 | pathUploadId: string | ||
659 | }) { | ||
660 | return this.deleteRequest({ | ||
661 | ...options, | ||
662 | |||
663 | path: options.path, | ||
664 | rawQuery: options.pathUploadId, | ||
665 | implicitToken: true, | ||
666 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
667 | }) | ||
668 | } | ||
669 | |||
670 | quickUpload (options: OverrideCommandOptions & { | ||
671 | name: string | ||
672 | nsfw?: boolean | ||
673 | privacy?: VideoPrivacy | ||
674 | fixture?: string | ||
675 | videoPasswords?: string[] | ||
676 | }) { | ||
677 | const attributes: VideoEdit = { name: options.name } | ||
678 | if (options.nsfw) attributes.nsfw = options.nsfw | ||
679 | if (options.privacy) attributes.privacy = options.privacy | ||
680 | if (options.fixture) attributes.fixture = options.fixture | ||
681 | if (options.videoPasswords) attributes.videoPasswords = options.videoPasswords | ||
682 | |||
683 | return this.upload({ ...options, attributes }) | ||
684 | } | ||
685 | |||
686 | async randomUpload (options: OverrideCommandOptions & { | ||
687 | wait?: boolean // default true | ||
688 | additionalParams?: VideoEdit & { prefixName?: string } | ||
689 | } = {}) { | ||
690 | const { wait = true, additionalParams } = options | ||
691 | const prefixName = additionalParams?.prefixName || '' | ||
692 | const name = prefixName + buildUUID() | ||
693 | |||
694 | const attributes = { name, ...additionalParams } | ||
695 | |||
696 | const result = await this.upload({ ...options, attributes }) | ||
697 | |||
698 | if (wait) await waitJobs([ this.server ]) | ||
699 | |||
700 | return { ...result, name } | ||
701 | } | ||
702 | |||
703 | // --------------------------------------------------------------------------- | ||
704 | |||
705 | replaceSourceFile (options: OverrideCommandOptions & { | ||
706 | videoId: number | string | ||
707 | fixture: string | ||
708 | completedExpectedStatus?: HttpStatusCode | ||
709 | }) { | ||
710 | return this.buildResumeUpload({ | ||
711 | ...options, | ||
712 | |||
713 | path: '/api/v1/videos/' + options.videoId + '/source/replace-resumable', | ||
714 | attributes: { fixture: options.fixture } | ||
715 | }) | ||
716 | } | ||
717 | |||
718 | // --------------------------------------------------------------------------- | ||
719 | |||
720 | removeHLSPlaylist (options: OverrideCommandOptions & { | ||
721 | videoId: number | string | ||
722 | }) { | ||
723 | const path = '/api/v1/videos/' + options.videoId + '/hls' | ||
724 | |||
725 | return this.deleteRequest({ | ||
726 | ...options, | ||
727 | |||
728 | path, | ||
729 | implicitToken: true, | ||
730 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
731 | }) | ||
732 | } | ||
733 | |||
734 | removeHLSFile (options: OverrideCommandOptions & { | ||
735 | videoId: number | string | ||
736 | fileId: number | ||
737 | }) { | ||
738 | const path = '/api/v1/videos/' + options.videoId + '/hls/' + options.fileId | ||
739 | |||
740 | return this.deleteRequest({ | ||
741 | ...options, | ||
742 | |||
743 | path, | ||
744 | implicitToken: true, | ||
745 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
746 | }) | ||
747 | } | ||
748 | |||
749 | removeAllWebVideoFiles (options: OverrideCommandOptions & { | ||
750 | videoId: number | string | ||
751 | }) { | ||
752 | const path = '/api/v1/videos/' + options.videoId + '/web-videos' | ||
753 | |||
754 | return this.deleteRequest({ | ||
755 | ...options, | ||
756 | |||
757 | path, | ||
758 | implicitToken: true, | ||
759 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
760 | }) | ||
761 | } | ||
762 | |||
763 | removeWebVideoFile (options: OverrideCommandOptions & { | ||
764 | videoId: number | string | ||
765 | fileId: number | ||
766 | }) { | ||
767 | const path = '/api/v1/videos/' + options.videoId + '/web-videos/' + options.fileId | ||
768 | |||
769 | return this.deleteRequest({ | ||
770 | ...options, | ||
771 | |||
772 | path, | ||
773 | implicitToken: true, | ||
774 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
775 | }) | ||
776 | } | ||
777 | |||
778 | runTranscoding (options: OverrideCommandOptions & VideoTranscodingCreate & { | ||
779 | videoId: number | string | ||
780 | }) { | ||
781 | const path = '/api/v1/videos/' + options.videoId + '/transcoding' | ||
782 | |||
783 | return this.postBodyRequest({ | ||
784 | ...options, | ||
785 | |||
786 | path, | ||
787 | fields: pick(options, [ 'transcodingType', 'forceTranscoding' ]), | ||
788 | implicitToken: true, | ||
789 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
790 | }) | ||
791 | } | ||
792 | |||
793 | // --------------------------------------------------------------------------- | ||
794 | |||
795 | private buildListQuery (options: VideosCommonQuery) { | ||
796 | return pick(options, [ | ||
797 | 'start', | ||
798 | 'count', | ||
799 | 'sort', | ||
800 | 'nsfw', | ||
801 | 'isLive', | ||
802 | 'categoryOneOf', | ||
803 | 'licenceOneOf', | ||
804 | 'languageOneOf', | ||
805 | 'privacyOneOf', | ||
806 | 'tagsOneOf', | ||
807 | 'tagsAllOf', | ||
808 | 'isLocal', | ||
809 | 'include', | ||
810 | 'skipCount' | ||
811 | ]) | ||
812 | } | ||
813 | |||
814 | private buildUploadFields (attributes: VideoEdit) { | ||
815 | return omit(attributes, [ 'fixture', 'thumbnailfile', 'previewfile' ]) | ||
816 | } | ||
817 | |||
818 | private buildUploadAttaches (attributes: VideoEdit) { | ||
819 | const attaches: { [ name: string ]: string } = {} | ||
820 | |||
821 | for (const key of [ 'thumbnailfile', 'previewfile' ]) { | ||
822 | if (attributes[key]) attaches[key] = buildAbsoluteFixturePath(attributes[key]) | ||
823 | } | ||
824 | |||
825 | if (attributes.fixture) attaches.videofile = buildAbsoluteFixturePath(attributes.fixture) | ||
826 | |||
827 | return attaches | ||
828 | } | ||
829 | } | ||
diff --git a/shared/server-commands/videos/views-command.ts b/shared/server-commands/videos/views-command.ts deleted file mode 100644 index bdb8daaa4..000000000 --- a/shared/server-commands/videos/views-command.ts +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ | ||
2 | import { HttpStatusCode, VideoViewEvent } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class ViewsCommand extends AbstractCommand { | ||
6 | |||
7 | view (options: OverrideCommandOptions & { | ||
8 | id: number | string | ||
9 | currentTime: number | ||
10 | viewEvent?: VideoViewEvent | ||
11 | xForwardedFor?: string | ||
12 | }) { | ||
13 | const { id, xForwardedFor, viewEvent, currentTime } = options | ||
14 | const path = '/api/v1/videos/' + id + '/views' | ||
15 | |||
16 | return this.postBodyRequest({ | ||
17 | ...options, | ||
18 | |||
19 | path, | ||
20 | xForwardedFor, | ||
21 | fields: { | ||
22 | currentTime, | ||
23 | viewEvent | ||
24 | }, | ||
25 | implicitToken: false, | ||
26 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
27 | }) | ||
28 | } | ||
29 | |||
30 | async simulateView (options: OverrideCommandOptions & { | ||
31 | id: number | string | ||
32 | xForwardedFor?: string | ||
33 | }) { | ||
34 | await this.view({ ...options, currentTime: 0 }) | ||
35 | await this.view({ ...options, currentTime: 5 }) | ||
36 | } | ||
37 | |||
38 | async simulateViewer (options: OverrideCommandOptions & { | ||
39 | id: number | string | ||
40 | currentTimes: number[] | ||
41 | xForwardedFor?: string | ||
42 | }) { | ||
43 | let viewEvent: VideoViewEvent = 'seek' | ||
44 | |||
45 | for (const currentTime of options.currentTimes) { | ||
46 | await this.view({ ...options, currentTime, viewEvent }) | ||
47 | |||
48 | viewEvent = undefined | ||
49 | } | ||
50 | } | ||
51 | } | ||
diff --git a/shared/tsconfig.json b/shared/tsconfig.json deleted file mode 100644 index 95892077b..000000000 --- a/shared/tsconfig.json +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | { | ||
2 | "extends": "../tsconfig.base.json", | ||
3 | "compilerOptions": { | ||
4 | "outDir": "../dist/shared" | ||
5 | } | ||
6 | } | ||
diff --git a/shared/tsconfig.types.json b/shared/tsconfig.types.json deleted file mode 100644 index 6acfc05e1..000000000 --- a/shared/tsconfig.types.json +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | { | ||
2 | "extends": "./tsconfig.json", | ||
3 | "compilerOptions": { | ||
4 | "outDir": "../packages/types/dist/shared", | ||
5 | "stripInternal": true, | ||
6 | "removeComments": false, | ||
7 | "emitDeclarationOnly": true | ||
8 | }, | ||
9 | "exclude": [ | ||
10 | "server-commands/" | ||
11 | ] | ||
12 | } | ||
diff --git a/shared/typescript-utils/index.ts b/shared/typescript-utils/index.ts deleted file mode 100644 index c9f6f047d..000000000 --- a/shared/typescript-utils/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './types' | ||
diff --git a/shared/typescript-utils/types.ts b/shared/typescript-utils/types.ts deleted file mode 100644 index 57cc23f1f..000000000 --- a/shared/typescript-utils/types.ts +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/array-type */ | ||
2 | |||
3 | export type FunctionPropertyNames<T> = { | ||
4 | [K in keyof T]: T[K] extends Function ? K : never | ||
5 | }[keyof T] | ||
6 | |||
7 | export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>> | ||
8 | |||
9 | export type AttributesOnly<T> = { | ||
10 | [K in keyof T]: T[K] extends Function ? never : T[K] | ||
11 | } | ||
12 | |||
13 | export type PickWith<T, KT extends keyof T, V> = { | ||
14 | [P in KT]: T[P] extends V ? V : never | ||
15 | } | ||
16 | |||
17 | export type PickWithOpt<T, KT extends keyof T, V> = { | ||
18 | [P in KT]?: T[P] extends V ? V : never | ||
19 | } | ||
20 | |||
21 | // https://github.com/krzkaczor/ts-essentials Rocks! | ||
22 | export type DeepPartial<T> = { | ||
23 | [P in keyof T]?: T[P] extends Array<infer U> | ||
24 | ? Array<DeepPartial<U>> | ||
25 | : T[P] extends ReadonlyArray<infer U> | ||
26 | ? ReadonlyArray<DeepPartial<U>> | ||
27 | : DeepPartial<T[P]> | ||
28 | } | ||
29 | |||
30 | type Primitive = string | Function | number | boolean | symbol | undefined | null | ||
31 | export type DeepOmitHelper<T, K extends keyof T> = { | ||
32 | [P in K]: // extra level of indirection needed to trigger homomorhic behavior | ||
33 | T[P] extends infer TP // distribute over unions | ||
34 | ? TP extends Primitive | ||
35 | ? TP // leave primitives and functions alone | ||
36 | : TP extends any[] | ||
37 | ? DeepOmitArray<TP, K> // Array special handling | ||
38 | : DeepOmit<TP, K> | ||
39 | : never | ||
40 | } | ||
41 | export type DeepOmit<T, K> = T extends Primitive ? T : DeepOmitHelper<T, Exclude<keyof T, K>> | ||
42 | |||
43 | export type DeepOmitArray<T extends any[], K> = { | ||
44 | [P in keyof T]: DeepOmit<T[P], K> | ||
45 | } | ||