diff --git a/server/app.js b/server/app.js index 5095aba8..745b722c 100644 --- a/server/app.js +++ b/server/app.js @@ -1,19 +1,19 @@ -require('events').EventEmitter.defaultMaxListeners = Infinity; +import bodyParser from 'body-parser'; +import compression from 'compression'; +import cookieParser from 'cookie-parser'; +import express from 'express'; +import fs from 'fs'; +import morgan from 'morgan'; +import passport from 'passport'; +import path from 'path'; -const bodyParser = require('body-parser'); -const compression = require('compression'); -const cookieParser = require('cookie-parser'); -const express = require('express'); -const fs = require('fs'); -const morgan = require('morgan'); -const passport = require('passport'); -const path = require('path'); +import apiRoutes from './routes/api'; +import authRoutes from './routes/auth'; +import passportConfig from './config/passport'; +import paths from '../shared/config/paths'; +import Users from './models/Users'; const app = express(); -const apiRoutes = require('./routes/api'); -const authRoutes = require('./routes/auth'); -const paths = require('../shared/config/paths'); -const Users = require('./models/Users'); Users.bootstrapServicesForAllUsers(); @@ -33,7 +33,7 @@ app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: false})); app.use(cookieParser()); -require('./config/passport')(passport); +passportConfig(passport); app.use(path.join(paths.servedPath, 'api'), apiRoutes); app.use(path.join(paths.servedPath, 'auth'), authRoutes); @@ -85,4 +85,4 @@ if (app.get('env') === 'development') { }); } -module.exports = app; +export default app; diff --git a/server/bin/migrations/fix-is-admin-flag.js b/server/bin/migrations/fix-is-admin-flag.js index f559ddbe..7492280c 100644 --- a/server/bin/migrations/fix-is-admin-flag.js +++ b/server/bin/migrations/fix-is-admin-flag.js @@ -1,5 +1,5 @@ -const chalk = require('chalk'); -const Users = require('../../models/Users'); +import chalk from 'chalk'; +import Users from '../../models/Users'; const log = (data) => { if (process.env.DEBUG) { @@ -46,4 +46,4 @@ const migrate = () => { }); }; -module.exports = migrate; +export default migrate; diff --git a/server/bin/migrations/per-user-rtorrent-instances.js b/server/bin/migrations/per-user-rtorrent-instances.js index 2875e65b..1c6b6c84 100644 --- a/server/bin/migrations/per-user-rtorrent-instances.js +++ b/server/bin/migrations/per-user-rtorrent-instances.js @@ -1,6 +1,6 @@ -const chalk = require('chalk'); -const config = require('../../../config'); -const Users = require('../../models/Users'); +import chalk from 'chalk'; +import config from '../../../config'; +import Users from '../../models/Users'; const log = (data) => { if (process.env.DEBUG) { @@ -73,4 +73,4 @@ const migrate = () => { }); }; -module.exports = migrate; +export default migrate; diff --git a/server/config/passport.js b/server/config/passport.js index 09945785..f2ab617c 100644 --- a/server/config/passport.js +++ b/server/config/passport.js @@ -1,10 +1,10 @@ -const JwtStrategy = require('passport-jwt').Strategy; +import {Strategy as JwtStrategy} from 'passport-jwt'; -const config = require('../../config'); -const Users = require('../models/Users'); +import config from '../../config'; +import Users from '../models/Users'; // Setup work and export for the JWT passport strategy. -module.exports = (passport) => { +export default (passport) => { const options = { jwtFromRequest: (req) => { let token = null; diff --git a/server/constants/clientGatewayServiceEvents.js b/server/constants/clientGatewayServiceEvents.js index e76b0126..aaf672db 100644 --- a/server/constants/clientGatewayServiceEvents.js +++ b/server/constants/clientGatewayServiceEvents.js @@ -1,4 +1,4 @@ -const objectUtil = require('../../shared/util/objectUtil'); +import objectUtil from '../../shared/util/objectUtil'; const clientGatewayServiceEvents = [ 'CLIENT_CONNECTION_STATE_CHANGE', @@ -9,4 +9,4 @@ const clientGatewayServiceEvents = [ 'TORRENTS_REMOVED', ]; -module.exports = objectUtil.createSymbolMapFromArray(clientGatewayServiceEvents); +export default objectUtil.createSymbolMapFromArray(clientGatewayServiceEvents); diff --git a/server/constants/diskUsageServiceEvents.js b/server/constants/diskUsageServiceEvents.js index fe4bad17..f5830ce1 100644 --- a/server/constants/diskUsageServiceEvents.js +++ b/server/constants/diskUsageServiceEvents.js @@ -1,5 +1,5 @@ -const objectUtil = require('../../shared/util/objectUtil'); +import objectUtil from '../../shared/util/objectUtil'; const diskUsageServiceEvents = ['DISK_USAGE_CHANGE']; -module.exports = objectUtil.createSymbolMapFromArray(diskUsageServiceEvents); +export default objectUtil.createSymbolMapFromArray(diskUsageServiceEvents); diff --git a/server/constants/fileListPropMap.js b/server/constants/fileListPropMap.js index 087458df..ebb0cc62 100644 --- a/server/constants/fileListPropMap.js +++ b/server/constants/fileListPropMap.js @@ -31,4 +31,4 @@ fileListPropMap.set('completedChunks', { transformValue: Number, }); -module.exports = fileListPropMap; +export default fileListPropMap; diff --git a/server/constants/historyServiceEvents.js b/server/constants/historyServiceEvents.js index bdbff577..49ff3065 100644 --- a/server/constants/historyServiceEvents.js +++ b/server/constants/historyServiceEvents.js @@ -1,5 +1,5 @@ -const historySnapshotTypes = require('../../shared/constants/historySnapshotTypes'); -const objectUtil = require('../../shared/util/objectUtil'); +import historySnapshotTypes from '../../shared/constants/historySnapshotTypes'; +import objectUtil from '../../shared/util/objectUtil'; const torrentServiceEvents = [ 'FETCH_TRANSFER_SUMMARY_ERROR', @@ -14,4 +14,4 @@ const torrentServiceEvents = [ }, []), ); -module.exports = objectUtil.createSymbolMapFromArray(torrentServiceEvents); +export default objectUtil.createSymbolMapFromArray(torrentServiceEvents); diff --git a/server/constants/notificationServiceEvents.js b/server/constants/notificationServiceEvents.js index 33d46210..32b58841 100644 --- a/server/constants/notificationServiceEvents.js +++ b/server/constants/notificationServiceEvents.js @@ -1,5 +1,5 @@ -const objectUtil = require('../../shared/util/objectUtil'); +import objectUtil from '../../shared/util/objectUtil'; const notificationServiceEvents = ['NOTIFICATION_COUNT_CHANGE']; -module.exports = objectUtil.createSymbolMapFromArray(notificationServiceEvents); +export default objectUtil.createSymbolMapFromArray(notificationServiceEvents); diff --git a/server/constants/taxonomyServiceEvents.js b/server/constants/taxonomyServiceEvents.js index ee5431f0..0e1bb3be 100644 --- a/server/constants/taxonomyServiceEvents.js +++ b/server/constants/taxonomyServiceEvents.js @@ -1,5 +1,5 @@ -const objectUtil = require('../../shared/util/objectUtil'); +import objectUtil from '../../shared/util/objectUtil'; const taxonomyServiceEvents = ['TAXONOMY_DIFF_CHANGE']; -module.exports = objectUtil.createSymbolMapFromArray(taxonomyServiceEvents); +export default objectUtil.createSymbolMapFromArray(taxonomyServiceEvents); diff --git a/server/constants/torrentListPropMap.js b/server/constants/torrentListPropMap.js index e7c91283..8078f61a 100644 --- a/server/constants/torrentListPropMap.js +++ b/server/constants/torrentListPropMap.js @@ -1,4 +1,4 @@ -const regEx = require('../../shared/util/regEx'); +import regEx from '../../shared/util/regEx'; const torrentListPropMap = new Map(); @@ -244,4 +244,4 @@ torrentListPropMap.set('peersTotal', { transformValue: (value) => Number(value.substr(0, value.indexOf('|||'))), }); -module.exports = torrentListPropMap; +export default torrentListPropMap; diff --git a/server/constants/torrentServiceEvents.js b/server/constants/torrentServiceEvents.js index 2859e9ea..a6525681 100644 --- a/server/constants/torrentServiceEvents.js +++ b/server/constants/torrentServiceEvents.js @@ -1,5 +1,5 @@ -const objectUtil = require('../../shared/util/objectUtil'); +import objectUtil from '../../shared/util/objectUtil'; const torrentServiceEvents = ['FETCH_TORRENT_LIST_ERROR', 'FETCH_TORRENT_LIST_SUCCESS', 'TORRENT_LIST_DIFF_CHANGE']; -module.exports = objectUtil.createSymbolMapFromArray(torrentServiceEvents); +export default objectUtil.createSymbolMapFromArray(torrentServiceEvents); diff --git a/server/constants/transferSummaryPropMap.js b/server/constants/transferSummaryPropMap.js index 323e61bd..4ae8bc37 100644 --- a/server/constants/transferSummaryPropMap.js +++ b/server/constants/transferSummaryPropMap.js @@ -30,4 +30,4 @@ transferSummaryPropMap.set('downThrottle', { transformValue: Number, }); -module.exports = transferSummaryPropMap; +export default transferSummaryPropMap; diff --git a/server/middleware/appendUserServices.js b/server/middleware/appendUserServices.js index 2feb9157..f82ff89c 100644 --- a/server/middleware/appendUserServices.js +++ b/server/middleware/appendUserServices.js @@ -1,6 +1,6 @@ -const services = require('../services'); +import services from '../services'; -module.exports = (req, res, next) => { +export default (req, res, next) => { req.services = services.getAllServices(req.user); next(); }; diff --git a/server/middleware/booleanCoerce.js b/server/middleware/booleanCoerce.js index 899dcfb2..c8edf7c8 100644 --- a/server/middleware/booleanCoerce.js +++ b/server/middleware/booleanCoerce.js @@ -1,4 +1,4 @@ -module.exports = (key) => (req, res, next) => { +export default (key) => (req, res, next) => { const value = req.body && req.body[key]; if (value && typeof value === 'string') { diff --git a/server/middleware/clientActivityStream.js b/server/middleware/clientActivityStream.js index 5723f46b..96e9d179 100644 --- a/server/middleware/clientActivityStream.js +++ b/server/middleware/clientActivityStream.js @@ -1,16 +1,16 @@ -const clientGatewayServiceEvents = require('../constants/clientGatewayServiceEvents'); -const historyServiceEvents = require('../constants/historyServiceEvents'); -const historySnapshotTypes = require('../../shared/constants/historySnapshotTypes'); -const notificationServiceEvents = require('../constants/notificationServiceEvents'); -const ServerEvent = require('../models/ServerEvent'); -const serverEventTypes = require('../../shared/constants/serverEventTypes'); -const services = require('../services'); -const taxonomyServiceEvents = require('../constants/taxonomyServiceEvents'); -const torrentServiceEvents = require('../constants/torrentServiceEvents'); -const diskUsageServiceEvents = require('../constants/diskUsageServiceEvents'); -const DiskUsageService = require('../services/diskUsageService'); +import clientGatewayServiceEvents from '../constants/clientGatewayServiceEvents'; +import historyServiceEvents from '../constants/historyServiceEvents'; +import historySnapshotTypes from '../../shared/constants/historySnapshotTypes'; +import notificationServiceEvents from '../constants/notificationServiceEvents'; +import ServerEvent from '../models/ServerEvent'; +import serverEventTypes from '../../shared/constants/serverEventTypes'; +import services from '../services'; +import taxonomyServiceEvents from '../constants/taxonomyServiceEvents'; +import torrentServiceEvents from '../constants/torrentServiceEvents'; +import diskUsageServiceEvents from '../constants/diskUsageServiceEvents'; +import DiskUsageService from '../services/diskUsageService'; -module.exports = (req, res) => { +export default (req, res) => { const { query: {historySnapshot = historySnapshotTypes.FIVE_MINUTE}, user, diff --git a/server/middleware/eventStream.js b/server/middleware/eventStream.js index b2463b13..f8bc9574 100644 --- a/server/middleware/eventStream.js +++ b/server/middleware/eventStream.js @@ -1,4 +1,4 @@ -module.exports = (req, res, next) => { +export default (req, res, next) => { req.socket.setKeepAlive(true); req.socket.setTimeout(0); diff --git a/server/middleware/requireAdmin.js b/server/middleware/requireAdmin.js index 069471ae..1c8f698f 100644 --- a/server/middleware/requireAdmin.js +++ b/server/middleware/requireAdmin.js @@ -1,4 +1,4 @@ -module.exports = (req, res, next) => { +export default (req, res, next) => { if (req.user == null || !req.user.isAdmin) { return res.status(403).json({message: 'User is not admin.'}).send(); } diff --git a/server/models/ClientRequest.js b/server/models/ClientRequest.js index 1f74e6e5..ff09e08e 100644 --- a/server/models/ClientRequest.js +++ b/server/models/ClientRequest.js @@ -1,13 +1,13 @@ /** * This file is deprecated in favor of clientGatewayService. */ -const mv = require('mv'); -const path = require('path'); -const util = require('util'); +import mv from 'mv'; +import path from 'path'; +import util from 'util'; -const {clientSettings, clientSettingsMap} = require('../../shared/constants/clientSettingsMap'); -const rTorrentPropMap = require('../util/rTorrentPropMap'); -const torrentStatusMap = require('../../shared/constants/torrentStatusMap'); +import {clientSettings, clientSettingsMap} from '../../shared/constants/clientSettingsMap'; +import rTorrentPropMap from '../util/rTorrentPropMap'; +import torrentStatusMap from '../../shared/constants/torrentStatusMap'; const addTagsToRequest = (tagsArr, requestParameters) => { if (tagsArr && tagsArr.length) { @@ -384,4 +384,4 @@ class ClientRequest { } } -module.exports = ClientRequest; +export default ClientRequest; diff --git a/server/models/Feed.js b/server/models/Feed.js index b3e6f1ac..7b712ca2 100644 --- a/server/models/Feed.js +++ b/server/models/Feed.js @@ -1,4 +1,4 @@ -const FeedSub = require('feedsub'); +import FeedSub from 'feedsub'; class Feed { constructor(options) { @@ -71,4 +71,4 @@ class Feed { } } -module.exports = Feed; +export default Feed; diff --git a/server/models/Filesystem.js b/server/models/Filesystem.js index 4b3781ae..63ba3744 100644 --- a/server/models/Filesystem.js +++ b/server/models/Filesystem.js @@ -1,8 +1,8 @@ -const fs = require('fs'); -const os = require('os'); -const path = require('path'); +import fs from 'fs'; +import os from 'os'; +import path from 'path'; -const fileUtil = require('../util/fileUtil'); +import fileUtil from '../util/fileUtil'; const getDirectoryList = (options, callback) => { const sourcePath = (options.path || '/').replace(/^~/, os.homedir()); @@ -42,4 +42,4 @@ const getDirectoryList = (options, callback) => { } }; -module.exports = {getDirectoryList}; +export default {getDirectoryList}; diff --git a/server/models/HistoryEra.js b/server/models/HistoryEra.js index cb139cda..0bf3baba 100644 --- a/server/models/HistoryEra.js +++ b/server/models/HistoryEra.js @@ -1,7 +1,7 @@ -const Datastore = require('nedb'); -const path = require('path'); +import Datastore from 'nedb'; +import path from 'path'; -const config = require('../../config'); +import config from '../../config'; const MAX_NEXT_ERA_UPDATE_INTERVAL = 1000 * 60 * 60 * 12; // 12 hours const CUMULATIVE_DATA_BUFFER_DIFF = 500; // 500 miliseconds @@ -202,4 +202,4 @@ upAvg: ${upAvg}`, } } -module.exports = HistoryEra; +export default HistoryEra; diff --git a/server/models/ServerEvent.js b/server/models/ServerEvent.js index fbc14034..9545a1dc 100644 --- a/server/models/ServerEvent.js +++ b/server/models/ServerEvent.js @@ -29,4 +29,4 @@ class ServerEvent { } } -module.exports = ServerEvent; +export default ServerEvent; diff --git a/server/models/TemporaryStorage.js b/server/models/TemporaryStorage.js index 3d502c61..3021245b 100644 --- a/server/models/TemporaryStorage.js +++ b/server/models/TemporaryStorage.js @@ -1,7 +1,7 @@ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; -const {tempPath} = require('../../config'); +import {tempPath} from '../../config'; class TemporaryStorage { constructor() { @@ -17,4 +17,4 @@ class TemporaryStorage { } } -module.exports = new TemporaryStorage(); +export default new TemporaryStorage(); diff --git a/server/models/Users.js b/server/models/Users.js index c398d248..97f4e9ab 100644 --- a/server/models/Users.js +++ b/server/models/Users.js @@ -1,10 +1,10 @@ -const argon2 = require('argon2'); -const Datastore = require('nedb'); -const fs = require('fs-extra'); -const path = require('path'); +import argon2 from 'argon2'; +import Datastore from 'nedb'; +import fs from 'fs-extra'; +import path from 'path'; -const config = require('../../config'); -const services = require('../services'); +import config from '../../config'; +import services from '../services'; class Users { constructor() { @@ -185,4 +185,4 @@ class Users { } } -module.exports = new Users(); +export default new Users(); diff --git a/server/models/client.js b/server/models/client.js index a096ca5b..93cffc09 100644 --- a/server/models/client.js +++ b/server/models/client.js @@ -1,19 +1,19 @@ -const fs = require('fs'); -const path = require('path'); -const sanitize = require('sanitize-filename'); -const series = require('run-series'); -const tar = require('tar-stream'); +import fs from 'fs'; +import path from 'path'; +import sanitize from 'sanitize-filename'; +import series from 'run-series'; +import tar from 'tar-stream'; -const ClientRequest = require('./ClientRequest'); -const clientResponseUtil = require('../util/clientResponseUtil'); -const {clientSettingsMap} = require('../../shared/constants/clientSettingsMap'); -const fileUtil = require('../util/fileUtil'); -const settings = require('./settings'); -const torrentFilePropsMap = require('../../shared/constants/torrentFilePropsMap'); -const torrentPeerPropsMap = require('../../shared/constants/torrentPeerPropsMap'); -const torrentFileUtil = require('../util/torrentFileUtil'); -const torrentStatusMap = require('../../shared/constants/torrentStatusMap'); -const torrentTrackerPropsMap = require('../../shared/constants/torrentTrackerPropsMap'); +import ClientRequest from './ClientRequest'; +import clientResponseUtil from '../util/clientResponseUtil'; +import {clientSettingsMap} from '../../shared/constants/clientSettingsMap'; +import fileUtil from '../util/fileUtil'; +import settings from './settings'; +import torrentFilePropsMap from '../../shared/constants/torrentFilePropsMap'; +import torrentPeerPropsMap from '../../shared/constants/torrentPeerPropsMap'; +import torrentFileUtil from '../util/torrentFileUtil'; +import torrentStatusMap from '../../shared/constants/torrentStatusMap'; +import torrentTrackerPropsMap from '../../shared/constants/torrentTrackerPropsMap'; const client = { addFiles(user, services, req, callback) { @@ -432,4 +432,4 @@ const client = { }, }; -module.exports = client; +export default client; diff --git a/server/models/settings.js b/server/models/settings.js index 7163f82b..731298e2 100644 --- a/server/models/settings.js +++ b/server/models/settings.js @@ -1,8 +1,8 @@ -const _ = require('lodash'); -const Datastore = require('nedb'); -const path = require('path'); +import _ from 'lodash'; +import Datastore from 'nedb'; +import path from 'path'; -const config = require('../../config'); +import config from '../../config'; const databases = new Map(); @@ -135,4 +135,4 @@ const settings = { }, }; -module.exports = settings; +export default settings; diff --git a/server/routes/api.js b/server/routes/api.js index 3e95ed8f..4febf6ff 100644 --- a/server/routes/api.js +++ b/server/routes/api.js @@ -1,18 +1,18 @@ -const express = require('express'); -const passport = require('passport'); +import express from 'express'; +import passport from 'passport'; + +import appendUserServices from '../middleware/appendUserServices'; +import ajaxUtil from '../util/ajaxUtil'; +import client from '../models/client'; +import clientRoutes from './client'; +import clientActivityStream from '../middleware/clientActivityStream'; +import eventStream from '../middleware/eventStream'; +import Filesystem from '../models/Filesystem'; +import mediainfo from '../util/mediainfo'; +import settings from '../models/settings'; const router = express.Router(); -const appendUserServices = require('../middleware/appendUserServices'); -const ajaxUtil = require('../util/ajaxUtil'); -const client = require('../models/client'); -const clientRoutes = require('./client'); -const clientActivityStream = require('../middleware/clientActivityStream'); -const eventStream = require('../middleware/eventStream'); -const Filesystem = require('../models/Filesystem'); -const mediainfo = require('../util/mediainfo'); -const settings = require('../models/settings'); - router.use('/', passport.authenticate('jwt', {session: false}), appendUserServices); router.use('/client', clientRoutes); @@ -83,4 +83,4 @@ router.patch('/settings', (req, res) => { settings.set(req.user, req.body, ajaxUtil.getResponseFn(res)); }); -module.exports = router; +export default router; diff --git a/server/routes/auth.js b/server/routes/auth.js index 4d7193e9..b39eccfa 100644 --- a/server/routes/auth.js +++ b/server/routes/auth.js @@ -1,15 +1,16 @@ -const express = require('express'); -const joi = require('joi'); -const jwt = require('jsonwebtoken'); -const passport = require('passport'); -const ajaxUtil = require('../util/ajaxUtil'); +import express from 'express'; +import joi from 'joi'; +import jwt from 'jsonwebtoken'; +import passport from 'passport'; +import ajaxUtil from '../util/ajaxUtil'; -const requireAdmin = require('../middleware/requireAdmin'); -const config = require('../../config'); +import requireAdmin from '../middleware/requireAdmin'; +import config from '../../config'; + +import services from '../services'; +import Users from '../models/Users'; const router = express.Router(); -const services = require('../services'); -const Users = require('../models/Users'); const failedLoginResponse = 'Failed login.'; @@ -210,4 +211,4 @@ router.put('/users', (req, res) => { ); }); -module.exports = router; +export default router; diff --git a/server/routes/client.js b/server/routes/client.js index 3075d6f6..ebba528c 100644 --- a/server/routes/client.js +++ b/server/routes/client.js @@ -1,9 +1,9 @@ -const express = require('express'); -const multer = require('multer'); +import express from 'express'; +import multer from 'multer'; -const ajaxUtil = require('../util/ajaxUtil'); -const booleanCoerce = require('../middleware/booleanCoerce'); -const client = require('../models/client'); +import ajaxUtil from '../util/ajaxUtil'; +import booleanCoerce from '../middleware/booleanCoerce'; +import client from '../models/client'; const router = express.Router(); @@ -117,4 +117,4 @@ router.get('/methods.json', (req, res) => { client.listMethods(req.user, req.services, method, args, ajaxUtil.getResponseFn(res)); }); -module.exports = router; +export default router; diff --git a/server/services/BaseService.js b/server/services/BaseService.js index 5cd4907e..637c021e 100644 --- a/server/services/BaseService.js +++ b/server/services/BaseService.js @@ -1,4 +1,4 @@ -const EventEmitter = require('events'); +import EventEmitter from 'events'; class BaseService extends EventEmitter { constructor(user, services, ...eventEmitterConfig) { @@ -19,4 +19,4 @@ class BaseService extends EventEmitter { } } -module.exports = BaseService; +export default BaseService; diff --git a/server/services/clientGatewayService.js b/server/services/clientGatewayService.js index 57701595..028471cb 100644 --- a/server/services/clientGatewayService.js +++ b/server/services/clientGatewayService.js @@ -1,11 +1,11 @@ -const path = require('path'); -const fs = require('fs'); +import path from 'path'; +import fs from 'fs'; -const BaseService = require('./BaseService'); -const clientGatewayServiceEvents = require('../constants/clientGatewayServiceEvents'); -const fileListPropMap = require('../constants/fileListPropMap'); -const methodCallUtil = require('../util/methodCallUtil'); -const scgiUtil = require('../util/scgiUtil'); +import BaseService from './BaseService'; +import clientGatewayServiceEvents from '../constants/clientGatewayServiceEvents'; +import fileListPropMap from '../constants/fileListPropMap'; +import methodCallUtil from '../util/methodCallUtil'; +import scgiUtil from '../util/scgiUtil'; const fileListMethodCallConfig = methodCallUtil.getMethodCallConfigFromPropMap(fileListPropMap, ['pathComponents']); @@ -262,4 +262,4 @@ class ClientGatewayService extends BaseService { } } -module.exports = ClientGatewayService; +export default ClientGatewayService; diff --git a/server/services/clientRequestManager.js b/server/services/clientRequestManager.js index 77569b77..5b737efd 100644 --- a/server/services/clientRequestManager.js +++ b/server/services/clientRequestManager.js @@ -1,5 +1,5 @@ -const BaseService = require('./BaseService'); -const scgiUtil = require('../util/scgiUtil'); +import BaseService from './BaseService'; +import scgiUtil from '../util/scgiUtil'; class ClientRequestManager extends BaseService { constructor(...serviceConfig) { @@ -80,4 +80,4 @@ class ClientRequestManager extends BaseService { } } -module.exports = ClientRequestManager; +export default ClientRequestManager; diff --git a/server/services/diskUsageService.js b/server/services/diskUsageService.js index d5904cb9..2bfe1ca6 100644 --- a/server/services/diskUsageService.js +++ b/server/services/diskUsageService.js @@ -1,12 +1,14 @@ /** - * This service is not per rtorrent session, which is why it does not inherit - * `BaseService` nor have any use of the per user API ie. `getSerivce()` + * This service is not per rTorrent session, which is why it does not inherit + * `BaseService` nor have any use of the per user API ie. `getService()` */ -const EventEmitter = require('events'); -const util = require('util'); -const execFile = util.promisify(require('child_process').execFile); -const config = require('../../config'); -const diskUsageServiceEvents = require('../constants/diskUsageServiceEvents'); +import EventEmitter from 'events'; +import {execFile} from 'child_process'; +import util from 'util'; +import config from '../../config'; +import diskUsageServiceEvents from '../constants/diskUsageServiceEvents'; + +const execFileAsync = util.promisify(execFile); const PLATFORMS_SUPPORTED = ['darwin', 'linux', 'freebsd', 'win32']; const MAX_BUFFER_SIZE = 65536; @@ -20,7 +22,7 @@ const filterMountPoint = const diskUsage = { linux: () => - execFile('df -xsquashfs -xtmpfs -xdevtmpfs | tail -n+2', { + execFileAsync('df -xsquashfs -xtmpfs -xdevtmpfs | tail -n+2', { shell: true, maxBuffer: MAX_BUFFER_SIZE, }).then(({stdout}) => @@ -39,7 +41,7 @@ const diskUsage = { }), ), freebsd: () => - execFile('df | tail -n+2', { + execFileAsync('df | tail -n+2', { shell: true, maxBuffer: MAX_BUFFER_SIZE, }).then(({stdout}) => @@ -58,7 +60,7 @@ const diskUsage = { }), ), darwin: () => - execFile('df -kl | tail -n+2', { + execFileAsync('df -kl | tail -n+2', { shell: true, maxBuffer: MAX_BUFFER_SIZE, }).then(({stdout}) => @@ -77,7 +79,7 @@ const diskUsage = { }), ), win32: () => - execFile('wmic logicaldisk', { + execFileAsync('wmic logicaldisk', { shell: true, maxBuffer: MAX_BUFFER_SIZE, }).then(({stdout}) => @@ -152,4 +154,4 @@ class DiskUsageService extends EventEmitter { } } -module.exports = new DiskUsageService(); +export default new DiskUsageService(); diff --git a/server/services/feedService.js b/server/services/feedService.js index 8612003a..182cf4f1 100644 --- a/server/services/feedService.js +++ b/server/services/feedService.js @@ -1,11 +1,11 @@ -const path = require('path'); -const Datastore = require('nedb'); +import path from 'path'; +import Datastore from 'nedb'; -const BaseService = require('./BaseService'); -const client = require('../models/client'); -const config = require('../../config'); -const Feed = require('../models/Feed'); -const regEx = require('../../shared/util/regEx'); +import BaseService from './BaseService'; +import client from '../models/client'; +import config from '../../config'; +import Feed from '../models/Feed'; +import regEx from '../../shared/util/regEx'; // TODO: Allow users to specify which key contains the URLs. const getTorrentUrlsFromItem = (feedItem) => { @@ -360,4 +360,4 @@ class FeedService extends BaseService { } } -module.exports = FeedService; +export default FeedService; diff --git a/server/services/historyService.js b/server/services/historyService.js index b2371a3e..21543ede 100644 --- a/server/services/historyService.js +++ b/server/services/historyService.js @@ -1,11 +1,11 @@ -const BaseService = require('./BaseService'); -const config = require('../../config'); -const HistoryEra = require('../models/HistoryEra'); -const historyServiceEvents = require('../constants/historyServiceEvents'); -const historySnapshotTypes = require('../../shared/constants/historySnapshotTypes'); -const methodCallUtil = require('../util/methodCallUtil'); -const objectUtil = require('../../shared/util/objectUtil'); -const transferSummaryPropMap = require('../constants/transferSummaryPropMap'); +import BaseService from './BaseService'; +import config from '../../config'; +import HistoryEra from '../models/HistoryEra'; +import historyServiceEvents from '../constants/historyServiceEvents'; +import historySnapshotTypes from '../../shared/constants/historySnapshotTypes'; +import methodCallUtil from '../util/methodCallUtil'; +import objectUtil from '../../shared/util/objectUtil'; +import transferSummaryPropMap from '../constants/transferSummaryPropMap'; const transferSummaryMethodCallConfig = methodCallUtil.getMethodCallConfigFromPropMap(transferSummaryPropMap); @@ -209,4 +209,4 @@ class HistoryService extends BaseService { } } -module.exports = HistoryService; +export default HistoryService; diff --git a/server/services/index.js b/server/services/index.js index b9b78bb1..0c827c24 100644 --- a/server/services/index.js +++ b/server/services/index.js @@ -1,10 +1,10 @@ -const ClientGatewayService = require('./clientGatewayService'); -const ClientRequestManager = require('./clientRequestManager'); -const FeedService = require('./feedService'); -const HistoryService = require('./historyService'); -const NotificationService = require('./notificationService'); -const TaxonomyService = require('./taxonomyService'); -const TorrentService = require('./torrentService'); +import ClientGatewayService from './clientGatewayService'; +import ClientRequestManager from './clientRequestManager'; +import FeedService from './feedService'; +import HistoryService from './historyService'; +import NotificationService from './notificationService'; +import TaxonomyService from './taxonomyService'; +import TorrentService from './torrentService'; const clientRequestManagers = new Map(); const clientGatewayServices = new Map(); @@ -113,7 +113,7 @@ const updateUserServices = (user) => { }); }; -module.exports = { +export default { bootstrapServicesForUser, destroyUserServices, getAllServices, diff --git a/server/services/notificationService.js b/server/services/notificationService.js index 7c6ced0c..2b287c2c 100644 --- a/server/services/notificationService.js +++ b/server/services/notificationService.js @@ -1,10 +1,10 @@ -const _ = require('lodash'); -const Datastore = require('nedb'); -const path = require('path'); +import _ from 'lodash'; +import Datastore from 'nedb'; +import path from 'path'; -const BaseService = require('./BaseService'); -const config = require('../../config'); -const notificationServiceEvents = require('../constants/notificationServiceEvents'); +import BaseService from './BaseService'; +import config from '../../config'; +import notificationServiceEvents from '../constants/notificationServiceEvents'; const DEFAULT_QUERY_LIMIT = 20; const INITIAL_COUNT_VALUE = {read: 0, total: 0, unread: 0}; @@ -122,4 +122,4 @@ class NotificationService extends BaseService { } } -module.exports = NotificationService; +export default NotificationService; diff --git a/server/services/taxonomyService.js b/server/services/taxonomyService.js index 9c917d8d..30e94296 100644 --- a/server/services/taxonomyService.js +++ b/server/services/taxonomyService.js @@ -1,8 +1,8 @@ -const BaseService = require('./BaseService'); -const clientGatewayServiceEvents = require('../constants/clientGatewayServiceEvents'); -const objectUtil = require('../../shared/util/objectUtil'); -const taxonomyServiceEvents = require('../constants/taxonomyServiceEvents'); -const torrentStatusMap = require('../../shared/constants/torrentStatusMap'); +import BaseService from './BaseService'; +import clientGatewayServiceEvents from '../constants/clientGatewayServiceEvents'; +import objectUtil from '../../shared/util/objectUtil'; +import taxonomyServiceEvents from '../constants/taxonomyServiceEvents'; +import torrentStatusMap from '../../shared/constants/torrentStatusMap'; class TaxonomyService extends BaseService { constructor(...serviceConfig) { @@ -130,4 +130,4 @@ class TaxonomyService extends BaseService { } } -module.exports = TaxonomyService; +export default TaxonomyService; diff --git a/server/services/torrentService.js b/server/services/torrentService.js index 034b90eb..1cdc4973 100644 --- a/server/services/torrentService.js +++ b/server/services/torrentService.js @@ -1,14 +1,14 @@ -const deepEqual = require('deep-equal'); -const BaseService = require('./BaseService'); -const clientGatewayServiceEvents = require('../constants/clientGatewayServiceEvents'); -const config = require('../../config'); -const formatUtil = require('../../shared/util/formatUtil'); -const methodCallUtil = require('../util/methodCallUtil'); -const serverEventTypes = require('../../shared/constants/serverEventTypes'); -const truncateTo = require('../util/numberUtils'); -const torrentListPropMap = require('../constants/torrentListPropMap'); -const torrentServiceEvents = require('../constants/torrentServiceEvents'); -const torrentStatusMap = require('../../shared/constants/torrentStatusMap'); +import deepEqual from 'deep-equal'; +import BaseService from './BaseService'; +import clientGatewayServiceEvents from '../constants/clientGatewayServiceEvents'; +import config from '../../config'; +import formatUtil from '../../shared/util/formatUtil'; +import methodCallUtil from '../util/methodCallUtil'; +import serverEventTypes from '../../shared/constants/serverEventTypes'; +import truncateTo from '../util/numberUtils'; +import torrentListPropMap from '../constants/torrentListPropMap'; +import torrentServiceEvents from '../constants/torrentServiceEvents'; +import torrentStatusMap from '../../shared/constants/torrentStatusMap'; const torrentListMethodCallConfig = methodCallUtil.getMethodCallConfigFromPropMap(torrentListPropMap); @@ -280,4 +280,4 @@ class TorrentService extends BaseService { } } -module.exports = TorrentService; +export default TorrentService; diff --git a/server/util/ajaxUtil.js b/server/util/ajaxUtil.js index cf5faba1..e6bf9311 100644 --- a/server/util/ajaxUtil.js +++ b/server/util/ajaxUtil.js @@ -18,4 +18,4 @@ const ajaxUtil = { }, }; -module.exports = ajaxUtil; +export default ajaxUtil; diff --git a/server/util/clientResponseUtil.js b/server/util/clientResponseUtil.js index 54f55984..c3d1747e 100644 --- a/server/util/clientResponseUtil.js +++ b/server/util/clientResponseUtil.js @@ -1,8 +1,8 @@ -const geoip = require('geoip-country'); -const truncateTo = require('./numberUtils'); -const torrentFilePropsMap = require('../../shared/constants/torrentFilePropsMap'); -const torrentPeerPropsMap = require('../../shared/constants/torrentPeerPropsMap'); -const torrentTrackerPropsMap = require('../../shared/constants/torrentTrackerPropsMap'); +import geoip from 'geoip-country'; +import truncateTo from './numberUtils'; +import torrentFilePropsMap from '../../shared/constants/torrentFilePropsMap'; +import torrentPeerPropsMap from '../../shared/constants/torrentPeerPropsMap'; +import torrentTrackerPropsMap from '../../shared/constants/torrentTrackerPropsMap'; const processFile = (file) => { file.filename = file.pathComponents[file.pathComponents.length - 1]; @@ -124,4 +124,4 @@ const clientResponseUtil = { processTorrentDetails, }; -module.exports = clientResponseUtil; +export default clientResponseUtil; diff --git a/server/util/fileUtil.js b/server/util/fileUtil.js index 4dacb720..9e91c822 100644 --- a/server/util/fileUtil.js +++ b/server/util/fileUtil.js @@ -1,7 +1,7 @@ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; -const config = require('../../config'); +import config from '../../config'; const createDirectory = (options) => { if (options.path) { @@ -44,4 +44,4 @@ const fileUtil = { accessDeniedError, }; -module.exports = fileUtil; +export default fileUtil; diff --git a/server/util/mediainfo.js b/server/util/mediainfo.js index 52922b56..fc99ffb6 100644 --- a/server/util/mediainfo.js +++ b/server/util/mediainfo.js @@ -1,8 +1,8 @@ -const childProcess = require('child_process'); +import childProcess from 'child_process'; -const services = require('../services'); +import services from '../services'; -module.exports = { +export default { getMediainfo(user, options, callback) { const torrentService = services.getTorrentService(user); const {hash} = options; diff --git a/server/util/methodCallUtil.js b/server/util/methodCallUtil.js index 22136aff..db67bc5b 100644 --- a/server/util/methodCallUtil.js +++ b/server/util/methodCallUtil.js @@ -25,4 +25,4 @@ const methodCallUtil = { }, }; -module.exports = methodCallUtil; +export default methodCallUtil; diff --git a/server/util/numberUtils.js b/server/util/numberUtils.js index f47d3230..dc2ea792 100644 --- a/server/util/numberUtils.js +++ b/server/util/numberUtils.js @@ -3,4 +3,4 @@ const truncateTo = (num, precision = 0) => { return Math.floor(num * factor) / factor; }; -module.exports = truncateTo; +export default truncateTo; diff --git a/server/util/rTorrentDeserializer.js b/server/util/rTorrentDeserializer.js index e8ac8227..be407547 100644 --- a/server/util/rTorrentDeserializer.js +++ b/server/util/rTorrentDeserializer.js @@ -1,4 +1,4 @@ -const saxen = require('saxen'); +import {Parser} from 'saxen'; let stackMarks; let dataStack; @@ -6,6 +6,9 @@ let tmpData; let dataIsVal; let endOfResponse; let rejectCallback; +let parser = new Parser(); + +let parserInit = false; const unescapeXMLString = (value) => value @@ -87,6 +90,19 @@ const closeTag = (elementName) => { } }; +const initParser = () => { + if (parserInit === true) { + return; + } + + parser.on('openTag', openTag); + parser.on('closeTag', closeTag); + parser.on('text', onText); + parser.on('error', onError); + + parserInit = true; +}; + const deserialize = (data, resolve, reject) => { stackMarks = []; dataStack = []; @@ -94,16 +110,15 @@ const deserialize = (data, resolve, reject) => { dataIsVal = false; endOfResponse = false; rejectCallback = reject; - const parser = new saxen.Parser(); - parser.on('openTag', openTag); - parser.on('closeTag', closeTag); - parser.on('text', onText); - parser.on('error', onError); + + initParser(); parser.parse(data); + if (endOfResponse) { return resolve(dataStack[0]); } + return reject('truncated response was received'); }; -module.exports = {deserialize}; +export default {deserialize}; diff --git a/server/util/rTorrentPropMap.js b/server/util/rTorrentPropMap.js index 7eed427b..88503136 100644 --- a/server/util/rTorrentPropMap.js +++ b/server/util/rTorrentPropMap.js @@ -9,4 +9,4 @@ const RTORRENT_PROPS_MAP = { }, }; -module.exports = RTORRENT_PROPS_MAP; +export default RTORRENT_PROPS_MAP; diff --git a/server/util/scgiUtil.js b/server/util/scgiUtil.js index 738bc3d3..4043cd43 100644 --- a/server/util/scgiUtil.js +++ b/server/util/scgiUtil.js @@ -1,6 +1,6 @@ -const net = require('net'); -const Serializer = require('xmlrpc/lib/serializer'); -const rTorrentDeserializer = require('./rTorrentDeserializer'); +import net from 'net'; +import Serializer from 'xmlrpc/lib/serializer'; +import rTorrentDeserializer from './rTorrentDeserializer'; const NULL_CHAR = String.fromCharCode(0); @@ -40,4 +40,4 @@ const methodCall = (connectionMethod, methodName, parameters) => .catch(reject); }); -module.exports = {methodCall}; +export default {methodCall}; diff --git a/server/util/torrentFileUtil.js b/server/util/torrentFileUtil.js index 183d7e8c..60f3a253 100644 --- a/server/util/torrentFileUtil.js +++ b/server/util/torrentFileUtil.js @@ -1,5 +1,5 @@ -const bencode = require('bencode'); -const fs = require('fs'); +import bencode from 'bencode'; +import fs from 'fs'; const setTracker = (torrent, tracker) => { fs.readFile(torrent, (err, data) => { @@ -21,4 +21,4 @@ const torrentFileUtil = { setTracker, }; -module.exports = torrentFileUtil; +export default torrentFileUtil;