From fd206f0b2d7e5c8e00e2817266d90ec54f79e1da Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 17 Jan 2018 10:32:03 +0100 Subject: Add ability to update some configuration keys --- server/controllers/api/config.ts | 91 +++++++++++++++++- server/helpers/utils.ts | 2 +- server/initializers/constants.ts | 84 +++++++++++++---- server/middlewares/validators/config.ts | 32 +++++++ server/tests/api/check-params/config.ts | 152 +++++++++++++++++++++++++++++++ server/tests/api/server/config.ts | 112 ++++++++++++++++++++++- server/tests/api/videos/single-server.ts | 3 +- server/tests/utils/miscs/miscs.ts | 23 ----- server/tests/utils/requests/requests.ts | 2 +- server/tests/utils/server/config.ts | 41 ++++++++- server/tests/utils/videos/videos.ts | 5 +- 11 files changed, 496 insertions(+), 51 deletions(-) create mode 100644 server/middlewares/validators/config.ts create mode 100644 server/tests/api/check-params/config.ts (limited to 'server') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 35c89835b..f0b2c3d79 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -1,15 +1,34 @@ import * as express from 'express' +import { ServerConfig, UserRight } from '../../../shared' +import { CustomConfig } from '../../../shared/models/config/custom-config.model' +import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils' import { isSignupAllowed } from '../../helpers/utils' - -import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' -import { asyncMiddleware } from '../../middlewares' -import { ServerConfig } from '../../../shared' +import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' +import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' +import { customConfigUpdateValidator } from '../../middlewares/validators/config' +import { omit } from 'lodash' const configRouter = express.Router() configRouter.get('/', asyncMiddleware(getConfig) ) +configRouter.get('/custom', + authenticate, + ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), + asyncMiddleware(getCustomConfig) +) +configRouter.put('/custom', + authenticate, + ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), + asyncMiddleware(customConfigUpdateValidator), + asyncMiddleware(updateCustomConfig) +) +configRouter.delete('/custom', + authenticate, + ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), + asyncMiddleware(deleteCustomConfig) +) async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { const allowed = await isSignupAllowed() @@ -43,8 +62,72 @@ async function getConfig (req: express.Request, res: express.Response, next: exp return res.json(json) } +async function getCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { + const data = customConfig() + + return res.json(data).end() +} + +async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { + await unlinkPromise(CONFIG.CUSTOM_FILE) + + reloadConfig() + + const data = customConfig() + + return res.json(data).end() +} + +async function updateCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { + const toUpdate: CustomConfig = req.body + + // Need to change the videoQuota key a little bit + const toUpdateJSON = omit(toUpdate, 'videoQuota') + toUpdateJSON.user['video_quota'] = toUpdate.user.videoQuota + + await writeFilePromise(CONFIG.CUSTOM_FILE, JSON.stringify(toUpdateJSON)) + + reloadConfig() + + const data = customConfig() + return res.json(data).end() +} + // --------------------------------------------------------------------------- export { configRouter } + +// --------------------------------------------------------------------------- + +function customConfig (): CustomConfig { + return { + cache: { + previews: { + size: CONFIG.CACHE.PREVIEWS.SIZE + } + }, + signup: { + enabled: CONFIG.SIGNUP.ENABLED, + limit: CONFIG.SIGNUP.LIMIT + }, + admin: { + email: CONFIG.ADMIN.EMAIL + }, + user: { + videoQuota: CONFIG.USER.VIDEO_QUOTA + }, + transcoding: { + enabled: CONFIG.TRANSCODING.ENABLED, + threads: CONFIG.TRANSCODING.THREADS, + resolutions: { + '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ], + '360p': CONFIG.TRANSCODING.RESOLUTIONS[ '360p' ], + '480p': CONFIG.TRANSCODING.RESOLUTIONS[ '480p' ], + '720p': CONFIG.TRANSCODING.RESOLUTIONS[ '720p' ], + '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ] + } + } + } +} diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index b61d6e3fa..79c3b5858 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -104,7 +104,7 @@ function computeResolutionsToTranscode (videoFileHeight: number) { ] for (const resolution of resolutions) { - if (configResolutions[resolution.toString()] === true && videoFileHeight > resolution) { + if (configResolutions[resolution + 'p'] === true && videoFileHeight > resolution) { resolutionsEnabled.push(resolution) } } diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 759880201..7b63a9ccd 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -1,11 +1,14 @@ -import * as config from 'config' -import { join } from 'path' +import { IConfig } from 'config' +import { dirname, join } from 'path' import { JobCategory, JobState, VideoRateType } from '../../shared/models' import { ActivityPubActorType } from '../../shared/models/activitypub' import { FollowState } from '../../shared/models/actors' import { VideoPrivacy } from '../../shared/models/videos' // Do not use barrels, remain constants as independent as possible -import { buildPath, isTestInstance, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' +import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' + +// Use a variable to reload the configuration if we need +let config: IConfig = require('config') // --------------------------------------------------------------------------- @@ -82,6 +85,7 @@ let SCHEDULER_INTERVAL = 60000 * 60 // --------------------------------------------------------------------------- const CONFIG = { + CUSTOM_FILE: getLocalConfigFilePath(), LISTEN: { PORT: config.get('listen.port') }, @@ -110,29 +114,29 @@ const CONFIG = { HOST: '' }, ADMIN: { - EMAIL: config.get('admin.email') + get EMAIL () { return config.get('admin.email') } }, SIGNUP: { - ENABLED: config.get('signup.enabled'), - LIMIT: config.get('signup.limit') + get ENABLED () { return config.get('signup.enabled') }, + get LIMIT () { return config.get('signup.limit') } }, USER: { - VIDEO_QUOTA: config.get('user.video_quota') + get VIDEO_QUOTA () { return config.get('user.video_quota') } }, TRANSCODING: { - ENABLED: config.get('transcoding.enabled'), - THREADS: config.get('transcoding.threads'), + get ENABLED () { return config.get('transcoding.enabled') }, + get THREADS () { return config.get('transcoding.threads') }, RESOLUTIONS: { - '240' : config.get('transcoding.resolutions.240p'), - '360': config.get('transcoding.resolutions.360p'), - '480': config.get('transcoding.resolutions.480p'), - '720': config.get('transcoding.resolutions.720p'), - '1080': config.get('transcoding.resolutions.1080p') + get '240p' () { return config.get('transcoding.resolutions.240p') }, + get '360p' () { return config.get('transcoding.resolutions.360p') }, + get '480p' () { return config.get('transcoding.resolutions.480p') }, + get '720p' () { return config.get('transcoding.resolutions.720p') }, + get '1080p' () { return config.get('transcoding.resolutions.1080p') } } }, CACHE: { PREVIEWS: { - SIZE: config.get('cache.previews.size') + get SIZE () { return config.get('cache.previews.size') } } } } @@ -361,8 +365,7 @@ if (isTestInstance() === true) { SCHEDULER_INTERVAL = 10000 } -CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT) -CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) +updateWebserverConfig() // --------------------------------------------------------------------------- @@ -404,3 +407,50 @@ export { AVATAR_MIMETYPE_EXT, SCHEDULER_INTERVAL } + +// --------------------------------------------------------------------------- + +function getLocalConfigFilePath () { + const configSources = config.util.getConfigSources() + if (configSources.length === 0) throw new Error('Invalid config source.') + + let filename = 'local' + if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}` + if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}` + + return join(dirname(configSources[ 0 ].name), filename + '.json') +} + +function updateWebserverConfig () { + CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT) + CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) +} + +export function reloadConfig () { + + function directory () { + if (process.env.NODE_CONFIG_DIR) { + return process.env.NODE_CONFIG_DIR + } + + return join(root(), 'config') + } + + function purge () { + for (const fileName in require.cache) { + if (-1 === fileName.indexOf(directory())) { + continue + } + + delete require.cache[fileName] + } + + delete require.cache[require.resolve('config')] + } + + purge() + + config = require('config') + + updateWebserverConfig() +} diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts new file mode 100644 index 000000000..800aaf107 --- /dev/null +++ b/server/middlewares/validators/config.ts @@ -0,0 +1,32 @@ +import * as express from 'express' +import { body } from 'express-validator/check' +import { isUserVideoQuotaValid } from '../../helpers/custom-validators/users' +import { logger } from '../../helpers/logger' +import { areValidationErrors } from './utils' + +const customConfigUpdateValidator = [ + body('cache.previews.size').isInt().withMessage('Should have a valid previews size'), + body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'), + body('signup.limit').isInt().withMessage('Should have a valid signup limit'), + body('admin.email').isEmail().withMessage('Should have a valid administrator email'), + body('user.videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid video quota'), + body('transcoding.enabled').isBoolean().withMessage('Should have a valid transcoding enabled boolean'), + body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'), + body('transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'), + body('transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'), + body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), + body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), + body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), + + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) + + if (areValidationErrors(req, res)) return + + return next() + } +] + +export { + customConfigUpdateValidator +} diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts new file mode 100644 index 000000000..59a0c3049 --- /dev/null +++ b/server/tests/api/check-params/config.ts @@ -0,0 +1,152 @@ +/* tslint:disable:no-unused-expression */ + +import { omit } from 'lodash' +import 'mocha' +import { CustomConfig } from '../../../../shared/models/config/custom-config.model' + +import { + createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, + setAccessTokensToServers, userLogin +} from '../../utils' + +describe('Test config API validators', function () { + const path = '/api/v1/config/custom' + let server: ServerInfo + let userAccessToken: string + const updateParams: CustomConfig = { + cache: { + previews: { + size: 2 + } + }, + signup: { + enabled: false, + limit: 5 + }, + admin: { + email: 'superadmin1@example.com' + }, + user: { + videoQuota: 5242881 + }, + transcoding: { + enabled: true, + threads: 1, + resolutions: { + '240p': false, + '360p': true, + '480p': true, + '720p': false, + '1080p': false + } + } + } + + // --------------------------------------------------------------- + + before(async function () { + this.timeout(20000) + + await flushTests() + server = await runServer(1) + + await setAccessTokensToServers([ server ]) + + const user = { + username: 'user1', + password: 'password' + } + await createUser(server.url, server.accessToken, user.username, user.password) + userAccessToken = await userLogin(server, user) + }) + + describe('When getting the configuration', function () { + it('Should fail without token', async function () { + await makeGetRequest({ + url: server.url, + path, + statusCodeExpected: 401 + }) + }) + + it('Should fail if the user is not an administrator', async function () { + await makeGetRequest({ + url: server.url, + path, + token: userAccessToken, + statusCodeExpected: 403 + }) + }) + }) + + describe('When updating the configuration', function () { + it('Should fail without token', async function () { + await makePutBodyRequest({ + url: server.url, + path, + fields: updateParams, + statusCodeExpected: 401 + }) + }) + + it('Should fail if the user is not an administrator', async function () { + await makePutBodyRequest({ + url: server.url, + path, + fields: updateParams, + token: userAccessToken, + statusCodeExpected: 403 + }) + }) + + it('Should fail if it misses a key', async function () { + const newUpdateParams = omit(updateParams, 'admin.email') + + await makePutBodyRequest({ + url: server.url, + path, + fields: newUpdateParams, + token: server.accessToken, + statusCodeExpected: 400 + }) + }) + + it('Should success with the correct parameters', async function () { + await makePutBodyRequest({ + url: server.url, + path, + fields: updateParams, + token: server.accessToken, + statusCodeExpected: 200 + }) + }) + }) + + describe('When deleting the configuration', function () { + it('Should fail without token', async function () { + await makeDeleteRequest({ + url: server.url, + path, + statusCodeExpected: 401 + }) + }) + + it('Should fail if the user is not an administrator', async function () { + await makeDeleteRequest({ + url: server.url, + path, + token: userAccessToken, + statusCodeExpected: 403 + }) + }) + }) + + after(async function () { + killallServers([ server ]) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index e8846c8db..8c1389e7f 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -2,13 +2,14 @@ import 'mocha' import * as chai from 'chai' +import { deleteCustomConfig, killallServers, reRunServer } from '../../utils' const expect = chai.expect import { getConfig, flushTests, runServer, - registerUser + registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig } from '../../utils/index' describe('Test config', function () { @@ -19,6 +20,7 @@ describe('Test config', function () { await flushTests() server = await runServer(1) + await setAccessTokensToServers([ server ]) }) it('Should have a correct config on a server with registration enabled', async function () { @@ -43,6 +45,114 @@ describe('Test config', function () { expect(data.signup.allowed).to.be.false }) + it('Should get the customized configuration', async function () { + const res = await getCustomConfig(server.url, server.accessToken) + const data = res.body + + expect(data.cache.previews.size).to.equal(1) + expect(data.signup.enabled).to.be.true + expect(data.signup.limit).to.equal(4) + expect(data.admin.email).to.equal('admin1@example.com') + expect(data.user.videoQuota).to.equal(5242880) + expect(data.transcoding.enabled).to.be.false + expect(data.transcoding.threads).to.equal(2) + expect(data.transcoding.resolutions['240p']).to.be.true + expect(data.transcoding.resolutions['360p']).to.be.true + expect(data.transcoding.resolutions['480p']).to.be.true + expect(data.transcoding.resolutions['720p']).to.be.true + expect(data.transcoding.resolutions['1080p']).to.be.true + }) + + it('Should update the customized configuration', async function () { + const newCustomConfig = { + cache: { + previews: { + size: 2 + } + }, + signup: { + enabled: false, + limit: 5 + }, + admin: { + email: 'superadmin1@example.com' + }, + user: { + videoQuota: 5242881 + }, + transcoding: { + enabled: true, + threads: 1, + resolutions: { + '240p': false, + '360p': true, + '480p': true, + '720p': false, + '1080p': false + } + } + } + await updateCustomConfig(server.url, server.accessToken, newCustomConfig) + + const res = await getCustomConfig(server.url, server.accessToken) + const data = res.body + + expect(data.cache.previews.size).to.equal(2) + expect(data.signup.enabled).to.be.false + expect(data.signup.limit).to.equal(5) + expect(data.admin.email).to.equal('superadmin1@example.com') + expect(data.user.videoQuota).to.equal(5242881) + expect(data.transcoding.enabled).to.be.true + expect(data.transcoding.threads).to.equal(1) + expect(data.transcoding.resolutions['240p']).to.be.false + expect(data.transcoding.resolutions['360p']).to.be.true + expect(data.transcoding.resolutions['480p']).to.be.true + expect(data.transcoding.resolutions['720p']).to.be.false + expect(data.transcoding.resolutions['1080p']).to.be.false + }) + + it('Should have the configuration updated after a restart', async function () { + killallServers([ server ]) + + await reRunServer(server) + + const res = await getCustomConfig(server.url, server.accessToken) + const data = res.body + + expect(data.cache.previews.size).to.equal(2) + expect(data.signup.enabled).to.be.false + expect(data.signup.limit).to.equal(5) + expect(data.admin.email).to.equal('superadmin1@example.com') + expect(data.user.videoQuota).to.equal(5242881) + expect(data.transcoding.enabled).to.be.true + expect(data.transcoding.threads).to.equal(1) + expect(data.transcoding.resolutions['240p']).to.be.false + expect(data.transcoding.resolutions['360p']).to.be.true + expect(data.transcoding.resolutions['480p']).to.be.true + expect(data.transcoding.resolutions['720p']).to.be.false + expect(data.transcoding.resolutions['1080p']).to.be.false + }) + + it('Should remove the custom configuration', async function () { + await deleteCustomConfig(server.url, server.accessToken) + + const res = await getCustomConfig(server.url, server.accessToken) + const data = res.body + + expect(data.cache.previews.size).to.equal(1) + expect(data.signup.enabled).to.be.true + expect(data.signup.limit).to.equal(4) + expect(data.admin.email).to.equal('admin1@example.com') + expect(data.user.videoQuota).to.equal(5242880) + expect(data.transcoding.enabled).to.be.false + expect(data.transcoding.threads).to.equal(2) + expect(data.transcoding.resolutions['240p']).to.be.true + expect(data.transcoding.resolutions['360p']).to.be.true + expect(data.transcoding.resolutions['480p']).to.be.true + expect(data.transcoding.resolutions['720p']).to.be.true + expect(data.transcoding.resolutions['1080p']).to.be.true + }) + after(async function () { process.kill(-server.app.pid) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 0a0c95750..ca20f39a0 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -5,9 +5,10 @@ import { keyBy } from 'lodash' import 'mocha' import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos' +import { readdirPromise } from '../../../helpers/core-utils' import { completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies, - getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, readdirPromise, removeVideo, runServer, searchVideo, + getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, searchVideo, searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo } from '../../utils' diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts index 2c51d1f0a..2aac37791 100644 --- a/server/tests/utils/miscs/miscs.ts +++ b/server/tests/utils/miscs/miscs.ts @@ -1,5 +1,4 @@ import * as WebTorrent from 'webtorrent' -import { readFile, readdir } from 'fs' let webtorrent = new WebTorrent() @@ -7,26 +6,6 @@ function immutableAssign (target: T, source: U) { return Object.assign<{}, T, U>({}, target, source) } -function readFilePromise (path: string) { - return new Promise((res, rej) => { - readFile(path, (err, data) => { - if (err) return rej(err) - - return res(data) - }) - }) -} - -function readdirPromise (path: string) { - return new Promise((res, rej) => { - readdir(path, (err, files) => { - if (err) return rej(err) - - return res(files) - }) - }) -} - // Default interval -> 5 minutes function dateIsValid (dateString: string, interval = 300000) { const dateToCheck = new Date(dateString) @@ -48,8 +27,6 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { // --------------------------------------------------------------------------- export { - readFilePromise, - readdirPromise, dateIsValid, wait, webtorrentAdd, diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index eb02cf9e6..840072430 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts @@ -99,7 +99,7 @@ function makePostBodyRequest (options: { function makePutBodyRequest (options: { url: string, path: string, - token: string, + token?: string, fields: { [ fieldName: string ]: any }, statusCodeExpected?: number }) { diff --git a/server/tests/utils/server/config.ts b/server/tests/utils/server/config.ts index d09c19c60..b6905757a 100644 --- a/server/tests/utils/server/config.ts +++ b/server/tests/utils/server/config.ts @@ -1,4 +1,6 @@ import * as request from 'supertest' +import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../' +import { CustomConfig } from '../../../../shared/models/config/custom-config.model' function getConfig (url: string) { const path = '/api/v1/config' @@ -10,8 +12,45 @@ function getConfig (url: string) { .expect('Content-Type', /json/) } +function getCustomConfig (url: string, token: string, statusCodeExpected = 200) { + const path = '/api/v1/config/custom' + + return makeGetRequest({ + url, + token, + path, + statusCodeExpected + }) +} + +function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) { + const path = '/api/v1/config/custom' + + return makePutBodyRequest({ + url, + token, + path, + fields: newCustomConfig, + statusCodeExpected + }) +} + +function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) { + const path = '/api/v1/config/custom' + + return makeDeleteRequest({ + url, + token, + path, + statusCodeExpected + }) +} + // --------------------------------------------------------------------------- export { - getConfig + getConfig, + getCustomConfig, + updateCustomConfig, + deleteCustomConfig } diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index dc1327215..095d4e29d 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -5,8 +5,9 @@ import { readFile } from 'fs' import * as parseTorrent from 'parse-torrent' import { extname, isAbsolute, join } from 'path' import * as request from 'supertest' -import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../' +import { getMyUserInformation, makeGetRequest, ServerInfo } from '../' import { VideoPrivacy } from '../../../../shared/models/videos' +import { readFileBufferPromise } from '../../../helpers/core-utils' import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' import { dateIsValid, webtorrentAdd } from '../index' @@ -210,7 +211,7 @@ async function testVideoImage (url: string, imageName: string, imagePath: string .get(imagePath) .expect(200) - const data = await readFilePromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) + const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) return data.equals(res.body) } else { -- cgit v1.2.3