aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--package.json7
-rwxr-xr-xscripts/check.ts (renamed from scripts/check.js)33
-rwxr-xr-xscripts/reset-password.ts (renamed from scripts/reset-password.js)8
-rwxr-xr-xscripts/update-host.js42
-rwxr-xr-xscripts/update-host.ts37
-rw-r--r--server/models/video-interface.ts2
-rw-r--r--yarn.lock6
7 files changed, 65 insertions, 70 deletions
diff --git a/package.json b/package.json
index 83ea17638..095d380bf 100644
--- a/package.json
+++ b/package.json
@@ -28,14 +28,14 @@
28 "danger:clean:dev": "scripty", 28 "danger:clean:dev": "scripty",
29 "danger:clean:prod": "scripty", 29 "danger:clean:prod": "scripty",
30 "danger:clean:modules": "scripty", 30 "danger:clean:modules": "scripty",
31 "reset-password": "scripty", 31 "reset-password": "ts-node ./scripts/reset-password.ts",
32 "play": "scripty", 32 "play": "scripty",
33 "dev:server": "scripty", 33 "dev:server": "scripty",
34 "dev:client": "scripty", 34 "dev:client": "scripty",
35 "start": "node dist/server", 35 "start": "node dist/server",
36 "check": "scripty", 36 "check": "ts-node ./scripts/check.ts",
37 "upgrade": "scripty", 37 "upgrade": "scripty",
38 "update-host": "scripty", 38 "update-host": "ts-node ./scripts/update-host.ts",
39 "test": "scripty", 39 "test": "scripty",
40 "help": "scripty", 40 "help": "scripty",
41 "postinstall": "cd client && yarn install", 41 "postinstall": "cd client && yarn install",
@@ -85,6 +85,7 @@
85 "@types/async": "^2.0.40", 85 "@types/async": "^2.0.40",
86 "@types/bcrypt": "^1.0.0", 86 "@types/bcrypt": "^1.0.0",
87 "@types/body-parser": "^1.16.3", 87 "@types/body-parser": "^1.16.3",
88 "@types/commander": "^2.9.1",
88 "@types/config": "^0.0.32", 89 "@types/config": "^0.0.32",
89 "@types/express": "^4.0.35", 90 "@types/express": "^4.0.35",
90 "@types/lodash": "^4.14.64", 91 "@types/lodash": "^4.14.64",
diff --git a/scripts/check.js b/scripts/check.ts
index 3ccfbb3b2..28167482c 100755
--- a/scripts/check.js
+++ b/scripts/check.ts
@@ -1,12 +1,9 @@
1#!/usr/bin/env node 1import * as series from 'async/series'
2import * as request from 'request'
3import * as WebSocket from 'ws'
2 4
3'use strict' 5import { CONFIG } from '../server/initializers/constants'
4 6
5const series = require('async/series')
6const request = require('request')
7const WebSocket = require('ws')
8
9const constants = require('../server/initializers/constants')
10const requestHeaders = { 7const requestHeaders = {
11 'Range': '', 8 'Range': '',
12 'Keep-Alive': '', 9 'Keep-Alive': '',
@@ -29,8 +26,8 @@ series([
29 26
30// --------------------------------------------------------------------------- 27// ---------------------------------------------------------------------------
31 28
32function pingServer (callback) { 29function pingServer (callback: () => void) {
33 const pingUrl = constants.CONFIG.WEBSERVER.URL + '/api/v1/ping' 30 const pingUrl = CONFIG.WEBSERVER.URL + '/api/v1/ping'
34 console.log('Checking server is up (%s)...', pingUrl) 31 console.log('Checking server is up (%s)...', pingUrl)
35 32
36 request(pingUrl, function (err, res, body) { 33 request(pingUrl, function (err, res, body) {
@@ -44,8 +41,8 @@ function pingServer (callback) {
44 }) 41 })
45} 42}
46 43
47function checkCORSTorrent (callback) { 44function checkCORSTorrent (callback: () => void) {
48 const torrentUrl = constants.CONFIG.WEBSERVER.URL + '/static/torrents/test.torrent' 45 const torrentUrl = CONFIG.WEBSERVER.URL + '/static/torrents/test.torrent'
49 console.log('Checking CORS headers for the torrent (%s)...', torrentUrl) 46 console.log('Checking CORS headers for the torrent (%s)...', torrentUrl)
50 47
51 request({ 48 request({
@@ -63,8 +60,8 @@ function checkCORSTorrent (callback) {
63 }) 60 })
64} 61}
65 62
66function checkCORSWebSeed (callback) { 63function checkCORSWebSeed (callback: () => void) {
67 const webseedUrl = constants.CONFIG.WEBSERVER.URL + '/static/webseed/test.mp4' 64 const webseedUrl = CONFIG.WEBSERVER.URL + '/static/webseed/test.mp4'
68 console.log('Checking CORS headers for the video (%s)...', webseedUrl) 65 console.log('Checking CORS headers for the video (%s)...', webseedUrl)
69 66
70 request({ 67 request({
@@ -82,9 +79,9 @@ function checkCORSWebSeed (callback) {
82 }) 79 })
83} 80}
84 81
85function checkTracker (callback) { 82function checkTracker (callback: () => void) {
86 const trackerUrl = constants.CONFIG.WEBSERVER.WS + '://' + 83 const trackerUrl = CONFIG.WEBSERVER.WS + '://' +
87 constants.CONFIG.WEBSERVER.HOST + 84 CONFIG.WEBSERVER.HOST +
88 '/tracker/socket' 85 '/tracker/socket'
89 console.log('Checking tracker websocket (%s)...', trackerUrl) 86 console.log('Checking tracker websocket (%s)...', trackerUrl)
90 87
@@ -111,7 +108,7 @@ function checkTracker (callback) {
111 } 108 }
112} 109}
113 110
114function isThereValidCORSHeaders (res) { 111function isThereValidCORSHeaders (res: request.RequestResponse) {
115 let fail = false 112 let fail = false
116 113
117 // Check Access-Control-Allow-Origin 114 // Check Access-Control-Allow-Origin
@@ -160,7 +157,7 @@ function isThereValidCORSHeaders (res) {
160 return !fail 157 return !fail
161} 158}
162 159
163function findPatternNotInString (stringChain, patterns) { 160function findPatternNotInString (stringChain: string, patterns: string[]) {
164 let res = null 161 let res = null
165 const stringChainLowerCase = stringChain.toLowerCase() 162 const stringChainLowerCase = stringChain.toLowerCase()
166 163
diff --git a/scripts/reset-password.js b/scripts/reset-password.ts
index 49a481a18..50e11c69c 100755
--- a/scripts/reset-password.js
+++ b/scripts/reset-password.ts
@@ -1,10 +1,6 @@
1#!/usr/bin/env node 1import * as program from 'commander'
2 2
3'use strict' 3import { database as db } from '../server/initializers/database'
4
5const program = require('commander')
6
7const db = require('../server/initializers/database')
8 4
9program 5program
10 .option('-u, --user [user]', 'User') 6 .option('-u, --user [user]', 'User')
diff --git a/scripts/update-host.js b/scripts/update-host.js
deleted file mode 100755
index 8ae0f0d0e..000000000
--- a/scripts/update-host.js
+++ /dev/null
@@ -1,42 +0,0 @@
1#!/usr/bin/env node
2
3'use strict'
4
5const fs = require('fs')
6const parseTorrent = require('parse-torrent')
7
8const constants = require('../server/initializers/constants')
9const db = require('../server/initializers/database')
10
11const friends = require('../server/lib/friends')
12
13db.init(true, function () {
14 friends.hasFriends(function (err, hasFriends) {
15 if (err) throw err
16
17 if (hasFriends === true) {
18 console.log('Cannot update host because you have friends!')
19 process.exit(-1)
20 }
21
22 console.log('Updating torrent files.')
23 db.Video.list(function (err, videos) {
24 if (err) throw err
25
26 videos.forEach(function (video) {
27 const torrentName = video.id + '.torrent'
28 const torrentPath = constants.CONFIG.STORAGE.TORRENTS_DIR + torrentName
29 const filename = video.id + video.extname
30
31 const parsed = parseTorrent(fs.readFileSync(torrentPath))
32 parsed.announce = [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
33 parsed.urlList = [ constants.CONFIG.WEBSERVER.URL + constants.STATIC_PATHS.WEBSEED + filename ]
34
35 const buf = parseTorrent.toTorrentFile(parsed)
36 fs.writeFileSync(torrentPath, buf)
37 })
38
39 process.exit(0)
40 })
41 })
42})
diff --git a/scripts/update-host.ts b/scripts/update-host.ts
new file mode 100755
index 000000000..0f6af0942
--- /dev/null
+++ b/scripts/update-host.ts
@@ -0,0 +1,37 @@
1import { readFileSync, writeFileSync } from 'fs'
2import * as parseTorrent from 'parse-torrent'
3
4import { CONFIG, STATIC_PATHS } from '../server/initializers/constants'
5import { database as db } from '../server/initializers/database'
6import { hasFriends } from '../server/lib/friends'
7
8db.init(true, function () {
9 hasFriends(function (err, itHasFriends) {
10 if (err) throw err
11
12 if (itHasFriends === true) {
13 console.log('Cannot update host because you have friends!')
14 process.exit(-1)
15 }
16
17 console.log('Updating torrent files.')
18 db.Video.list(function (err, videos) {
19 if (err) throw err
20
21 videos.forEach(function (video) {
22 const torrentName = video.id + '.torrent'
23 const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName
24 const filename = video.id + video.extname
25
26 const parsed = parseTorrent(readFileSync(torrentPath))
27 parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ]
28 parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ]
29
30 const buf = parseTorrent.toTorrentFile(parsed)
31 writeFileSync(torrentPath, buf)
32 })
33
34 process.exit(0)
35 })
36 })
37})
diff --git a/server/models/video-interface.ts b/server/models/video-interface.ts
index 7005f213c..7120f91cd 100644
--- a/server/models/video-interface.ts
+++ b/server/models/video-interface.ts
@@ -70,7 +70,7 @@ export namespace VideoMethods {
70 export type GetDurationFromFileCallback = (err: Error, duration?: number) => void 70 export type GetDurationFromFileCallback = (err: Error, duration?: number) => void
71 export type GetDurationFromFile = (videoPath, callback) => void 71 export type GetDurationFromFile = (videoPath, callback) => void
72 72
73 export type ListCallback = () => void 73 export type ListCallback = (err: Error, videoInstances: VideoInstance[]) => void
74 export type List = (callback: ListCallback) => void 74 export type List = (callback: ListCallback) => void
75 75
76 export type ListForApiCallback = (err: Error, videoInstances?: VideoInstance[], total?: number) => void 76 export type ListForApiCallback = (err: Error, videoInstances?: VideoInstance[], total?: number) => void
diff --git a/yarn.lock b/yarn.lock
index a4f880cc2..9c0af9d32 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -21,6 +21,12 @@
21 "@types/express" "*" 21 "@types/express" "*"
22 "@types/node" "*" 22 "@types/node" "*"
23 23
24"@types/commander@^2.9.1":
25 version "2.9.1"
26 resolved "https://registry.yarnpkg.com/@types/commander/-/commander-2.9.1.tgz#d4e464425baf4685bd49dd233be11de9c00c0784"
27 dependencies:
28 "@types/node" "*"
29
24"@types/config@^0.0.32": 30"@types/config@^0.0.32":
25 version "0.0.32" 31 version "0.0.32"
26 resolved "https://registry.yarnpkg.com/@types/config/-/config-0.0.32.tgz#c106055802d78e234e28374adc4dad460d098558" 32 resolved "https://registry.yarnpkg.com/@types/config/-/config-0.0.32.tgz#c106055802d78e234e28374adc4dad460d098558"