constants.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. import { join } from 'path'
  2. import { JobType, VideoRateType, VideoResolution, VideoState } from '../../shared/models'
  3. import { ActivityPubActorType } from '../../shared/models/activitypub'
  4. import { FollowState } from '../../shared/models/actors'
  5. import { VideoAbuseState, VideoImportState, VideoPrivacy, VideoTranscodingFPS } from '../../shared/models/videos'
  6. // Do not use barrels, remain constants as independent as possible
  7. import { isTestInstance, sanitizeHost, sanitizeUrl, root } from '../helpers/core-utils'
  8. import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
  9. import { invert } from 'lodash'
  10. import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
  11. import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model'
  12. import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model'
  13. import { CONFIG, registerConfigChangedHandler } from './config'
  14. // ---------------------------------------------------------------------------
  15. const LAST_MIGRATION_VERSION = 395
  16. // ---------------------------------------------------------------------------
  17. // API version
  18. const API_VERSION = 'v1'
  19. const PAGINATION = {
  20. COUNT: {
  21. DEFAULT: 15,
  22. MAX: 100
  23. }
  24. }
  25. const WEBSERVER = {
  26. URL: '',
  27. HOST: '',
  28. SCHEME: '',
  29. WS: '',
  30. HOSTNAME: '',
  31. PORT: 0
  32. }
  33. // Sortable columns per schema
  34. const SORTABLE_COLUMNS = {
  35. USERS: [ 'id', 'username', 'createdAt' ],
  36. USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ],
  37. ACCOUNTS: [ 'createdAt' ],
  38. JOBS: [ 'createdAt' ],
  39. VIDEO_ABUSES: [ 'id', 'createdAt', 'state' ],
  40. VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
  41. VIDEO_IMPORTS: [ 'createdAt' ],
  42. VIDEO_COMMENT_THREADS: [ 'createdAt' ],
  43. VIDEO_RATES: [ 'createdAt' ],
  44. BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
  45. FOLLOWERS: [ 'createdAt' ],
  46. FOLLOWING: [ 'createdAt' ],
  47. VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'trending' ],
  48. VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'match' ],
  49. VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
  50. ACCOUNTS_BLOCKLIST: [ 'createdAt' ],
  51. SERVERS_BLOCKLIST: [ 'createdAt' ],
  52. USER_NOTIFICATIONS: [ 'createdAt' ],
  53. VIDEO_PLAYLISTS: [ 'displayName', 'createdAt', 'updatedAt' ]
  54. }
  55. const OAUTH_LIFETIME = {
  56. ACCESS_TOKEN: 3600 * 24, // 1 day, for upload
  57. REFRESH_TOKEN: 1209600 // 2 weeks
  58. }
  59. const ROUTE_CACHE_LIFETIME = {
  60. FEEDS: '15 minutes',
  61. ROBOTS: '2 hours',
  62. SITEMAP: '1 day',
  63. SECURITYTXT: '2 hours',
  64. NODEINFO: '10 minutes',
  65. DNT_POLICY: '1 week',
  66. OVERVIEWS: {
  67. VIDEOS: '1 hour'
  68. },
  69. ACTIVITY_PUB: {
  70. VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example
  71. },
  72. STATS: '4 hours'
  73. }
  74. // ---------------------------------------------------------------------------
  75. // Number of points we add/remove after a successful/bad request
  76. const ACTOR_FOLLOW_SCORE = {
  77. PENALTY: -10,
  78. BONUS: 10,
  79. BASE: 1000,
  80. MAX: 10000
  81. }
  82. const FOLLOW_STATES: { [ id: string ]: FollowState } = {
  83. PENDING: 'pending',
  84. ACCEPTED: 'accepted'
  85. }
  86. const REMOTE_SCHEME = {
  87. HTTP: 'https',
  88. WS: 'wss'
  89. }
  90. // TODO: remove 'video-file'
  91. const JOB_ATTEMPTS: { [id in (JobType | 'video-file')]: number } = {
  92. 'activitypub-http-broadcast': 5,
  93. 'activitypub-http-unicast': 5,
  94. 'activitypub-http-fetcher': 5,
  95. 'activitypub-follow': 5,
  96. 'video-file-import': 1,
  97. 'video-transcoding': 1,
  98. 'video-file': 1,
  99. 'video-import': 1,
  100. 'email': 5,
  101. 'videos-views': 1,
  102. 'activitypub-refresher': 1
  103. }
  104. const JOB_CONCURRENCY: { [id in (JobType | 'video-file')]: number } = {
  105. 'activitypub-http-broadcast': 1,
  106. 'activitypub-http-unicast': 5,
  107. 'activitypub-http-fetcher': 1,
  108. 'activitypub-follow': 3,
  109. 'video-file-import': 1,
  110. 'video-transcoding': 1,
  111. 'video-file': 1,
  112. 'video-import': 1,
  113. 'email': 5,
  114. 'videos-views': 1,
  115. 'activitypub-refresher': 1
  116. }
  117. const JOB_TTL: { [id in (JobType | 'video-file')]: number } = {
  118. 'activitypub-http-broadcast': 60000 * 10, // 10 minutes
  119. 'activitypub-http-unicast': 60000 * 10, // 10 minutes
  120. 'activitypub-http-fetcher': 60000 * 10, // 10 minutes
  121. 'activitypub-follow': 60000 * 10, // 10 minutes
  122. 'video-file-import': 1000 * 3600, // 1 hour
  123. 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long
  124. 'video-file': 1000 * 3600 * 48, // 2 days, transcoding could be long
  125. 'video-import': 1000 * 3600 * 2, // hours
  126. 'email': 60000 * 10, // 10 minutes
  127. 'videos-views': undefined, // Unlimited
  128. 'activitypub-refresher': 60000 * 10 // 10 minutes
  129. }
  130. const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = {
  131. 'videos-views': {
  132. cron: '1 * * * *' // At 1 minute past the hour
  133. }
  134. }
  135. const BROADCAST_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-http-broadcast job
  136. const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
  137. const JOB_REQUEST_TIMEOUT = 3000 // 3 seconds
  138. const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
  139. const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour
  140. const SCHEDULER_INTERVALS_MS = {
  141. actorFollowScores: 60000 * 60, // 1 hour
  142. removeOldJobs: 60000 * 60, // 1 hour
  143. updateVideos: 60000, // 1 minute
  144. youtubeDLUpdate: 60000 * 60 * 24, // 1 day
  145. removeOldViews: 60000 * 60 * 24, // 1 day
  146. removeOldHistory: 60000 * 60 * 24 // 1 day
  147. }
  148. // ---------------------------------------------------------------------------
  149. let CONSTRAINTS_FIELDS = {
  150. USERS: {
  151. NAME: { min: 1, max: 120 }, // Length
  152. DESCRIPTION: { min: 3, max: 1000 }, // Length
  153. USERNAME: { min: 1, max: 50 }, // Length
  154. PASSWORD: { min: 6, max: 255 }, // Length
  155. VIDEO_QUOTA: { min: -1 },
  156. VIDEO_QUOTA_DAILY: { min: -1 },
  157. VIDEO_LANGUAGES: { max: 500 }, // Array length
  158. BLOCKED_REASON: { min: 3, max: 250 } // Length
  159. },
  160. VIDEO_ABUSES: {
  161. REASON: { min: 2, max: 3000 }, // Length
  162. MODERATION_COMMENT: { min: 2, max: 3000 } // Length
  163. },
  164. VIDEO_BLACKLIST: {
  165. REASON: { min: 2, max: 300 } // Length
  166. },
  167. VIDEO_CHANNELS: {
  168. NAME: { min: 1, max: 120 }, // Length
  169. DESCRIPTION: { min: 3, max: 1000 }, // Length
  170. SUPPORT: { min: 3, max: 1000 }, // Length
  171. URL: { min: 3, max: 2000 } // Length
  172. },
  173. VIDEO_CAPTIONS: {
  174. CAPTION_FILE: {
  175. EXTNAME: [ '.vtt', '.srt' ],
  176. FILE_SIZE: {
  177. max: 2 * 1024 * 1024 // 2MB
  178. }
  179. }
  180. },
  181. VIDEO_IMPORTS: {
  182. URL: { min: 3, max: 2000 }, // Length
  183. TORRENT_NAME: { min: 3, max: 255 }, // Length
  184. TORRENT_FILE: {
  185. EXTNAME: [ '.torrent' ],
  186. FILE_SIZE: {
  187. max: 1024 * 200 // 200 KB
  188. }
  189. }
  190. },
  191. VIDEOS_REDUNDANCY: {
  192. URL: { min: 3, max: 2000 } // Length
  193. },
  194. VIDEO_RATES: {
  195. URL: { min: 3, max: 2000 } // Length
  196. },
  197. VIDEOS: {
  198. NAME: { min: 3, max: 120 }, // Length
  199. LANGUAGE: { min: 1, max: 10 }, // Length
  200. TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
  201. DESCRIPTION: { min: 3, max: 10000 }, // Length
  202. SUPPORT: { min: 3, max: 1000 }, // Length
  203. IMAGE: {
  204. EXTNAME: [ '.jpg', '.jpeg' ],
  205. FILE_SIZE: {
  206. max: 2 * 1024 * 1024 // 2MB
  207. }
  208. },
  209. EXTNAME: [] as string[],
  210. INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
  211. DURATION: { min: 0 }, // Number
  212. TAGS: { min: 0, max: 5 }, // Number of total tags
  213. TAG: { min: 2, max: 30 }, // Length
  214. THUMBNAIL: { min: 2, max: 30 },
  215. THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
  216. VIEWS: { min: 0 },
  217. LIKES: { min: 0 },
  218. DISLIKES: { min: 0 },
  219. FILE_SIZE: { min: 10 },
  220. URL: { min: 3, max: 2000 } // Length
  221. },
  222. VIDEO_PLAYLISTS: {
  223. NAME: { min: 1, max: 120 }, // Length
  224. DESCRIPTION: { min: 3, max: 1000 }, // Length
  225. URL: { min: 3, max: 2000 }, // Length
  226. IMAGE: {
  227. EXTNAME: [ '.jpg', '.jpeg' ],
  228. FILE_SIZE: {
  229. max: 2 * 1024 * 1024 // 2MB
  230. }
  231. }
  232. },
  233. ACTORS: {
  234. PUBLIC_KEY: { min: 10, max: 5000 }, // Length
  235. PRIVATE_KEY: { min: 10, max: 5000 }, // Length
  236. URL: { min: 3, max: 2000 }, // Length
  237. AVATAR: {
  238. EXTNAME: [ '.png', '.jpeg', '.jpg' ],
  239. FILE_SIZE: {
  240. max: 2 * 1024 * 1024 // 2MB
  241. }
  242. }
  243. },
  244. VIDEO_EVENTS: {
  245. COUNT: { min: 0 }
  246. },
  247. VIDEO_COMMENTS: {
  248. TEXT: { min: 1, max: 3000 }, // Length
  249. URL: { min: 3, max: 2000 } // Length
  250. },
  251. VIDEO_SHARE: {
  252. URL: { min: 3, max: 2000 } // Length
  253. },
  254. CONTACT_FORM: {
  255. FROM_NAME: { min: 1, max: 120 }, // Length
  256. BODY: { min: 3, max: 5000 } // Length
  257. }
  258. }
  259. const RATES_LIMIT = {
  260. LOGIN: {
  261. WINDOW_MS: CONFIG.RATES_LIMIT.LOGIN.WINDOW_MS,
  262. MAX: CONFIG.RATES_LIMIT.LOGIN.MAX
  263. },
  264. ASK_SEND_EMAIL: {
  265. WINDOW_MS: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.WINDOW_MS,
  266. MAX: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.MAX
  267. }
  268. }
  269. let VIDEO_VIEW_LIFETIME = 60000 * 60 // 1 hour
  270. let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
  271. const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
  272. MIN: 10,
  273. AVERAGE: 30,
  274. MAX: 60,
  275. KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
  276. }
  277. const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P
  278. const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
  279. LIKE: 'like',
  280. DISLIKE: 'dislike'
  281. }
  282. const FFMPEG_NICE: { [ id: string ]: number } = {
  283. THUMBNAIL: 2, // 2 just for don't blocking servers
  284. TRANSCODING: 15
  285. }
  286. const VIDEO_CATEGORIES = {
  287. 1: 'Music',
  288. 2: 'Films',
  289. 3: 'Vehicles',
  290. 4: 'Art',
  291. 5: 'Sports',
  292. 6: 'Travels',
  293. 7: 'Gaming',
  294. 8: 'People',
  295. 9: 'Comedy',
  296. 10: 'Entertainment',
  297. 11: 'News & Politics',
  298. 12: 'How To',
  299. 13: 'Education',
  300. 14: 'Activism',
  301. 15: 'Science & Technology',
  302. 16: 'Animals',
  303. 17: 'Kids',
  304. 18: 'Food'
  305. }
  306. // See https://creativecommons.org/licenses/?lang=en
  307. const VIDEO_LICENCES = {
  308. 1: 'Attribution',
  309. 2: 'Attribution - Share Alike',
  310. 3: 'Attribution - No Derivatives',
  311. 4: 'Attribution - Non Commercial',
  312. 5: 'Attribution - Non Commercial - Share Alike',
  313. 6: 'Attribution - Non Commercial - No Derivatives',
  314. 7: 'Public Domain Dedication'
  315. }
  316. let VIDEO_LANGUAGES: { [id: string]: string } = {}
  317. const VIDEO_PRIVACIES = {
  318. [ VideoPrivacy.PUBLIC ]: 'Public',
  319. [ VideoPrivacy.UNLISTED ]: 'Unlisted',
  320. [ VideoPrivacy.PRIVATE ]: 'Private'
  321. }
  322. const VIDEO_STATES = {
  323. [ VideoState.PUBLISHED ]: 'Published',
  324. [ VideoState.TO_TRANSCODE ]: 'To transcode',
  325. [ VideoState.TO_IMPORT ]: 'To import'
  326. }
  327. const VIDEO_IMPORT_STATES = {
  328. [ VideoImportState.FAILED ]: 'Failed',
  329. [ VideoImportState.PENDING ]: 'Pending',
  330. [ VideoImportState.SUCCESS ]: 'Success'
  331. }
  332. const VIDEO_ABUSE_STATES = {
  333. [ VideoAbuseState.PENDING ]: 'Pending',
  334. [ VideoAbuseState.REJECTED ]: 'Rejected',
  335. [ VideoAbuseState.ACCEPTED ]: 'Accepted'
  336. }
  337. const VIDEO_PLAYLIST_PRIVACIES = {
  338. [ VideoPlaylistPrivacy.PUBLIC ]: 'Public',
  339. [ VideoPlaylistPrivacy.UNLISTED ]: 'Unlisted',
  340. [ VideoPlaylistPrivacy.PRIVATE ]: 'Private'
  341. }
  342. const VIDEO_PLAYLIST_TYPES = {
  343. [ VideoPlaylistType.REGULAR ]: 'Regular',
  344. [ VideoPlaylistType.WATCH_LATER ]: 'Watch later'
  345. }
  346. const MIMETYPES = {
  347. AUDIO: {
  348. MIMETYPE_EXT: {
  349. 'audio/mpeg': '.mp3',
  350. 'audio/mp3': '.mp3',
  351. 'application/ogg': '.ogg',
  352. 'audio/ogg': '.ogg',
  353. 'audio/flac': '.flac'
  354. },
  355. EXT_MIMETYPE: null as { [ id: string ]: string }
  356. },
  357. VIDEO: {
  358. MIMETYPE_EXT: null as { [ id: string ]: string },
  359. EXT_MIMETYPE: null as { [ id: string ]: string }
  360. },
  361. IMAGE: {
  362. MIMETYPE_EXT: {
  363. 'image/png': '.png',
  364. 'image/jpg': '.jpg',
  365. 'image/jpeg': '.jpg'
  366. }
  367. },
  368. VIDEO_CAPTIONS: {
  369. MIMETYPE_EXT: {
  370. 'text/vtt': '.vtt',
  371. 'application/x-subrip': '.srt'
  372. }
  373. },
  374. TORRENT: {
  375. MIMETYPE_EXT: {
  376. 'application/x-bittorrent': '.torrent'
  377. }
  378. }
  379. }
  380. MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)
  381. // ---------------------------------------------------------------------------
  382. const OVERVIEWS = {
  383. VIDEOS: {
  384. SAMPLE_THRESHOLD: 6,
  385. SAMPLES_COUNT: 2
  386. }
  387. }
  388. // ---------------------------------------------------------------------------
  389. const SERVER_ACTOR_NAME = 'peertube'
  390. const ACTIVITY_PUB = {
  391. POTENTIAL_ACCEPT_HEADERS: [
  392. 'application/activity+json',
  393. 'application/ld+json',
  394. 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
  395. ],
  396. ACCEPT_HEADER: 'application/activity+json, application/ld+json',
  397. PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
  398. COLLECTION_ITEMS_PER_PAGE: 10,
  399. FETCH_PAGE_LIMIT: 100,
  400. URL_MIME_TYPES: {
  401. VIDEO: [] as string[],
  402. TORRENT: [ 'application/x-bittorrent' ],
  403. MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
  404. },
  405. MAX_RECURSION_COMMENTS: 100,
  406. ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
  407. VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
  408. VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days
  409. }
  410. const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
  411. GROUP: 'Group',
  412. PERSON: 'Person',
  413. APPLICATION: 'Application'
  414. }
  415. const HTTP_SIGNATURE = {
  416. HEADER_NAME: 'signature',
  417. ALGORITHM: 'rsa-sha256',
  418. HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ]
  419. }
  420. // ---------------------------------------------------------------------------
  421. let PRIVATE_RSA_KEY_SIZE = 2048
  422. // Password encryption
  423. const BCRYPT_SALT_SIZE = 10
  424. const USER_PASSWORD_RESET_LIFETIME = 60000 * 5 // 5 minutes
  425. const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
  426. const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = {
  427. DO_NOT_LIST: 'do_not_list',
  428. BLUR: 'blur',
  429. DISPLAY: 'display'
  430. }
  431. // ---------------------------------------------------------------------------
  432. // Express static paths (router)
  433. const STATIC_PATHS = {
  434. PREVIEWS: '/static/previews/',
  435. THUMBNAILS: '/static/thumbnails/',
  436. TORRENTS: '/static/torrents/',
  437. WEBSEED: '/static/webseed/',
  438. REDUNDANCY: '/static/redundancy/',
  439. STREAMING_PLAYLISTS: {
  440. HLS: '/static/streaming-playlists/hls'
  441. },
  442. AVATARS: '/static/avatars/',
  443. VIDEO_CAPTIONS: '/static/video-captions/'
  444. }
  445. const STATIC_DOWNLOAD_PATHS = {
  446. TORRENTS: '/download/torrents/',
  447. VIDEOS: '/download/videos/'
  448. }
  449. // Cache control
  450. let STATIC_MAX_AGE = '2h'
  451. // Videos thumbnail size
  452. const THUMBNAILS_SIZE = {
  453. width: 223,
  454. height: 122
  455. }
  456. const PREVIEWS_SIZE = {
  457. width: 850,
  458. height: 480
  459. }
  460. const AVATARS_SIZE = {
  461. width: 120,
  462. height: 120
  463. }
  464. const EMBED_SIZE = {
  465. width: 560,
  466. height: 315
  467. }
  468. // Sub folders of cache directory
  469. const FILES_CACHE = {
  470. PREVIEWS: {
  471. DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'),
  472. MAX_AGE: 1000 * 3600 * 3 // 3 hours
  473. },
  474. VIDEO_CAPTIONS: {
  475. DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
  476. MAX_AGE: 1000 * 3600 * 3 // 3 hours
  477. }
  478. }
  479. const CACHE = {
  480. USER_TOKENS: {
  481. MAX_SIZE: 10000
  482. }
  483. }
  484. const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls')
  485. const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
  486. const MEMOIZE_TTL = {
  487. OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours
  488. }
  489. const REDUNDANCY = {
  490. VIDEOS: {
  491. RANDOMIZED_FACTOR: 5
  492. }
  493. }
  494. const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
  495. const ASSETS_PATH = {
  496. DEFAULT_AUDIO_BACKGROUND: join(root(), 'server', 'assets', 'default-audio-background.jpg')
  497. }
  498. // ---------------------------------------------------------------------------
  499. const CUSTOM_HTML_TAG_COMMENTS = {
  500. TITLE: '<!-- title tag -->',
  501. DESCRIPTION: '<!-- description tag -->',
  502. CUSTOM_CSS: '<!-- custom css tag -->',
  503. META_TAGS: '<!-- meta tags -->'
  504. }
  505. // ---------------------------------------------------------------------------
  506. const FEEDS = {
  507. COUNT: 20
  508. }
  509. const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000
  510. // ---------------------------------------------------------------------------
  511. const TRACKER_RATE_LIMITS = {
  512. INTERVAL: 60000 * 5, // 5 minutes
  513. ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
  514. ANNOUNCES_PER_IP: 30 // maximum announces for all our torrents in the interval
  515. }
  516. const P2P_MEDIA_LOADER_PEER_VERSION = 2
  517. // ---------------------------------------------------------------------------
  518. // Special constants for a test instance
  519. if (isTestInstance() === true) {
  520. PRIVATE_RSA_KEY_SIZE = 1024
  521. ACTOR_FOLLOW_SCORE.BASE = 20
  522. REMOTE_SCHEME.HTTP = 'http'
  523. REMOTE_SCHEME.WS = 'ws'
  524. STATIC_MAX_AGE = '0'
  525. ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
  526. ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
  527. ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
  528. ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
  529. CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB
  530. SCHEDULER_INTERVALS_MS.actorFollowScores = 1000
  531. SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
  532. SCHEDULER_INTERVALS_MS.removeOldHistory = 5000
  533. SCHEDULER_INTERVALS_MS.removeOldViews = 5000
  534. SCHEDULER_INTERVALS_MS.updateVideos = 5000
  535. REPEAT_JOBS[ 'videos-views' ] = { every: 5000 }
  536. REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
  537. VIDEO_VIEW_LIFETIME = 1000 // 1 second
  538. CONTACT_FORM_LIFETIME = 1000 // 1 second
  539. JOB_ATTEMPTS[ 'email' ] = 1
  540. FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
  541. MEMOIZE_TTL.OVERVIEWS_SAMPLE = 1
  542. ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS = '0ms'
  543. RATES_LIMIT.LOGIN.MAX = 20
  544. }
  545. updateWebserverUrls()
  546. updateWebserverConfig()
  547. registerConfigChangedHandler(() => {
  548. updateWebserverUrls()
  549. updateWebserverConfig()
  550. })
  551. // ---------------------------------------------------------------------------
  552. export {
  553. WEBSERVER,
  554. API_VERSION,
  555. HLS_REDUNDANCY_DIRECTORY,
  556. P2P_MEDIA_LOADER_PEER_VERSION,
  557. AVATARS_SIZE,
  558. ACCEPT_HEADERS,
  559. BCRYPT_SALT_SIZE,
  560. TRACKER_RATE_LIMITS,
  561. FILES_CACHE,
  562. CONSTRAINTS_FIELDS,
  563. EMBED_SIZE,
  564. REDUNDANCY,
  565. JOB_CONCURRENCY,
  566. JOB_ATTEMPTS,
  567. LAST_MIGRATION_VERSION,
  568. OAUTH_LIFETIME,
  569. CUSTOM_HTML_TAG_COMMENTS,
  570. BROADCAST_CONCURRENCY,
  571. PAGINATION,
  572. ACTOR_FOLLOW_SCORE,
  573. PREVIEWS_SIZE,
  574. REMOTE_SCHEME,
  575. FOLLOW_STATES,
  576. SERVER_ACTOR_NAME,
  577. PRIVATE_RSA_KEY_SIZE,
  578. ROUTE_CACHE_LIFETIME,
  579. SORTABLE_COLUMNS,
  580. HLS_STREAMING_PLAYLIST_DIRECTORY,
  581. FEEDS,
  582. JOB_TTL,
  583. NSFW_POLICY_TYPES,
  584. STATIC_MAX_AGE,
  585. STATIC_PATHS,
  586. VIDEO_IMPORT_TIMEOUT,
  587. VIDEO_PLAYLIST_TYPES,
  588. MAX_LOGS_OUTPUT_CHARACTERS,
  589. ACTIVITY_PUB,
  590. ACTIVITY_PUB_ACTOR_TYPES,
  591. THUMBNAILS_SIZE,
  592. VIDEO_CATEGORIES,
  593. VIDEO_LANGUAGES,
  594. VIDEO_PRIVACIES,
  595. VIDEO_LICENCES,
  596. VIDEO_STATES,
  597. VIDEO_RATE_TYPES,
  598. VIDEO_TRANSCODING_FPS,
  599. FFMPEG_NICE,
  600. VIDEO_ABUSE_STATES,
  601. CACHE,
  602. JOB_REQUEST_TIMEOUT,
  603. USER_PASSWORD_RESET_LIFETIME,
  604. MEMOIZE_TTL,
  605. USER_EMAIL_VERIFY_LIFETIME,
  606. OVERVIEWS,
  607. SCHEDULER_INTERVALS_MS,
  608. REPEAT_JOBS,
  609. STATIC_DOWNLOAD_PATHS,
  610. RATES_LIMIT,
  611. MIMETYPES,
  612. CRAWL_REQUEST_CONCURRENCY,
  613. DEFAULT_AUDIO_RESOLUTION,
  614. JOB_COMPLETED_LIFETIME,
  615. HTTP_SIGNATURE,
  616. VIDEO_IMPORT_STATES,
  617. VIDEO_VIEW_LIFETIME,
  618. CONTACT_FORM_LIFETIME,
  619. VIDEO_PLAYLIST_PRIVACIES,
  620. ASSETS_PATH,
  621. loadLanguages,
  622. buildLanguages
  623. }
  624. // ---------------------------------------------------------------------------
  625. function buildVideoMimetypeExt () {
  626. const data = {
  627. 'video/webm': '.webm',
  628. 'video/ogg': '.ogv',
  629. 'video/mp4': '.mp4'
  630. }
  631. if (CONFIG.TRANSCODING.ENABLED) {
  632. if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
  633. Object.assign(data, {
  634. 'video/quicktime': '.mov',
  635. 'video/x-msvideo': '.avi',
  636. 'video/x-flv': '.flv',
  637. 'video/x-matroska': '.mkv',
  638. 'application/octet-stream': '.mkv',
  639. 'video/avi': '.avi'
  640. })
  641. }
  642. if (CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) {
  643. Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT)
  644. }
  645. }
  646. return data
  647. }
  648. function updateWebserverUrls () {
  649. WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
  650. WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
  651. WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME
  652. WEBSERVER.WS = CONFIG.WEBSERVER.WS
  653. WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME
  654. WEBSERVER.PORT = CONFIG.WEBSERVER.PORT
  655. }
  656. function updateWebserverConfig () {
  657. MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
  658. MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT)
  659. ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
  660. CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = buildVideosExtname()
  661. }
  662. function buildVideosExtname () {
  663. return Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE)
  664. }
  665. function loadLanguages () {
  666. Object.assign(VIDEO_LANGUAGES, buildLanguages())
  667. }
  668. function buildLanguages () {
  669. const iso639 = require('iso-639-3')
  670. const languages: { [ id: string ]: string } = {}
  671. const additionalLanguages = {
  672. 'sgn': true, // Sign languages (macro language)
  673. 'ase': true, // American sign language
  674. 'sdl': true, // Arabian sign language
  675. 'bfi': true, // British sign language
  676. 'bzs': true, // Brazilian sign language
  677. 'csl': true, // Chinese sign language
  678. 'cse': true, // Czech sign language
  679. 'dsl': true, // Danish sign language
  680. 'fsl': true, // French sign language
  681. 'gsg': true, // German sign language
  682. 'pks': true, // Pakistan sign language
  683. 'jsl': true, // Japanese sign language
  684. 'sfs': true, // South African sign language
  685. 'swl': true, // Swedish sign language
  686. 'rsl': true, // Russian sign language: true
  687. 'epo': true, // Esperanto
  688. 'tlh': true, // Klingon
  689. 'jbo': true, // Lojban
  690. 'avk': true // Kotava
  691. }
  692. // Only add ISO639-1 languages and some sign languages (ISO639-3)
  693. iso639
  694. .filter(l => {
  695. return (l.iso6391 !== null && l.type === 'living') ||
  696. additionalLanguages[ l.iso6393 ] === true
  697. })
  698. .forEach(l => languages[ l.iso6391 || l.iso6393 ] = l.name)
  699. // Override Occitan label
  700. languages[ 'oc' ] = 'Occitan'
  701. languages[ 'el' ] = 'Greek'
  702. return languages
  703. }