diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
commit | 69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch) | |
tree | ad199a18ec3c322460d6f9523fc383ee562554e0 /server/helpers/utils.ts | |
parent | 4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff) | |
download | PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip |
Type functions
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r-- | server/helpers/utils.ts | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index bc76cfb26..1dcbd31c4 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -1,13 +1,15 @@ | |||
1 | import * as express from 'express' | ||
2 | |||
1 | import { pseudoRandomBytes } from 'crypto' | 3 | import { pseudoRandomBytes } from 'crypto' |
2 | import { join } from 'path' | 4 | import { join } from 'path' |
3 | 5 | ||
4 | import { logger } from './logger' | 6 | import { logger } from './logger' |
5 | 7 | ||
6 | function badRequest (req, res, next) { | 8 | function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { |
7 | res.type('json').status(400).end() | 9 | res.type('json').status(400).end() |
8 | } | 10 | } |
9 | 11 | ||
10 | function generateRandomString (size, callback) { | 12 | function generateRandomString (size: number, callback: (err: Error, randomString?: string) => void) { |
11 | pseudoRandomBytes(size, function (err, raw) { | 13 | pseudoRandomBytes(size, function (err, raw) { |
12 | if (err) return callback(err) | 14 | if (err) return callback(err) |
13 | 15 | ||
@@ -15,11 +17,6 @@ function generateRandomString (size, callback) { | |||
15 | }) | 17 | }) |
16 | } | 18 | } |
17 | 19 | ||
18 | function cleanForExit (webtorrentProcess) { | ||
19 | logger.info('Gracefully exiting.') | ||
20 | process.kill(-webtorrentProcess.pid) | ||
21 | } | ||
22 | |||
23 | function createEmptyCallback () { | 20 | function createEmptyCallback () { |
24 | return function (err) { | 21 | return function (err) { |
25 | if (err) logger.error('Error in empty callback.', { error: err }) | 22 | if (err) logger.error('Error in empty callback.', { error: err }) |
@@ -27,10 +24,10 @@ function createEmptyCallback () { | |||
27 | } | 24 | } |
28 | 25 | ||
29 | function isTestInstance () { | 26 | function isTestInstance () { |
30 | return (process.env.NODE_ENV === 'test') | 27 | return process.env.NODE_ENV === 'test' |
31 | } | 28 | } |
32 | 29 | ||
33 | function getFormatedObjects (objects, objectsTotal) { | 30 | function getFormatedObjects (objects: any[], objectsTotal: number) { |
34 | const formatedObjects = [] | 31 | const formatedObjects = [] |
35 | 32 | ||
36 | objects.forEach(function (object) { | 33 | objects.forEach(function (object) { |
@@ -53,7 +50,6 @@ function root () { | |||
53 | export { | 50 | export { |
54 | badRequest, | 51 | badRequest, |
55 | createEmptyCallback, | 52 | createEmptyCallback, |
56 | cleanForExit, | ||
57 | generateRandomString, | 53 | generateRandomString, |
58 | isTestInstance, | 54 | isTestInstance, |
59 | getFormatedObjects, | 55 | getFormatedObjects, |