diff options
-rw-r--r-- | package.json | 7 | ||||
-rwxr-xr-x | scripts/check.ts (renamed from scripts/check.js) | 33 | ||||
-rwxr-xr-x | scripts/reset-password.ts (renamed from scripts/reset-password.js) | 8 | ||||
-rwxr-xr-x | scripts/update-host.js | 42 | ||||
-rwxr-xr-x | scripts/update-host.ts | 37 | ||||
-rw-r--r-- | server/models/video-interface.ts | 2 | ||||
-rw-r--r-- | yarn.lock | 6 |
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 | 1 | import * as series from 'async/series' |
2 | import * as request from 'request' | ||
3 | import * as WebSocket from 'ws' | ||
2 | 4 | ||
3 | 'use strict' | 5 | import { CONFIG } from '../server/initializers/constants' |
4 | 6 | ||
5 | const series = require('async/series') | ||
6 | const request = require('request') | ||
7 | const WebSocket = require('ws') | ||
8 | |||
9 | const constants = require('../server/initializers/constants') | ||
10 | const requestHeaders = { | 7 | const requestHeaders = { |
11 | 'Range': '', | 8 | 'Range': '', |
12 | 'Keep-Alive': '', | 9 | 'Keep-Alive': '', |
@@ -29,8 +26,8 @@ series([ | |||
29 | 26 | ||
30 | // --------------------------------------------------------------------------- | 27 | // --------------------------------------------------------------------------- |
31 | 28 | ||
32 | function pingServer (callback) { | 29 | function 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 | ||
47 | function checkCORSTorrent (callback) { | 44 | function 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 | ||
66 | function checkCORSWebSeed (callback) { | 63 | function 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 | ||
85 | function checkTracker (callback) { | 82 | function 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 | ||
114 | function isThereValidCORSHeaders (res) { | 111 | function 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 | ||
163 | function findPatternNotInString (stringChain, patterns) { | 160 | function 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 | 1 | import * as program from 'commander' |
2 | 2 | ||
3 | 'use strict' | 3 | import { database as db } from '../server/initializers/database' |
4 | |||
5 | const program = require('commander') | ||
6 | |||
7 | const db = require('../server/initializers/database') | ||
8 | 4 | ||
9 | program | 5 | program |
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 | |||
5 | const fs = require('fs') | ||
6 | const parseTorrent = require('parse-torrent') | ||
7 | |||
8 | const constants = require('../server/initializers/constants') | ||
9 | const db = require('../server/initializers/database') | ||
10 | |||
11 | const friends = require('../server/lib/friends') | ||
12 | |||
13 | db.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 @@ | |||
1 | import { readFileSync, writeFileSync } from 'fs' | ||
2 | import * as parseTorrent from 'parse-torrent' | ||
3 | |||
4 | import { CONFIG, STATIC_PATHS } from '../server/initializers/constants' | ||
5 | import { database as db } from '../server/initializers/database' | ||
6 | import { hasFriends } from '../server/lib/friends' | ||
7 | |||
8 | db.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 |
@@ -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" |