diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-16 14:52:24 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | e0ce715a1ded6e84c877004dae3e354c8716fb06 (patch) | |
tree | c2a48af098e27fea2c2c6bb47b2daa68103c1a0e /server/helpers | |
parent | 89c344dba4ae2fca39cf636c3c6f09f31a339493 (diff) | |
download | PeerTube-e0ce715a1ded6e84c877004dae3e354c8716fb06.tar.gz PeerTube-e0ce715a1ded6e84c877004dae3e354c8716fb06.tar.zst PeerTube-e0ce715a1ded6e84c877004dae3e354c8716fb06.zip |
Check latest plugins version
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/requests.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 2e30c94a1..80476d649 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -1,18 +1,22 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { createWriteStream, remove } from 'fs-extra' | 2 | import { createWriteStream, remove } from 'fs-extra' |
3 | import * as request from 'request' | 3 | import * as request from 'request' |
4 | import { ACTIVITY_PUB } from '../initializers/constants' | 4 | import { ACTIVITY_PUB, WEBSERVER } from '../initializers/constants' |
5 | import { processImage } from './image-utils' | 5 | import { processImage } from './image-utils' |
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { logger } from './logger' | 7 | import { logger } from './logger' |
8 | import { CONFIG } from '../initializers/config' | 8 | import { CONFIG } from '../initializers/config' |
9 | 9 | ||
10 | const packageJSON = require('../../../package.json') | ||
11 | |||
10 | function doRequest <T> ( | 12 | function doRequest <T> ( |
11 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }, | 13 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }, |
12 | bodyKBLimit = 1000 // 1MB | 14 | bodyKBLimit = 1000 // 1MB |
13 | ): Bluebird<{ response: request.RequestResponse, body: T }> { | 15 | ): Bluebird<{ response: request.RequestResponse, body: T }> { |
16 | if (!(requestOptions.headers)) requestOptions.headers = {} | ||
17 | requestOptions.headers['User-Agent'] = getUserAgent() | ||
18 | |||
14 | if (requestOptions.activityPub === true) { | 19 | if (requestOptions.activityPub === true) { |
15 | if (!Array.isArray(requestOptions.headers)) requestOptions.headers = {} | ||
16 | requestOptions.headers['accept'] = ACTIVITY_PUB.ACCEPT_HEADER | 20 | requestOptions.headers['accept'] = ACTIVITY_PUB.ACCEPT_HEADER |
17 | } | 21 | } |
18 | 22 | ||
@@ -27,6 +31,9 @@ function doRequestAndSaveToFile ( | |||
27 | destPath: string, | 31 | destPath: string, |
28 | bodyKBLimit = 10000 // 10MB | 32 | bodyKBLimit = 10000 // 10MB |
29 | ) { | 33 | ) { |
34 | if (!requestOptions.headers) requestOptions.headers = {} | ||
35 | requestOptions.headers['User-Agent'] = getUserAgent() | ||
36 | |||
30 | return new Bluebird<void>((res, rej) => { | 37 | return new Bluebird<void>((res, rej) => { |
31 | const file = createWriteStream(destPath) | 38 | const file = createWriteStream(destPath) |
32 | file.on('finish', () => res()) | 39 | file.on('finish', () => res()) |
@@ -60,6 +67,10 @@ async function downloadImage (url: string, destDir: string, destName: string, si | |||
60 | } | 67 | } |
61 | } | 68 | } |
62 | 69 | ||
70 | function getUserAgent () { | ||
71 | return `PeerTube/${packageJSON.version} (+${WEBSERVER.URL})` | ||
72 | } | ||
73 | |||
63 | // --------------------------------------------------------------------------- | 74 | // --------------------------------------------------------------------------- |
64 | 75 | ||
65 | export { | 76 | export { |