diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-05 13:26:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-05 14:14:16 +0200 |
commit | 6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch) | |
tree | 3365a96d82bc7f00ae504a568725c8e914150cf8 /scripts | |
parent | 5fe7e898316e18369c3e1aba307b55077adc7bfb (diff) | |
download | PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.gz PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.zst PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.zip |
Move to promises
Closes https://github.com/Chocobozzz/PeerTube/issues/74
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/danger/clean/cleaner.ts | 27 | ||||
-rwxr-xr-x | scripts/reset-password.ts | 26 | ||||
-rwxr-xr-x | scripts/test.sh | 4 | ||||
-rwxr-xr-x | scripts/update-host.ts | 43 |
4 files changed, 47 insertions, 53 deletions
diff --git a/scripts/danger/clean/cleaner.ts b/scripts/danger/clean/cleaner.ts index d1dba4650..d80b8d323 100644 --- a/scripts/danger/clean/cleaner.ts +++ b/scripts/danger/clean/cleaner.ts | |||
@@ -1,25 +1,28 @@ | |||
1 | import * as eachSeries from 'async/eachSeries' | ||
2 | import * as rimraf from 'rimraf' | 1 | import * as rimraf from 'rimraf' |
2 | import * as Promise from 'bluebird' | ||
3 | 3 | ||
4 | import { CONFIG } from '../../../server/initializers/constants' | 4 | import { CONFIG } from '../../../server/initializers/constants' |
5 | import { database as db } from '../../../server/initializers/database' | 5 | import { database as db } from '../../../server/initializers/database' |
6 | 6 | ||
7 | db.init(true, function () { | 7 | db.init(true) |
8 | db.sequelize.drop().asCallback(function (err) { | 8 | .then(() => { |
9 | if (err) throw err | 9 | return db.sequelize.drop() |
10 | 10 | }) | |
11 | .then(() => { | ||
11 | console.info('Tables of %s deleted.', CONFIG.DATABASE.DBNAME) | 12 | console.info('Tables of %s deleted.', CONFIG.DATABASE.DBNAME) |
12 | 13 | ||
13 | const STORAGE = CONFIG.STORAGE | 14 | const STORAGE = CONFIG.STORAGE |
14 | eachSeries(Object.keys(STORAGE), function (storage, callbackEach) { | 15 | Promise.mapSeries(Object.keys(STORAGE), storage => { |
15 | const storageDir = STORAGE[storage] | 16 | const storageDir = STORAGE[storage] |
16 | 17 | ||
17 | rimraf(storageDir, function (err) { | 18 | return new Promise((res, rej) => { |
18 | console.info('%s deleted.', storageDir) | 19 | rimraf(storageDir, function (err) { |
19 | return callbackEach(err) | 20 | if (err) return rej(err) |
21 | |||
22 | console.info('%s deleted.', storageDir) | ||
23 | return res() | ||
24 | }) | ||
20 | }) | 25 | }) |
21 | }, function () { | ||
22 | process.exit(0) | ||
23 | }) | 26 | }) |
27 | .then(() => process.exit(0)) | ||
24 | }) | 28 | }) |
25 | }) | ||
diff --git a/scripts/reset-password.ts b/scripts/reset-password.ts index 50e11c69c..09f27bfa4 100755 --- a/scripts/reset-password.ts +++ b/scripts/reset-password.ts | |||
@@ -11,13 +11,11 @@ if (program.user === undefined) { | |||
11 | process.exit(-1) | 11 | process.exit(-1) |
12 | } | 12 | } |
13 | 13 | ||
14 | db.init(true, function () { | 14 | db.init(true) |
15 | db.User.loadByUsername(program.user, function (err, user) { | 15 | .then(() => { |
16 | if (err) { | 16 | return db.User.loadByUsername(program.user) |
17 | console.error(err) | 17 | }) |
18 | return | 18 | .then(user => { |
19 | } | ||
20 | |||
21 | if (!user) { | 19 | if (!user) { |
22 | console.error('User unknown.') | 20 | console.error('User unknown.') |
23 | return | 21 | return |
@@ -40,15 +38,9 @@ db.init(true, function () { | |||
40 | rl.on('line', function (password) { | 38 | rl.on('line', function (password) { |
41 | user.password = password | 39 | user.password = password |
42 | 40 | ||
43 | user.save().asCallback(function (err) { | 41 | user.save() |
44 | if (err) { | 42 | .then(() => console.log('User password updated.')) |
45 | console.error(err) | 43 | .catch(err => console.error(err)) |
46 | } else { | 44 | .finally(() => process.exit(0)) |
47 | console.log('User password updated.') | ||
48 | } | ||
49 | |||
50 | process.exit(0) | ||
51 | }) | ||
52 | }) | 45 | }) |
53 | }) | 46 | }) |
54 | }) | ||
diff --git a/scripts/test.sh b/scripts/test.sh index 6e8e38659..6c6312d52 100755 --- a/scripts/test.sh +++ b/scripts/test.sh | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/env sh | 1 | #!/bin/bash |
2 | 2 | ||
3 | npm run build:server | 3 | npm run build:server |
4 | 4 | ||
@@ -6,5 +6,5 @@ cd client || exit -1 | |||
6 | npm test || exit -1 | 6 | npm test || exit -1 |
7 | 7 | ||
8 | cd .. || exit -1 | 8 | cd .. || exit -1 |
9 | npm run tslint -- --type-check --project ./tsconfig.json -c ./tslint.json server.ts server/**/*.ts || exit -1 | 9 | npm run tslint -- --type-check --project ./tsconfig.json -c ./tslint.json server.ts "server/**/*.ts" || exit -1 |
10 | mocha --bail server/tests | 10 | mocha --bail server/tests |
diff --git a/scripts/update-host.ts b/scripts/update-host.ts index 0f6af0942..23e8d5ef3 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts | |||
@@ -5,33 +5,32 @@ import { CONFIG, STATIC_PATHS } from '../server/initializers/constants' | |||
5 | import { database as db } from '../server/initializers/database' | 5 | import { database as db } from '../server/initializers/database' |
6 | import { hasFriends } from '../server/lib/friends' | 6 | import { hasFriends } from '../server/lib/friends' |
7 | 7 | ||
8 | db.init(true, function () { | 8 | db.init(true) |
9 | hasFriends(function (err, itHasFriends) { | 9 | .then(() => { |
10 | if (err) throw err | 10 | return hasFriends() |
11 | 11 | }) | |
12 | .then(itHasFriends => { | ||
12 | if (itHasFriends === true) { | 13 | if (itHasFriends === true) { |
13 | console.log('Cannot update host because you have friends!') | 14 | console.log('Cannot update host because you have friends!') |
14 | process.exit(-1) | 15 | process.exit(-1) |
15 | } | 16 | } |
16 | 17 | ||
17 | console.log('Updating torrent files.') | 18 | console.log('Updating torrent files.') |
18 | db.Video.list(function (err, videos) { | 19 | return db.Video.list() |
19 | if (err) throw err | 20 | }) |
20 | 21 | .then(videos => { | |
21 | videos.forEach(function (video) { | 22 | videos.forEach(function (video) { |
22 | const torrentName = video.id + '.torrent' | 23 | const torrentName = video.id + '.torrent' |
23 | const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName | 24 | const torrentPath = CONFIG.STORAGE.TORRENTS_DIR + torrentName |
24 | const filename = video.id + video.extname | 25 | const filename = video.id + video.extname |
25 | 26 | ||
26 | const parsed = parseTorrent(readFileSync(torrentPath)) | 27 | const parsed = parseTorrent(readFileSync(torrentPath)) |
27 | parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ] | 28 | parsed.announce = [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOST + '/tracker/socket' ] |
28 | parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ] | 29 | parsed.urlList = [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + filename ] |
29 | 30 | ||
30 | const buf = parseTorrent.toTorrentFile(parsed) | 31 | const buf = parseTorrent.toTorrentFile(parsed) |
31 | writeFileSync(torrentPath, buf) | 32 | writeFileSync(torrentPath, buf) |
32 | }) | ||
33 | |||
34 | process.exit(0) | ||
35 | }) | 33 | }) |
34 | |||
35 | process.exit(0) | ||
36 | }) | 36 | }) |
37 | }) | ||