"danger:clean:dev": "scripty",
"danger:clean:prod": "scripty",
"danger:clean:modules": "scripty",
- "reset-password": "scripty",
+ "reset-password": "ts-node ./scripts/reset-password.ts",
"play": "scripty",
"dev:server": "scripty",
"dev:client": "scripty",
"start": "node dist/server",
- "check": "scripty",
+ "check": "ts-node ./scripts/check.ts",
"upgrade": "scripty",
- "update-host": "scripty",
+ "update-host": "ts-node ./scripts/update-host.ts",
"test": "scripty",
"help": "scripty",
"postinstall": "cd client && yarn install",
"@types/async": "^2.0.40",
"@types/bcrypt": "^1.0.0",
"@types/body-parser": "^1.16.3",
+ "@types/commander": "^2.9.1",
"@types/config": "^0.0.32",
"@types/express": "^4.0.35",
"@types/lodash": "^4.14.64",
+++ /dev/null
-#!/usr/bin/env node
-
-'use strict'
-
-const series = require('async/series')
-const request = require('request')
-const WebSocket = require('ws')
-
-const constants = require('../server/initializers/constants')
-const requestHeaders = {
- 'Range': '',
- 'Keep-Alive': '',
- 'User-Agent': 'Mozilla',
- 'Cache-Control': 'no-cache',
- 'Content-Type': '',
- 'Host': 'example.com',
- 'Access-Control-Request-Method': 'GET',
- 'Access-Control-Request-Headers': 'range'
-}
-
-series([
- pingServer,
- checkCORSTorrent,
- checkCORSWebSeed,
- checkTracker
-], function () {
- process.exit(0)
-})
-
-// ---------------------------------------------------------------------------
-
-function pingServer (callback) {
- const pingUrl = constants.CONFIG.WEBSERVER.URL + '/api/v1/ping'
- console.log('Checking server is up (%s)...', pingUrl)
-
- request(pingUrl, function (err, res, body) {
- if (!err && res.statusCode === 200 && body === 'pong') {
- console.log('SUCCESS.')
- } else {
- console.log('FAIL.')
- }
-
- callback()
- })
-}
-
-function checkCORSTorrent (callback) {
- const torrentUrl = constants.CONFIG.WEBSERVER.URL + '/static/torrents/test.torrent'
- console.log('Checking CORS headers for the torrent (%s)...', torrentUrl)
-
- request({
- method: 'OPTIONS',
- uri: torrentUrl,
- headers: requestHeaders
- }, function (err, res) {
- if (err || isThereValidCORSHeaders(res) === false) {
- console.error('FAIL.')
- } else {
- console.log('SUCCESS.')
- }
-
- callback()
- })
-}
-
-function checkCORSWebSeed (callback) {
- const webseedUrl = constants.CONFIG.WEBSERVER.URL + '/static/webseed/test.mp4'
- console.log('Checking CORS headers for the video (%s)...', webseedUrl)
-
- request({
- method: 'OPTIONS',
- uri: webseedUrl,
- headers: requestHeaders
- }, function (err, res) {
- if (err || isThereValidCORSHeaders(res) === false) {
- console.error('FAIL.')
- } else {
- console.log('SUCCESS.')
- }
-
- callback()
- })
-}
-
-function checkTracker (callback) {
- const trackerUrl = constants.CONFIG.WEBSERVER.WS + '://' +
- constants.CONFIG.WEBSERVER.HOST +
- '/tracker/socket'
- console.log('Checking tracker websocket (%s)...', trackerUrl)
-
- let ws = null
- ws = new WebSocket(trackerUrl)
-
- const timeout = setTimeout(failed, 1000)
- ws.on('open', onOpen)
-
- function onOpen () {
- clearTimeout(timeout)
- ws.close()
-
- console.log('SUCCESS.')
- callback()
- }
-
- function failed () {
- ws.removeListener('open', onOpen)
- ws.close()
-
- console.log('FAILED.')
- callback()
- }
-}
-
-function isThereValidCORSHeaders (res) {
- let fail = false
-
- // Check Access-Control-Allow-Origin
- const headerAllowOriginKey = 'access-control-allow-origin'
- const headerAllowOrigin = res.headers[headerAllowOriginKey]
-
- if (!headerAllowOrigin) {
- console.error(headerAllowOriginKey + ' is not present.')
- fail = true
- } else if (headerAllowOrigin !== '*') {
- console.error(headerAllowOriginKey + ' does not equal "*".')
- fail = true
- }
-
- // Check Access-Control-Allow-Methods
- const headerAllowMethodsKey = 'access-control-allow-methods'
- const headerAllowMethods = res.headers[headerAllowMethodsKey]
- if (!headerAllowMethods) {
- console.error(headerAllowMethodsKey + ' is not present.')
- fail = true
- } else {
- const allowMethodsMissed = findPatternNotInString(headerAllowMethods, [ 'get' ])
- if (allowMethodsMissed !== null) {
- console.error(headerAllowMethodsKey + ' misses the ' + allowMethodsMissed + ' method.')
- fail = true
- }
- }
-
- // Check Access-Control-Allow-Headers
- const headerAllowHeadersKey = 'access-control-allow-headers'
- const headerAllowHeaders = res.headers[headerAllowHeadersKey]
- if (!headerAllowHeaders) {
- console.error(headerAllowHeadersKey + ' is not present.')
- fail = true
- } else {
- const headersThatShouldBePresent = [
- 'Range'
- ]
- const allowHeadersMissed = findPatternNotInString(headerAllowHeaders, headersThatShouldBePresent)
- if (allowHeadersMissed !== null) {
- console.error(headerAllowHeadersKey + ' misses the ' + allowHeadersMissed + ' header.')
- fail = true
- }
- }
-
- return !fail
-}
-
-function findPatternNotInString (stringChain, patterns) {
- let res = null
- const stringChainLowerCase = stringChain.toLowerCase()
-
- patterns.forEach(function (pattern) {
- if (stringChainLowerCase.indexOf(pattern.toLowerCase()) === -1) {
- res = pattern
- }
- })
-
- return res
-}
--- /dev/null
+import * as series from 'async/series'
+import * as request from 'request'
+import * as WebSocket from 'ws'
+
+import { CONFIG } from '../server/initializers/constants'
+
+const requestHeaders = {
+ 'Range': '',
+ 'Keep-Alive': '',
+ 'User-Agent': 'Mozilla',
+ 'Cache-Control': 'no-cache',
+ 'Content-Type': '',
+ 'Host': 'example.com',
+ 'Access-Control-Request-Method': 'GET',
+ 'Access-Control-Request-Headers': 'range'
+}
+
+series([
+ pingServer,
+ checkCORSTorrent,
+ checkCORSWebSeed,
+ checkTracker
+], function () {
+ process.exit(0)
+})
+
+// ---------------------------------------------------------------------------
+
+function pingServer (callback: () => void) {
+ const pingUrl = CONFIG.WEBSERVER.URL + '/api/v1/ping'
+ console.log('Checking server is up (%s)...', pingUrl)
+
+ request(pingUrl, function (err, res, body) {
+ if (!err && res.statusCode === 200 && body === 'pong') {
+ console.log('SUCCESS.')
+ } else {
+ console.log('FAIL.')
+ }
+
+ callback()
+ })
+}
+
+function checkCORSTorrent (callback: () => void) {
+ const torrentUrl = CONFIG.WEBSERVER.URL + '/static/torrents/test.torrent'
+ console.log('Checking CORS headers for the torrent (%s)...', torrentUrl)
+
+ request({
+ method: 'OPTIONS',
+ uri: torrentUrl,
+ headers: requestHeaders
+ }, function (err, res) {
+ if (err || isThereValidCORSHeaders(res) === false) {
+ console.error('FAIL.')
+ } else {
+ console.log('SUCCESS.')
+ }
+
+ callback()
+ })
+}
+
+function checkCORSWebSeed (callback: () => void) {
+ const webseedUrl = CONFIG.WEBSERVER.URL + '/static/webseed/test.mp4'
+ console.log('Checking CORS headers for the video (%s)...', webseedUrl)
+
+ request({
+ method: 'OPTIONS',
+ uri: webseedUrl,
+ headers: requestHeaders
+ }, function (err, res) {
+ if (err || isThereValidCORSHeaders(res) === false) {
+ console.error('FAIL.')
+ } else {
+ console.log('SUCCESS.')
+ }
+
+ callback()
+ })
+}
+
+function checkTracker (callback: () => void) {
+ const trackerUrl = CONFIG.WEBSERVER.WS + '://' +
+ CONFIG.WEBSERVER.HOST +
+ '/tracker/socket'
+ console.log('Checking tracker websocket (%s)...', trackerUrl)
+
+ let ws = null
+ ws = new WebSocket(trackerUrl)
+
+ const timeout = setTimeout(failed, 1000)
+ ws.on('open', onOpen)
+
+ function onOpen () {
+ clearTimeout(timeout)
+ ws.close()
+
+ console.log('SUCCESS.')
+ callback()
+ }
+
+ function failed () {
+ ws.removeListener('open', onOpen)
+ ws.close()
+
+ console.log('FAILED.')
+ callback()
+ }
+}
+
+function isThereValidCORSHeaders (res: request.RequestResponse) {
+ let fail = false
+
+ // Check Access-Control-Allow-Origin
+ const headerAllowOriginKey = 'access-control-allow-origin'
+ const headerAllowOrigin = res.headers[headerAllowOriginKey]
+
+ if (!headerAllowOrigin) {
+ console.error(headerAllowOriginKey + ' is not present.')
+ fail = true
+ } else if (headerAllowOrigin !== '*') {
+ console.error(headerAllowOriginKey + ' does not equal "*".')
+ fail = true
+ }
+
+ // Check Access-Control-Allow-Methods
+ const headerAllowMethodsKey = 'access-control-allow-methods'
+ const headerAllowMethods = res.headers[headerAllowMethodsKey]
+ if (!headerAllowMethods) {
+ console.error(headerAllowMethodsKey + ' is not present.')
+ fail = true
+ } else {
+ const allowMethodsMissed = findPatternNotInString(headerAllowMethods, [ 'get' ])
+ if (allowMethodsMissed !== null) {
+ console.error(headerAllowMethodsKey + ' misses the ' + allowMethodsMissed + ' method.')
+ fail = true
+ }
+ }
+
+ // Check Access-Control-Allow-Headers
+ const headerAllowHeadersKey = 'access-control-allow-headers'
+ const headerAllowHeaders = res.headers[headerAllowHeadersKey]
+ if (!headerAllowHeaders) {
+ console.error(headerAllowHeadersKey + ' is not present.')
+ fail = true
+ } else {
+ const headersThatShouldBePresent = [
+ 'Range'
+ ]
+ const allowHeadersMissed = findPatternNotInString(headerAllowHeaders, headersThatShouldBePresent)
+ if (allowHeadersMissed !== null) {
+ console.error(headerAllowHeadersKey + ' misses the ' + allowHeadersMissed + ' header.')
+ fail = true
+ }
+ }
+
+ return !fail
+}
+
+function findPatternNotInString (stringChain: string, patterns: string[]) {
+ let res = null
+ const stringChainLowerCase = stringChain.toLowerCase()
+
+ patterns.forEach(function (pattern) {
+ if (stringChainLowerCase.indexOf(pattern.toLowerCase()) === -1) {
+ res = pattern
+ }
+ })
+
+ return res
+}
+++ /dev/null
-#!/usr/bin/env node
-
-'use strict'
-
-const program = require('commander')
-
-const db = require('../server/initializers/database')
-
-program
- .option('-u, --user [user]', 'User')
- .parse(process.argv)
-
-if (program.user === undefined) {
- console.error('All parameters are mandatory.')
- process.exit(-1)
-}
-
-db.init(true, function () {
- db.User.loadByUsername(program.user, function (err, user) {
- if (err) {
- console.error(err)
- return
- }
-
- if (!user) {
- console.error('User unknown.')
- return
- }
-
- const readline = require('readline')
- const Writable = require('stream').Writable
- const mutableStdout = new Writable({
- write: function (chunk, encoding, callback) {
- callback()
- }
- })
- const rl = readline.createInterface({
- input: process.stdin,
- output: mutableStdout,
- terminal: true
- })
-
- console.log('New password?')
- rl.on('line', function (password) {
- user.password = password
-
- user.save().asCallback(function (err) {
- if (err) {
- console.error(err)
- } else {
- console.log('User password updated.')
- }
-
- process.exit(0)
- })
- })
- })
-})
--- /dev/null
+import * as program from 'commander'
+
+import { database as db } from '../server/initializers/database'
+
+program
+ .option('-u, --user [user]', 'User')
+ .parse(process.argv)
+
+if (program.user === undefined) {
+ console.error('All parameters are mandatory.')
+ process.exit(-1)
+}
+
+db.init(true, function () {
+ db.User.loadByUsername(program.user, function (err, user) {
+ if (err) {
+ console.error(err)
+ return
+ }
+
+ if (!user) {
+ console.error('User unknown.')
+ return
+ }
+
+ const readline = require('readline')
+ const Writable = require('stream').Writable
+ const mutableStdout = new Writable({
+ write: function (chunk, encoding, callback) {
+ callback()
+ }
+ })
+ const rl = readline.createInterface({
+ input: process.stdin,
+ output: mutableStdout,
+ terminal: true
+ })
+
+ console.log('New password?')
+ rl.on('line', function (password) {
+ user.password = password
+
+ user.save().asCallback(function (err) {
+ if (err) {
+ console.error(err)
+ } else {
+ console.log('User password updated.')
+ }
+
+ process.exit(0)
+ })
+ })
+ })
+})
+++ /dev/null
-#!/usr/bin/env node
-
-'use strict'
-
-const fs = require('fs')
-const parseTorrent = require('parse-torrent')
-
-const constants = require('../server/initializers/constants')
-const db = require('../server/initializers/database')
-
-const friends = require('../server/lib/friends')
-
-db.init(true, function () {
- friends.hasFriends(function (err, hasFriends) {
- if (err) throw err
-
- if (hasFriends === true) {
- console.log('Cannot update host because you have friends!')
- process.exit(-1)
- }
-
- console.log('Updating torrent files.')
- db.Video.list(function (err, videos) {
- if (err) throw err
-
- videos.forEach(function (video) {
- const torrentName = video.id + '.torrent'
- const torrentPath = constants.CONFIG.STORAGE.TORRENTS_DIR + torrentName
- const filename = video.id + video.extname
-
- const parsed = parseTorrent(fs.readFileSync(torrentPath))
- parsed.announce = [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
- parsed.urlList = [ constants.CONFIG.WEBSERVER.URL + constants.STATIC_PATHS.WEBSEED + filename ]
-
- const buf = parseTorrent.toTorrentFile(parsed)
- fs.writeFileSync(torrentPath, buf)
- })
-
- process.exit(0)
- })
- })
-})
--- /dev/null
+import { readFileSync, writeFileSync } from 'fs'
+import * as parseTorrent from 'parse-torrent'
+
+import { CONFIG, STATIC_PATHS } from '../server/initializers/constants'
+import { database as db } from '../server/initializers/database'
+import { hasFriends } from '../server/lib/friends'
+
+db.init(true, function () {
+ hasFriends(function (err, itHasFriends) {
+ if (err) throw err
+
+ if (itHasFriends === true) {
+ console.log('Cannot update host because you have friends!')
+ process.exit(-1)
+ }
+
+ console.log('Updating torrent files.')
+ db.Video.list(function (err, videos) {
+ if (err) throw err
+
+ videos.forEach(function (video) {
+ const torrentName = video.id + '.torrent'
+ const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName
+ const filename = video.id + video.extname
+
+ const parsed = parseTorrent(readFileSync(torrentPath))
+ parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
+ parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ]
+
+ const buf = parseTorrent.toTorrentFile(parsed)
+ writeFileSync(torrentPath, buf)
+ })
+
+ process.exit(0)
+ })
+ })
+})
export type GetDurationFromFileCallback = (err: Error, duration?: number) => void
export type GetDurationFromFile = (videoPath, callback) => void
- export type ListCallback = () => void
+ export type ListCallback = (err: Error, videoInstances: VideoInstance[]) => void
export type List = (callback: ListCallback) => void
export type ListForApiCallback = (err: Error, videoInstances?: VideoInstance[], total?: number) => void
"@types/express" "*"
"@types/node" "*"
+"@types/commander@^2.9.1":
+ version "2.9.1"
+ resolved "https://registry.yarnpkg.com/@types/commander/-/commander-2.9.1.tgz#d4e464425baf4685bd49dd233be11de9c00c0784"
+ dependencies:
+ "@types/node" "*"
+
"@types/config@^0.0.32":
version "0.0.32"
resolved "https://registry.yarnpkg.com/@types/config/-/config-0.0.32.tgz#c106055802d78e234e28374adc4dad460d098558"