From 0dc1b6fa04c71bb06bd675adc8c208ebdd2fcdec Mon Sep 17 00:00:00 2001 From: Alex Kern Date: Sun, 20 Sep 2020 17:27:08 -0700 Subject: [PATCH] prettier --- .eslintrc.js | 3 +- .prettierrc.js | 9 +++ pages/download/[...slug].tsx | 7 ++ src/actions/DownloadActions.js | 7 +- src/actions/SupportActions.js | 7 +- src/actions/UploadActions.js | 7 +- src/alt.js | 2 +- src/client.js | 28 ++++---- src/components/App.js | 44 ++++++------ src/components/Bootstrap.js | 2 +- src/components/DownloadButton.js | 2 +- src/components/DownloadPage.js | 20 +++--- src/components/DropZone.js | 4 +- src/components/ErrorPage.js | 8 +-- src/components/Tempalink.js | 9 ++- src/components/Uploader.js | 8 +-- src/ice.js | 51 -------------- src/ice.ts | 52 ++++++++++++++ src/index.js | 13 ++-- src/middleware/bootstrap.js | 16 +++-- src/middleware/error.js | 11 ++- src/middleware/javascript.js | 16 +++-- src/middleware/react.js | 21 +++--- src/middleware/static.js | 10 +-- src/routes.js | 12 ++-- src/server.js | 113 ++++++++++++++++--------------- src/stores/DownloadStore.js | 42 ++++++------ src/stores/ErrorStore.js | 12 ++-- src/stores/SupportStore.js | 10 +-- src/stores/UploadStore.js | 58 ++++++++-------- src/toppings.js | 100 --------------------------- src/toppings.ts | 100 +++++++++++++++++++++++++++ src/{util.js => util.ts} | 6 +- src/{wt.js => wt.ts} | 4 +- 34 files changed, 419 insertions(+), 395 deletions(-) create mode 100644 .prettierrc.js create mode 100644 pages/download/[...slug].tsx delete mode 100644 src/ice.js create mode 100644 src/ice.ts delete mode 100644 src/toppings.js create mode 100644 src/toppings.ts rename src/{util.js => util.ts} (82%) rename src/{wt.js => wt.ts} (83%) diff --git a/.eslintrc.js b/.eslintrc.js index 08bfe7e..95f0ce9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,8 +1,9 @@ 'use strict'; module.exports = { + parser: '@typescript-eslint/parser', parserOptions: { - project: './tsconfig.json' + project: './tsconfig.json', }, extends: [ '@strv/typescript', diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..5f64564 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,9 @@ +'use strict'; + +module.exports = { + semi: false, + trailingComma: 'all', + singleQuote: true, + printWidth: 80, + tabWidth: 2, +}; diff --git a/pages/download/[...slug].tsx b/pages/download/[...slug].tsx new file mode 100644 index 0000000..402a959 --- /dev/null +++ b/pages/download/[...slug].tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +const DownloadPage = () => { + return
+} + +export default DownloadPage diff --git a/src/actions/DownloadActions.js b/src/actions/DownloadActions.js index 724ee0e..6d0fe5e 100644 --- a/src/actions/DownloadActions.js +++ b/src/actions/DownloadActions.js @@ -1,8 +1,7 @@ -import alt from '../alt'; +import alt from '../alt' export default alt.createActions(class DownloadActions { constructor() { - this.generateActions('requestDownload'); + this.generateActions('requestDownload') } - }, -) + }) diff --git a/src/actions/SupportActions.js b/src/actions/SupportActions.js index 9f7be30..9c4e1bd 100644 --- a/src/actions/SupportActions.js +++ b/src/actions/SupportActions.js @@ -1,8 +1,7 @@ -import alt from '../alt'; +import alt from '../alt' export default alt.createActions(class SupportActions { constructor() { - this.generateActions('isChrome', 'noSupport'); + this.generateActions('isChrome', 'noSupport') } - }, -) + }) diff --git a/src/actions/UploadActions.js b/src/actions/UploadActions.js index 3440170..96a7bb8 100644 --- a/src/actions/UploadActions.js +++ b/src/actions/UploadActions.js @@ -1,8 +1,7 @@ -import alt from '../alt'; +import alt from '../alt' export default alt.createActions(class UploadActions { constructor() { - this.generateActions('uploadFile'); + this.generateActions('uploadFile') } - }, -) + }) diff --git a/src/alt.js b/src/alt.js index 67ce981..714e2eb 100644 --- a/src/alt.js +++ b/src/alt.js @@ -1,3 +1,3 @@ -import Alt from 'alt'; +import Alt from 'alt' export default new Alt() diff --git a/src/client.js b/src/client.js index 9115de6..fa3c975 100644 --- a/src/client.js +++ b/src/client.js @@ -1,25 +1,25 @@ -import "babel-polyfill"; -import "./index.styl"; -import React from "react"; -import ReactRouter from "react-router"; -import webrtcSupport from 'webrtcsupport'; -import routes from './routes'; -import alt from './alt'; -import SupportActions from "./actions/SupportActions"; +import 'babel-polyfill' +import './index.styl' +import React from 'react' +import ReactRouter from 'react-router' +import webrtcSupport from 'webrtcsupport' +import routes from './routes' +import alt from './alt' +import SupportActions from './actions/SupportActions' -const bootstrap = document.getElementById("bootstrap").innerHTML; -alt.bootstrap(bootstrap); +const bootstrap = document.getElementById('bootstrap').innerHTML +alt.bootstrap(bootstrap) window.FilePizza = () => { ReactRouter.run(routes, ReactRouter.HistoryLocation, Handler => { - React.render(, document); + React.render(, document) }) if (!webrtcSupport.support) { - SupportActions.noSupport(); + SupportActions.noSupport() } const isChrome = navigator.userAgent.toLowerCase().includes('chrome') -;if (isChrome) { + if (isChrome) { SupportActions.isChrome() } -}; +} diff --git a/src/components/App.js b/src/components/App.js index d3ffc5d..a772378 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,32 +1,32 @@ -import FrozenHead from "react-frozenhead"; -import React from "react"; -import { RouteHandler } from 'react-router'; -import ga from 'react-google-analytics'; -import SupportStore from '../stores/SupportStore'; -import ErrorPage from "./ErrorPage"; -import Bootstrap from './Bootstrap'; +import FrozenHead from 'react-frozenhead' +import React from 'react' +import { RouteHandler } from 'react-router' +import ga from 'react-google-analytics' +import SupportStore from '../stores/SupportStore' +import ErrorPage from './ErrorPage' +import Bootstrap from './Bootstrap' if (process.env.GA_ACCESS_TOKEN) { - ga("create", process.env.GA_ACCESS_TOKEN, "auto"); - ;;ga('send', 'pageview') + ga('create', process.env.GA_ACCESS_TOKEN, 'auto') + ga('send', 'pageview') } export default class App extends React.Component { constructor() { - super(); - this.state = SupportStore.getState(); + super() + this.state = SupportStore.getState() this._onChange = () => { - this.setState(SupportStore.getState()); + this.setState(SupportStore.getState()) } } componentDidMount() { - SupportStore.listen(this._onChange); + SupportStore.listen(this._onChange) } componentWillUnmount() { - SupportStore.unlisten(this._onChange); + SupportStore.unlisten(this._onChange) } render() { @@ -72,19 +72,19 @@ export default class App extends React.Component {

- Cooked up by{" "} + Cooked up by{' '} Alex Kern - {" "} - &{" "} + {' '} + &{' '} Neeraj Baid - {" "} - while eating Sliver @ UC Berkeley ·{" "} + {' '} + while eating Sliver @ UC Berkeley ·{' '} FAQ - {" "} - ·{" "} + {' '} + ·{' '} Fork us @@ -94,6 +94,6 @@ export default class App extends React.Component { {process.env.GA_ACCESS_TOKEN ? :

} - ); + ) } } diff --git a/src/components/Bootstrap.js b/src/components/Bootstrap.js index 769f0e9..7e48f35 100644 --- a/src/components/Bootstrap.js +++ b/src/components/Bootstrap.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React from 'react' export default class Bootstrap extends React.Component { render() { diff --git a/src/components/DownloadButton.js b/src/components/DownloadButton.js index 98362f0..64e14ff 100644 --- a/src/components/DownloadButton.js +++ b/src/components/DownloadButton.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React from 'react' export default class DownloadButton extends React.Component { constructor() { diff --git a/src/components/DownloadPage.js b/src/components/DownloadPage.js index 0478d07..514d4cb 100644 --- a/src/components/DownloadPage.js +++ b/src/components/DownloadPage.js @@ -1,12 +1,12 @@ -import React from "react"; -import DownloadActions from '../actions/DownloadActions'; -import DownloadStore from '../stores/DownloadStore'; -import { formatSize } from "../util"; -import ChromeNotice from './ChromeNotice'; -import DownloadButton from "./DownloadButton"; -import ErrorPage from './ErrorPage'; -import ProgressBar from './ProgressBar'; -import Spinner from "./Spinner"; +import React from 'react' +import DownloadActions from '../actions/DownloadActions' +import DownloadStore from '../stores/DownloadStore' +import { formatSize } from '../util' +import ChromeNotice from './ChromeNotice' +import DownloadButton from './DownloadButton' +import ErrorPage from './ErrorPage' +import ProgressBar from './ProgressBar' +import Spinner from './Spinner' export default class DownloadPage extends React.Component { constructor() { @@ -15,7 +15,7 @@ export default class DownloadPage extends React.Component { this._onChange = () => { this.setState(DownloadStore.getState()) - }; + } this.downloadFile = this.downloadFile.bind(this) } diff --git a/src/components/DropZone.js b/src/components/DropZone.js index c06f746..3f7aef4 100644 --- a/src/components/DropZone.js +++ b/src/components/DropZone.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React from 'react' export default class DropZone extends React.Component { constructor() { @@ -24,7 +24,7 @@ export default class DropZone extends React.Component { onDragOver(e) { e.preventDefault() - e.dataTransfer.dropEffect = 'copy'; + e.dataTransfer.dropEffect = 'copy' } onDrop(e) { diff --git a/src/components/ErrorPage.js b/src/components/ErrorPage.js index ac97f5f..6dddc61 100644 --- a/src/components/ErrorPage.js +++ b/src/components/ErrorPage.js @@ -1,6 +1,6 @@ -import React from "react"; -import ErrorStore from "../stores/ErrorStore"; -import Spinner from './Spinner'; +import React from 'react' +import ErrorStore from '../stores/ErrorStore' +import Spinner from './Spinner' export default class ErrorPage extends React.Component { constructor() { @@ -9,7 +9,7 @@ export default class ErrorPage extends React.Component { this._onChange = () => { this.setState(ErrorStore.getState()) - }; + } } componentDidMount() { diff --git a/src/components/Tempalink.js b/src/components/Tempalink.js index 47fe426..dad73dc 100644 --- a/src/components/Tempalink.js +++ b/src/components/Tempalink.js @@ -1,5 +1,5 @@ -import React from 'react'; -import QRCode from 'react-qr'; +import React from 'react' +import QRCode from 'react-qr' export default class Tempalink extends React.Component { constructor() { @@ -12,9 +12,8 @@ export default class Tempalink extends React.Component { } render() { - const url = `${window.location.origin}/${this.props.token}`; - const shortUrl - = window.location.origin + '/download/' + this.props.shortToken + const url = `${window.location.origin}/${this.props.token}` + const shortUrl = `${window.location.origin}/download/${this.props.shortToken}` return (
diff --git a/src/components/Uploader.js b/src/components/Uploader.js index d911c3b..3291afa 100644 --- a/src/components/Uploader.js +++ b/src/components/Uploader.js @@ -1,6 +1,6 @@ -import Arrow from '@app/components/Arrow'; -import React from 'react'; -import UploadActions from '@app/actions/UploadActions'; +import Arrow from '@app/components/Arrow' +import React from 'react' +import UploadActions from '@app/actions/UploadActions' export default class UploadPage extends React.Component { constructor() { @@ -9,7 +9,7 @@ export default class UploadPage extends React.Component { } uploadFile(file) { - UploadActions.uploadFile(file); + UploadActions.uploadFile(file) } render() { diff --git a/src/ice.js b/src/ice.js deleted file mode 100644 index bbdccac..0000000 --- a/src/ice.js +++ /dev/null @@ -1,51 +0,0 @@ -const twilio = require("twilio"); -var winston = require("winston"); -if (process.env.TWILIO_SID && process.env.TWILIO_TOKEN) { - const twilioSID = process.env.TWILIO_SID; - const twilioToken = process.env.TWILIO_TOKEN; - var client = twilio(twilioSID, twilioToken); - winston.info("Using Twilio TURN service"); -} else { - var client = null; -} - -let ICE_SERVERS = [ - { - urls: "stun:stun.l.google.com:19302", - }, -]; - -if (process.env.ICE_SERVERS) { - ICE_SERVERS = JSON.parse(process.env.ICE_SERVERS) -} - -const CACHE_LIFETIME = 5 * 60 * 1000; // 5 minutes -let cachedPromise = null; - -function clearCache() { - cachedPromise = null; -} - -exports.getICEServers = function() { - if (client == null) { - return Promise.resolve(ICE_SERVERS) - } - if (cachedPromise) { - return cachedPromise - } - - cachedPromise = new Promise((resolve, reject) => { - client.tokens.create({}, (err, token) => { - if (err) { - winston.error(err); - return resolve(DEFAULT_ICE_SERVERS); - } - - winston.info("Retrieved ICE servers from Twilio"); - ;setTimeout(clearCache, CACHE_LIFETIME) - resolve(token.ice_servers); - }) - }); - - return cachedPromise; -} diff --git a/src/ice.ts b/src/ice.ts new file mode 100644 index 0000000..602b348 --- /dev/null +++ b/src/ice.ts @@ -0,0 +1,52 @@ +const twilio = require('twilio') +const winston = require('winston') + +if (process.env.TWILIO_SID && process.env.TWILIO_TOKEN) { + const twilioSID = process.env.TWILIO_SID + const twilioToken = process.env.TWILIO_TOKEN + var client = twilio(twilioSID, twilioToken) + winston.info('Using Twilio TURN service') +} else { + var client = null +} + +let ICE_SERVERS = [ + { + urls: 'stun:stun.l.google.com:19302', + }, +] + +if (process.env.ICE_SERVERS) { + ICE_SERVERS = JSON.parse(process.env.ICE_SERVERS) +} + +const CACHE_LIFETIME = 5 * 60 * 1000 // 5 minutes +let cachedPromise = null + +function clearCache() { + cachedPromise = null +} + +exports.getICEServers = function() { + if (client == null) { + return Promise.resolve(ICE_SERVERS) + } + if (cachedPromise) { + return cachedPromise + } + + cachedPromise = new Promise((resolve, reject) => { + client.tokens.create({}, (err, token) => { + if (err) { + winston.error(err) + return resolve(DEFAULT_ICE_SERVERS) + } + + winston.info('Retrieved ICE servers from Twilio') + setTimeout(clearCache, CACHE_LIFETIME) + resolve(token.ice_servers) + }) + }) + + return cachedPromise +} diff --git a/src/index.js b/src/index.js index 4c77ea3..f4b5b74 100755 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ try { require('../newrelic') -;require('newrelic'); + require('newrelic') } catch (ex) { // Don't load New Relic if the configuration file doesn't exist. } @@ -10,14 +10,15 @@ try { process.on('unhandledRejection', (reason, p) => { p.catch(err => { console.error('Exiting due to unhandled rejection!') -;;;console.error(err) + console.error(err) process.exit(1) - }); + }) }) process.on('uncaughtException', err => { console.error('Exiting due to uncaught exception!') -;console.error(err.stack) + console.error(err.stack) process.exit(1) -}); -module.exports = require("./server"); +}) + +module.exports = require('./server') diff --git a/src/middleware/bootstrap.js b/src/middleware/bootstrap.js index 1968530..9ad59f1 100644 --- a/src/middleware/bootstrap.js +++ b/src/middleware/bootstrap.js @@ -1,7 +1,9 @@ -const express = require("express"); -const db = require("../db"); -let routes = (module.exports = new express.Router()) -;function bootstrap(uploader, req, res, next) { +const express = require('express') +const db = require('../db') + +const routes = module.exports = new express.Router() + +function bootstrap(uploader, req, res, next) { if (uploader) { res.locals.data = { DownloadStore: { @@ -17,7 +19,7 @@ let routes = (module.exports = new express.Router()) next() } else { const err = new Error('Not Found') -;err.status = 404 + err.status = 404 next(err) } } @@ -25,8 +27,8 @@ let routes = (module.exports = new express.Router()) routes.get(/^\/([a-z]+\/[a-z]+\/[a-z]+\/[a-z]+)$/, (req, res, next) => { const uploader = db.find(req.params[0]) return bootstrap(uploader, req, res, next) -}); +}) routes.get(/^\/download\/(\w+)$/, (req, res, next) => { const uploader = db.findShort(req.params[0]) return bootstrap(uploader, req, res, next) -}); +}) diff --git a/src/middleware/error.js b/src/middleware/error.js index e725db6..e519176 100644 --- a/src/middleware/error.js +++ b/src/middleware/error.js @@ -1,10 +1,9 @@ module.exports = function (err, req, res, next) { - const status = err.status || 500; - const message = err.message || ''; - const stack - = process.env.NODE_ENV === 'production' ? null : err.stack || null + const status = err.status || 500 + const message = err.message || '' + const stack = process.env.NODE_ENV === 'production' ? null : err.stack || null - req.url = '/error'; + req.url = '/error' res.status(status) res.locals.data = { ErrorStore: { @@ -15,4 +14,4 @@ module.exports = function (err, req, res, next) { } next() -}; +} diff --git a/src/middleware/javascript.js b/src/middleware/javascript.js index b2aeef5..4b0139e 100644 --- a/src/middleware/javascript.js +++ b/src/middleware/javascript.js @@ -1,15 +1,17 @@ const path = require('path') -;const BUNDLE_PATH = path.resolve(__dirname, '../../dist/bundle.js') -;if (process.env.NODE_ENV === 'production') { + +const BUNDLE_PATH = path.resolve(__dirname, '../../dist/bundle.js') +if (process.env.NODE_ENV === 'production') { module.exports = function (req, res) { res.sendFile(BUNDLE_PATH) - }; + } } else { const webpackMiddleware = require('webpack-dev-middleware') -;const webpack = require('webpack') -;const config = require('../../webpack.config.js') -;config.output.filename = '/app.js'; - config.output.path = '/'; + const webpack = require('webpack') + const config = require('../../webpack.config.js') + + config.output.filename = '/app.js' + config.output.path = '/' module.exports = webpackMiddleware(webpack(config)) } diff --git a/src/middleware/react.js b/src/middleware/react.js index 87bfae4..230ecce 100644 --- a/src/middleware/react.js +++ b/src/middleware/react.js @@ -1,8 +1,9 @@ const React = require('react') -;let ReactRouter = require('react-router') -;let alt = require('../alt') -;let routes = require('../routes') -;function isNotFound(state) { +const ReactRouter = require('react-router') +const alt = require('../alt') +const routes = require('../routes') + +function isNotFound(state) { for (const r of state.routes) { if (r.isNotFound) { return true @@ -16,14 +17,14 @@ module.exports = function (req, res) { alt.bootstrap(JSON.stringify(res.locals.data || {})) ReactRouter.run(routes, req.url, (Handler, state) => { - const html = React.renderToString(); + const html = React.renderToString() alt.flush() - res.setHeader('Content-Type', 'text/html'); - ;;if (isNotFound(state)) { - res.status(404); + res.setHeader('Content-Type', 'text/html') + if (isNotFound(state)) { + res.status(404) } res.write('\n') -;;res.end(html) - }); + res.end(html) + }) } diff --git a/src/middleware/static.js b/src/middleware/static.js index 0f25ce7..15fefdb 100644 --- a/src/middleware/static.js +++ b/src/middleware/static.js @@ -1,4 +1,6 @@ -const path = require("path"); -const express = require("express"); -let STATIC_PATH = path.resolve(__dirname, "../static"); -module.exports = express.static(STATIC_PATH); +const path = require('path') +const express = require('express') + +const STATIC_PATH = path.resolve(__dirname, '../static') + +module.exports = express.static(STATIC_PATH) diff --git a/src/routes.js b/src/routes.js index b361223..d2fa89a 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,9 +1,9 @@ -import React from 'react'; -import { Route, DefaultRoute, NotFoundRoute, RouteHandler } from 'react-router'; -import App from './components/App'; -import DownloadPage from './components/DownloadPage'; -import UploadPage from './components/UploadPage'; -import ErrorPage from './components/ErrorPage'; +import React from 'react' +import { Route, DefaultRoute, NotFoundRoute, RouteHandler } from 'react-router' +import App from './components/App' +import DownloadPage from './components/DownloadPage' +import UploadPage from './components/UploadPage' +import ErrorPage from './components/ErrorPage' export default ( diff --git a/src/server.js b/src/server.js index 5b41ea1..4649d79 100644 --- a/src/server.js +++ b/src/server.js @@ -1,98 +1,100 @@ -const fs = require("fs"); -const express = require("express"); -var expressWinston = require("express-winston"); -var ice = require('./ice') -;var socketIO = require('socket.io') -;var winston = require('winston') -;const db = require('./db') -;process.on("unhandledRejection", (reason, p) => { +const fs = require('fs') +const express = require('express') +const expressWinston = require('express-winston') +const socketIO = require('socket.io') +const winston = require('winston') +const ice = require('./ice') +const db = require('./db') + +process.on('unhandledRejection', (reason, p) => { p.catch(err => { - log.error("Exiting due to unhandled rejection!"); - log.error(err); - process.exit(1); + log.error('Exiting due to unhandled rejection!') + log.error(err) + process.exit(1) }) -}); +}) -process.on("uncaughtException", err => { - log.error("Exiting due to uncaught exception!"); - log.error(err); - process.exit(1); +process.on('uncaughtException', (err) => { + log.error('Exiting due to uncaught exception!') + log.error(err) + process.exit(1) }) -const app = express(); +const app = express() let port -process.env.PORT || (process.env.NODE_ENV === "production" ? 80 : 3000); +process.env.PORT || (process.env.NODE_ENV === 'production' ? 80 : 3000) if (!process.env.QUIET) { app.use( expressWinston.logger({ winstonInstance: winston, expressFormat: true, - }) - ); + })) } -app.get("/app.js", require("./middleware/javascript")); -app.use(require("./middleware/static")); +app.get('/app.js', require('./middleware/javascript')) +app.use(require('./middleware/static')) app.use([ - require("./middleware/bootstrap"), - require("./middleware/error"), - require("./middleware/react"), -]); + require('./middleware/bootstrap'), + require('./middleware/error'), + require('./middleware/react'), +]) const TRACKERS = process.env.WEBTORRENT_TRACKERS ? process.env.WEBTORRENT_TRACKERS.split(',').map(t => [t.trim()]) : [ - ["wss://tracker.openwebtorrent.com"], - ["wss://tracker.btorrent.xyz"], + ['wss://tracker.openwebtorrent.com'], + ['wss://tracker.btorrent.xyz'], ['wss://tracker.fastcast.nz'], ] -;function bootServer(server) { - const io = socketIO(server); - io.set("transports", ["polling"]); - io.on("connection", socket => { - let upload = null; +function bootServer(server) { + const io = socketIO(server) + io.set('transports', ['polling']) - socket.on("upload", (metadata, res) => { + io.on('connection', (socket) => { + let upload = null + + socket.on('upload', (metadata, res) => { if (upload) { return } db.create(socket).then(u => { - upload = u; - upload.fileName = metadata.fileName; - upload.fileSize = metadata.fileSize; - upload.fileType = metadata.fileType; - upload.infoHash = metadata.infoHash; - res({ token: upload.token, shortToken: upload.shortToken }); + upload = u + upload.fileName = metadata.fileName + upload.fileSize = metadata.fileSize + upload.fileType = metadata.fileType + upload.infoHash = metadata.infoHash + res({ token: upload.token, shortToken: upload.shortToken }) }) - }); + }) - socket.on("trackerConfig", (_, res) => { + socket.on('trackerConfig', (_, res) => { ice.getICEServers().then(iceServers => { - res({ rtcConfig: { iceServers }, announce: TRACKERS }); + res({ rtcConfig: { iceServers }, announce: TRACKERS }) }) - }); + }) - socket.on("disconnect", () => { - db.remove(upload); + socket.on('disconnect', () => { + db.remove(upload) }) - }); + }) - server.on("error", err => { - winston.error(err.message); - process.exit(1); + server.on('error', (err) => { + winston.error(err.message) + process.exit(1) }) server.listen(port, (err) => { - const host = server.address().address; - const port = server.address().port; - winston.info("FilePizza listening on %s:%s", host, port); + const host = server.address().address + const port = server.address().port + winston.info('FilePizza listening on %s:%s', host, port) }) } if (process.env.HTTPS_KEY && process.env.HTTPS_CERT) { // user-supplied HTTPS key/cert - const https = require("https"); + const https = require('https') + var server = https.createServer( { key: fs.readFileSync(process.env.HTTPS_KEY), @@ -103,7 +105,8 @@ if (process.env.HTTPS_KEY && process.env.HTTPS_CERT) { bootServer(server) } else { // no HTTPS - const http = require("http"); + const http = require('http') + var server = http.Server(app) bootServer(server) } diff --git a/src/stores/DownloadStore.js b/src/stores/DownloadStore.js index e399c4b..a2cfeac 100644 --- a/src/stores/DownloadStore.js +++ b/src/stores/DownloadStore.js @@ -1,13 +1,13 @@ -import socket from "filepizza-socket"; -import DownloadActions from "../actions/DownloadActions"; -import alt from "../alt"; -import { getClient } from '../wt'; +import socket from 'filepizza-socket' +import DownloadActions from '../actions/DownloadActions' +import alt from '../alt' +import { getClient } from '../wt' const SPEED_REFRESH_TIME = 2000 function downloadBlobURL(name, blobURL) { const a = document.createElement('a') -;document.body.appendChild(a) + document.body.appendChild(a) a.download = name a.href = blobURL a.click() @@ -18,15 +18,15 @@ export default alt.createStore( constructor() { this.bindActions(DownloadActions) - this.fileName = ""; + this.fileName = '' this.fileSize = 0 - this.fileType = ""; + this.fileType = '' this.infoHash = null - this.peers = 0; - this.progress = 0; - this.speedDown = 0; - this.speedUp = 0; - this.status = "uninitialized"; + this.peers = 0 + this.progress = 0 + this.speedDown = 0 + this.speedUp = 0 + this.status = 'uninitialized' this.token = null } @@ -34,7 +34,7 @@ export default alt.createStore( if (this.status !== 'ready') { return } - this.status = 'requesting'; + this.status = 'requesting' getClient().then(client => { client.add( @@ -51,12 +51,12 @@ export default alt.createStore( }) } torrent.on('upload', updateSpeed) - torrent.on("download", updateSpeed); - setInterval(updateSpeed, SPEED_REFRESH_TIME); + torrent.on('download', updateSpeed) + setInterval(updateSpeed, SPEED_REFRESH_TIME) - const file = torrent.files[0]; - const stream = file.createReadStream(); - stream.on("data", (chunk) => { + const file = torrent.files[0] + const stream = file.createReadStream() + stream.on('data', (chunk) => { if (this.status !== 'downloading') { return } @@ -68,15 +68,15 @@ export default alt.createStore( throw err } downloadBlobURL(this.fileName, blobURL) - }); + }) } else { this.setState({ progress: torrent.progress }) } }) }, ) - }); + }) } }, - 'DownloadStore' + 'DownloadStore', ) diff --git a/src/stores/ErrorStore.js b/src/stores/ErrorStore.js index 799d57c..59b4912 100644 --- a/src/stores/ErrorStore.js +++ b/src/stores/ErrorStore.js @@ -1,21 +1,21 @@ -import SupportActions from '../actions/SupportActions'; -import alt from '../alt'; +import SupportActions from '../actions/SupportActions' +import alt from '../alt' export default alt.createStore( class ErrorStore { constructor() { this.bindActions(SupportActions) - this.status = 404; - this.message = "Not Found"; + this.status = 404 + this.message = 'Not Found' this.stack = null } onNoSupport() { this.status = 400 - this.message = "No WebRTC Support. Please use Chrome or Firefox."; + this.message = 'No WebRTC Support. Please use Chrome or Firefox.' this.stack = null } }, - 'ErrorStore' + 'ErrorStore', ) diff --git a/src/stores/SupportStore.js b/src/stores/SupportStore.js index d9e0f55..a80f888 100644 --- a/src/stores/SupportStore.js +++ b/src/stores/SupportStore.js @@ -1,12 +1,12 @@ -import SupportActions from '../actions/SupportActions'; -import alt from '../alt'; +import SupportActions from '../actions/SupportActions' +import alt from '../alt' export default alt.createStore( class SupportStore { constructor() { this.bindActions(SupportActions) - this.isSupported = true; - this.isChrome = false; + this.isSupported = true + this.isChrome = false } onNoSupport() { @@ -17,5 +17,5 @@ export default alt.createStore( this.isChrome = true } }, - 'SupportStore' + 'SupportStore', ) diff --git a/src/stores/UploadStore.js b/src/stores/UploadStore.js index 5ea0a0e..872629d 100644 --- a/src/stores/UploadStore.js +++ b/src/stores/UploadStore.js @@ -1,31 +1,31 @@ -import socket from 'filepizza-socket'; -import UploadActions from '../actions/UploadActions'; -import alt from '../alt'; -import { getClient } from "../wt"; +import socket from 'filepizza-socket' +import UploadActions from '../actions/UploadActions' +import alt from '../alt' +import { getClient } from '../wt' -const SPEED_REFRESH_TIME = 2000; +const SPEED_REFRESH_TIME = 2000 export default alt.createStore( class UploadStore { constructor() { - this.bindActions(UploadActions); + this.bindActions(UploadActions) - this.fileName = ""; - this.fileSize = 0; - this.fileType = ""; - this.infoHash = null; - this.peers = 0; - this.speedUp = 0; - this.status = "ready"; - this.token = null; - this.shortToken = null; + this.fileName = '' + this.fileSize = 0 + this.fileType = '' + this.infoHash = null + this.peers = 0 + this.speedUp = 0 + this.status = 'ready' + this.token = null + this.shortToken = null } onUploadFile(file) { - if (this.status !== "ready") { - return; + if (this.status !== 'ready') { + return } - this.status = "processing"; + this.status = 'processing' getClient().then(client => { client.seed(file, { announce: client.tracker.announce }, torrent => { @@ -33,15 +33,15 @@ export default alt.createStore( this.setState({ speedUp: torrent.uploadSpeed, peers: torrent.numPeers, - }); + }) } - torrent.on("upload", updateSpeed); - torrent.on("download", updateSpeed); - setInterval(updateSpeed, SPEED_REFRESH_TIME); + torrent.on('upload', updateSpeed) + torrent.on('download', updateSpeed) + setInterval(updateSpeed, SPEED_REFRESH_TIME) socket.emit( - "upload", + 'upload', { fileName: file.name, fileSize: file.size, @@ -50,19 +50,19 @@ export default alt.createStore( }, (res) => { this.setState({ - status: "uploading", + status: 'uploading', token: res.token, shortToken: res.shortToken, fileName: file.name, fileSize: file.size, fileType: file.type, infoHash: torrent.magnetURI, - }); + }) }, - ); + ) }) - }); + }) } }, - "UploadStore" -); + 'UploadStore', +) diff --git a/src/toppings.js b/src/toppings.js deleted file mode 100644 index e6c63cd..0000000 --- a/src/toppings.js +++ /dev/null @@ -1,100 +0,0 @@ -export default [ - "alfalfa", - "almonds", - "anchovies", - "artichoke", - "avocado", - "bacon", - "basil", - "bayleaves", - "bbqchicken", - "beans", - "beef", - "beetroot", - "bluecheese", - "brie", - "broccoli", - "cajunchicken", - "camembert", - "capers", - "capicolla", - "cardamon", - "carrot", - "cauliflower", - "cheddar", - "chickenmasala", - "chickentikka", - "chili", - "chives", - "chorizo", - "cilantro", - "colby", - "coriander", - "crayfish", - "cumin", - "dill", - "duck", - "eggplant", - "fenugreek", - "feta", - "fungi", - "garlic", - "goatcheese", - "gorgonzola", - "gouda", - "ham", - "jalapeno", - "laurel", - "leeks", - "lettuce", - "limburger", - "lobster", - "manchego", - "marjoram", - "meatballs", - "melon", - "montereyjack", - "mozzarella", - "muenster", - "mushrooms", - "olives", - "onion", - "oregano", - "oysters", - "parsley", - "parmesan", - "peanuts", - "peas", - "pecans", - "pepperoni", - "peppers", - "pineapple", - "pinenuts", - "pistachios", - "prawn", - "prosciutto", - "provolone", - "ricotta", - "romano", - "roquefort", - "rosemary", - "salami", - "salmon", - "sausage", - "scallions", - "shallots", - "shrimp", - "snowpeas", - "spinach", - "squash", - "squid", - "sweetcorn", - "tomatoes", - "tuna", - "turkey", - "venison", - "walnuts", - "watercress", - "whitebait", - "zucchini", -] diff --git a/src/toppings.ts b/src/toppings.ts new file mode 100644 index 0000000..07c9755 --- /dev/null +++ b/src/toppings.ts @@ -0,0 +1,100 @@ +export default [ + 'alfalfa', + 'almonds', + 'anchovies', + 'artichoke', + 'avocado', + 'bacon', + 'basil', + 'bayleaves', + 'bbqchicken', + 'beans', + 'beef', + 'beetroot', + 'bluecheese', + 'brie', + 'broccoli', + 'cajunchicken', + 'camembert', + 'capers', + 'capicolla', + 'cardamon', + 'carrot', + 'cauliflower', + 'cheddar', + 'chickenmasala', + 'chickentikka', + 'chili', + 'chives', + 'chorizo', + 'cilantro', + 'colby', + 'coriander', + 'crayfish', + 'cumin', + 'dill', + 'duck', + 'eggplant', + 'fenugreek', + 'feta', + 'fungi', + 'garlic', + 'goatcheese', + 'gorgonzola', + 'gouda', + 'ham', + 'jalapeno', + 'laurel', + 'leeks', + 'lettuce', + 'limburger', + 'lobster', + 'manchego', + 'marjoram', + 'meatballs', + 'melon', + 'montereyjack', + 'mozzarella', + 'muenster', + 'mushrooms', + 'olives', + 'onion', + 'oregano', + 'oysters', + 'parsley', + 'parmesan', + 'peanuts', + 'peas', + 'pecans', + 'pepperoni', + 'peppers', + 'pineapple', + 'pinenuts', + 'pistachios', + 'prawn', + 'prosciutto', + 'provolone', + 'ricotta', + 'romano', + 'roquefort', + 'rosemary', + 'salami', + 'salmon', + 'sausage', + 'scallions', + 'shallots', + 'shrimp', + 'snowpeas', + 'spinach', + 'squash', + 'squid', + 'sweetcorn', + 'tomatoes', + 'tuna', + 'turkey', + 'venison', + 'walnuts', + 'watercress', + 'whitebait', + 'zucchini', +] diff --git a/src/util.js b/src/util.ts similarity index 82% rename from src/util.js rename to src/util.ts index 7bc5f30..7ff4847 100644 --- a/src/util.js +++ b/src/util.ts @@ -2,10 +2,10 @@ // http://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript export function formatSize(bytes) { if (bytes === 0) { - return '0 Bytes'; + return '0 Bytes' } const k = 1000 const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] -;const i = Math.floor(Math.log(bytes) / Math.log(k)) - return `${(bytes / Math.pow(k, i)).toPrecision(3)} ${sizes[i]}`; + const i = Math.floor(Math.log(bytes) / Math.log(k)) + return `${(bytes / Math.pow(k, i)).toPrecision(3)} ${sizes[i]}` } diff --git a/src/wt.js b/src/wt.ts similarity index 83% rename from src/wt.js rename to src/wt.ts index 41ac020..e601f64 100644 --- a/src/wt.js +++ b/src/wt.ts @@ -1,4 +1,4 @@ -import socket from 'filepizza-socket'; +import socket from 'filepizza-socket' export function getClient() { return new Promise((resolve, reject) => { @@ -7,6 +7,6 @@ export function getClient() { tracker: trackerConfig, }) resolve(client) - }); + }) }) }