aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-12 21:06:32 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-12 21:06:32 +0200
commit75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615 (patch)
tree016f64d0fc6cfee533516be40d76eaca1b1f837e /scripts
parent7593a21d13baad422efedfb658d7ceda4e0a8c6b (diff)
downloadPeerTube-75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615.tar.gz
PeerTube-75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615.tar.zst
PeerTube-75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615.zip
Convert scripts to typescript
Diffstat (limited to 'scripts')
-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
4 files changed, 54 insertions, 66 deletions
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})