mirror of https://github.com/kern/filepizza
Lint
parent
b830677033
commit
5c3306b9c6
@ -1,9 +1,8 @@
|
||||
import alt from '../alt'
|
||||
import alt from '../alt';
|
||||
|
||||
export default alt.createActions(class DownloadActions {
|
||||
constructor() {
|
||||
this.generateActions(
|
||||
'requestDownload'
|
||||
)
|
||||
}
|
||||
})
|
||||
constructor() {
|
||||
this.generateActions('requestDownload');
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
import alt from '../alt'
|
||||
import alt from '../alt';
|
||||
|
||||
export default alt.createActions(class SupportActions {
|
||||
constructor() {
|
||||
this.generateActions(
|
||||
'isChrome',
|
||||
'noSupport'
|
||||
)
|
||||
}
|
||||
})
|
||||
constructor() {
|
||||
this.generateActions('isChrome', 'noSupport');
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import alt from '../alt'
|
||||
import alt from '../alt';
|
||||
|
||||
export default alt.createActions(class UploadActions {
|
||||
constructor() {
|
||||
this.generateActions(
|
||||
'uploadFile'
|
||||
)
|
||||
}
|
||||
})
|
||||
constructor() {
|
||||
this.generateActions('uploadFile');
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
import Alt from 'alt'
|
||||
import Alt from 'alt';
|
||||
|
||||
export default new Alt()
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
import React from 'react'
|
||||
import React from 'react';
|
||||
|
||||
export default class Bootstrap extends React.Component {
|
||||
|
||||
render() {
|
||||
return <script
|
||||
id="bootstrap"
|
||||
type="application/json"
|
||||
dangerouslySetInnerHTML={{ __html: this.props.data}} />
|
||||
return (
|
||||
<script
|
||||
id="bootstrap"
|
||||
type="application/json"
|
||||
dangerouslySetInnerHTML={{ __html: this.props.data }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,43 +1,42 @@
|
||||
import React from 'react'
|
||||
import classnames from 'classnames'
|
||||
import React from "react";
|
||||
import classnames from "classnames";
|
||||
|
||||
function formatProgress(dec) {
|
||||
return (dec * 100).toPrecision(3) + "%"
|
||||
return `${(dec * 100).toPrecision(3) }%`
|
||||
}
|
||||
|
||||
export default class ProgressBar extends React.Component {
|
||||
|
||||
render() {
|
||||
const failed = this.props.value < 0;
|
||||
const inProgress = this.props.value < 1 && this.props.value >= 0;
|
||||
const classes = classnames('progress-bar', {
|
||||
'progress-bar-failed': failed,
|
||||
'progress-bar-in-progress': inProgress,
|
||||
'progress-bar-small': this.props.small
|
||||
})
|
||||
const failed = this.props.value < 0
|
||||
const inProgress = this.props.value < 1 && this.props.value >= 0
|
||||
const classes = classnames("progress-bar", {
|
||||
"progress-bar-failed": failed,
|
||||
"progress-bar-in-progress": inProgress,
|
||||
"progress-bar-small": this.props.small,
|
||||
});
|
||||
|
||||
const formatted = formatProgress(this.props.value)
|
||||
const formatted = formatProgress(this.props.value);
|
||||
|
||||
return <div className={classes}>
|
||||
{failed
|
||||
? <div className="progress-bar-text">Failed</div>
|
||||
: inProgress ? <div
|
||||
className="progress-bar-inner"
|
||||
style={{width: formatted}}>
|
||||
<div className="progress-bar-text">
|
||||
{formatted}
|
||||
return (
|
||||
<div className={classes}>
|
||||
{failed ? (
|
||||
<div className="progress-bar-text">Failed</div>
|
||||
) : inProgress ? (
|
||||
<div className="progress-bar-inner" style={{ width: formatted }}>
|
||||
<div className="progress-bar-text">{formatted}</div>
|
||||
</div>
|
||||
</div>
|
||||
: <div className="progress-bar-text">Delivered</div>}
|
||||
</div>
|
||||
) : (
|
||||
: <div className="progress-bar-text">Delivered</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ProgressBar.propTypes = {
|
||||
value: React.PropTypes.number.isRequired,
|
||||
small: React.PropTypes.bool
|
||||
}
|
||||
small: React.PropTypes.bool,
|
||||
};
|
||||
|
||||
ProgressBar.defaultProps = {
|
||||
small: false
|
||||
}
|
||||
small: false,
|
||||
};
|
||||
|
||||
@ -1,38 +1,41 @@
|
||||
import React from 'react'
|
||||
import classnames from 'classnames'
|
||||
import { formatSize } from '../util'
|
||||
import React from "react";
|
||||
import classnames from "classnames";
|
||||
import { formatSize } from "../util";
|
||||
|
||||
export default class Spinner extends React.Component {
|
||||
|
||||
render() {
|
||||
const classes = classnames('spinner', {
|
||||
'spinner-animated': this.props.animated
|
||||
})
|
||||
const classes = classnames("spinner", {
|
||||
"spinner-animated": this.props.animated,
|
||||
});
|
||||
|
||||
return <div className={classes}>
|
||||
<img
|
||||
alt={this.props.name || this.props.dir}
|
||||
src={`/images/${this.props.dir}.png`}
|
||||
className="spinner-image" />
|
||||
return (
|
||||
<div className={classes}>
|
||||
<img
|
||||
alt={this.props.name || this.props.dir}
|
||||
src={`/images/${this.props.dir}.png`}
|
||||
className="spinner-image"
|
||||
/>
|
||||
|
||||
{this.props.name === null ? null
|
||||
: <div className="spinner-name">{this.props.name}</div>}
|
||||
{this.props.size === null ? null
|
||||
: <div className="spinner-size">{formatSize(this.props.size)}</div>}
|
||||
</div>
|
||||
{this.props.name === null ? null
|
||||
: <div className="spinner-name">{this.props.name}</div>
|
||||
)}
|
||||
{this.props.size === null ? null
|
||||
: <div className="spinner-size">{formatSize(this.props.size)}</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Spinner.propTypes = {
|
||||
dir: React.PropTypes.oneOf(['up', 'down']).isRequired,
|
||||
dir: React.PropTypes.oneOf(["up", "down"]).isRequired,
|
||||
name: React.PropTypes.string,
|
||||
size: React.PropTypes.number,
|
||||
animated: React.PropTypes.bool
|
||||
}
|
||||
animated: React.PropTypes.bool,
|
||||
};
|
||||
|
||||
Spinner.defaultProps = {
|
||||
name: null,
|
||||
size: null,
|
||||
animated: false
|
||||
}
|
||||
animated: false,
|
||||
};
|
||||
|
||||
@ -1,90 +1,104 @@
|
||||
import DropZone from './DropZone'
|
||||
import React from 'react'
|
||||
import Spinner from './Spinner'
|
||||
import Tempalink from './Tempalink'
|
||||
import UploadActions from '../actions/UploadActions'
|
||||
import UploadStore from '../stores/UploadStore'
|
||||
import socket from 'filepizza-socket'
|
||||
import { formatSize } from '../util'
|
||||
import DropZone from './DropZone'
|
||||
import Spinner from "./Spinner";
|
||||
import Tempalink from "./Tempalink";
|
||||
import UploadActions from "../actions/UploadActions";
|
||||
import UploadStore from "../stores/UploadStore";
|
||||
import socket from "filepizza-socket";
|
||||
import { formatSize } from "../util";
|
||||
|
||||
export default class UploadPage extends React.Component {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.state = UploadStore.getState()
|
||||
super();
|
||||
this.state = UploadStore.getState();
|
||||
|
||||
this._onChange = () => {
|
||||
this.setState(UploadStore.getState())
|
||||
}
|
||||
this.setState(UploadStore.getState());
|
||||
};
|
||||
|
||||
this.uploadFile = this.uploadFile.bind(this)
|
||||
this.uploadFile = this.uploadFile.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
UploadStore.listen(this._onChange)
|
||||
UploadStore.listen(this._onChange);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
UploadStore.unlisten(this._onChange)
|
||||
UploadStore.unlisten(this._onChange);
|
||||
}
|
||||
|
||||
uploadFile(file) {
|
||||
UploadActions.uploadFile(file)
|
||||
UploadActions.uploadFile(file);
|
||||
}
|
||||
|
||||
handleSelectedFile(event) {
|
||||
let files = event.target.files
|
||||
const files = event.target.files;
|
||||
if (files.length > 0) {
|
||||
UploadActions.uploadFile(files[0])
|
||||
UploadActions.uploadFile(files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
switch (this.state.status) {
|
||||
case 'ready':
|
||||
|
||||
return <DropZone onDrop={this.uploadFile}>
|
||||
case "ready":
|
||||
return (
|
||||
<DropZone onDrop={this.uploadFile}>
|
||||
<div className="page">
|
||||
<Spinner dir="up" />
|
||||
|
||||
<h1>FilePizza</h1>
|
||||
<p>Free peer-to-peer file transfers in your browser.</p>
|
||||
<small className="notice">
|
||||
We never store anything. Files only served fresh.
|
||||
</small>
|
||||
<p>
|
||||
<label className="select-file-label">
|
||||
<input
|
||||
type="file"
|
||||
onChange={this.handleSelectedFile}
|
||||
required
|
||||
/>
|
||||
<span>select a file</span>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
</DropZone>
|
||||
);
|
||||
|
||||
case "processing":
|
||||
return (
|
||||
<div className="page">
|
||||
<Spinner dir="up" animated />
|
||||
|
||||
<Spinner dir="up" />
|
||||
<h1>FilePizza</h1>
|
||||
<p>Processing...</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
case "uploading":
|
||||
return (
|
||||
<div className="page">
|
||||
<h1>FilePizza</h1>
|
||||
<p>Free peer-to-peer file transfers in your browser.</p>
|
||||
<small className="notice">We never store anything. Files only served fresh.</small>
|
||||
<Spinner
|
||||
dir="up"
|
||||
animated
|
||||
name={this.state.fileName}
|
||||
size={this.state.fileSize}
|
||||
/>
|
||||
|
||||
<p>Send someone this link to download.</p>
|
||||
<small className="notice">
|
||||
This link will work as long as this page is open.
|
||||
</small>
|
||||
<p>
|
||||
<label className="select-file-label">
|
||||
<input type="file" onChange={this.handleSelectedFile} required/>
|
||||
<span>select a file</span>
|
||||
</label>
|
||||
Peers: {this.state.peers} · Up:{" "}
|
||||
{formatSize(this.state.speedUp)}
|
||||
</p>
|
||||
<Tempalink
|
||||
token={this.state.token}
|
||||
shortToken={this.state.shortToken}
|
||||
/>
|
||||
</div>
|
||||
</DropZone>
|
||||
|
||||
case 'processing':
|
||||
return <div className="page">
|
||||
|
||||
<Spinner dir="up" animated />
|
||||
|
||||
<h1>FilePizza</h1>
|
||||
<p>Processing...</p>
|
||||
|
||||
</div>
|
||||
|
||||
case 'uploading':
|
||||
return <div className="page">
|
||||
|
||||
<h1>FilePizza</h1>
|
||||
<Spinner dir="up" animated
|
||||
name={this.state.fileName}
|
||||
size={this.state.fileSize} />
|
||||
|
||||
<p>Send someone this link to download.</p>
|
||||
<small className="notice">This link will work as long as this page is open.</small>
|
||||
<p>Peers: {this.state.peers} · Up: {formatSize(this.state.speedUp)}</p>
|
||||
<Tempalink token={this.state.token} shortToken={this.state.shortToken} />
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,48 +1,51 @@
|
||||
var twilio = require("twilio");
|
||||
const twilio = require("twilio");
|
||||
var winston = require("winston");
|
||||
|
||||
if (process.env.TWILIO_SID && process.env.TWILIO_TOKEN) {
|
||||
var twilioSID = process.env.TWILIO_SID;
|
||||
var twilioToken = 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;
|
||||
}
|
||||
|
||||
var ICE_SERVERS = [
|
||||
let ICE_SERVERS = [
|
||||
{
|
||||
urls: "stun:stun.l.google.com:19302"
|
||||
}
|
||||
urls: "stun:stun.l.google.com:19302",
|
||||
},
|
||||
];
|
||||
|
||||
if (process.env.ICE_SERVERS) {
|
||||
ICE_SERVERS = JSON.parse(process.env.ICE_SERVERS)
|
||||
}
|
||||
|
||||
var CACHE_LIFETIME = 5 * 60 * 1000; // 5 minutes
|
||||
var cachedPromise = null;
|
||||
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;
|
||||
if (client == null) {
|
||||
return Promise.resolve(ICE_SERVERS)
|
||||
}
|
||||
if (cachedPromise) {
|
||||
return cachedPromise
|
||||
}
|
||||
|
||||
cachedPromise = new Promise(function(resolve, reject) {
|
||||
client.tokens.create({}, function(err, token) {
|
||||
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);
|
||||
;setTimeout(clearCache, CACHE_LIFETIME)
|
||||
resolve(token.ice_servers);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
return cachedPromise;
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,19 +1,18 @@
|
||||
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
|
||||
|
||||
var status = err.status || 500
|
||||
var message = err.message || ''
|
||||
var stack = process.env.NODE_ENV === 'production' ? null : err.stack || null
|
||||
|
||||
req.url = '/error'
|
||||
req.url = '/error';
|
||||
res.status(status)
|
||||
res.locals.data = {
|
||||
ErrorStore: {
|
||||
status: status,
|
||||
message: message,
|
||||
stack: stack
|
||||
}
|
||||
status,
|
||||
message,
|
||||
stack,
|
||||
},
|
||||
}
|
||||
|
||||
next()
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
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))
|
||||
}
|
||||
|
||||
@ -1,30 +1,29 @@
|
||||
var React = require('react')
|
||||
var ReactRouter = require('react-router')
|
||||
var alt = require('../alt')
|
||||
var routes = require('../routes')
|
||||
|
||||
function isNotFound(state) {
|
||||
for (var r of state.routes) {
|
||||
if (r.isNotFound) return true
|
||||
const React = require('react')
|
||||
;let ReactRouter = require('react-router')
|
||||
;let alt = require('../alt')
|
||||
;let routes = require('../routes')
|
||||
;function isNotFound(state) {
|
||||
for (const r of state.routes) {
|
||||
if (r.isNotFound) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
module.exports = function (req, res) {
|
||||
|
||||
alt.bootstrap(JSON.stringify(res.locals.data || {}))
|
||||
|
||||
ReactRouter.run(routes, req.url, function (Handler, state) {
|
||||
|
||||
var html = React.renderToString(<Handler data={alt.takeSnapshot()} />)
|
||||
|
||||
ReactRouter.run(routes, req.url, (Handler, state) => {
|
||||
const html = React.renderToString(<Handler data={alt.takeSnapshot()} />);
|
||||
alt.flush()
|
||||
|
||||
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
if (isNotFound(state)) res.status(404)
|
||||
;;if (isNotFound(state)) {
|
||||
res.status(404);
|
||||
}
|
||||
res.write('<!DOCTYPE html>\n')
|
||||
res.end(html)
|
||||
|
||||
})
|
||||
|
||||
;;res.end(html)
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
var express = require('express')
|
||||
var path = require('path')
|
||||
|
||||
var STATIC_PATH = path.resolve(__dirname, '../static')
|
||||
|
||||
module.exports = express.static(STATIC_PATH)
|
||||
const path = require("path");
|
||||
const express = require("express");
|
||||
let STATIC_PATH = path.resolve(__dirname, "../static");
|
||||
module.exports = express.static(STATIC_PATH);
|
||||
|
||||
@ -1,73 +1,82 @@
|
||||
import DownloadActions from '../actions/DownloadActions'
|
||||
import alt from '../alt'
|
||||
import socket from 'filepizza-socket'
|
||||
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) {
|
||||
let a = document.createElement('a')
|
||||
document.body.appendChild(a)
|
||||
const a = document.createElement('a')
|
||||
;document.body.appendChild(a)
|
||||
a.download = name
|
||||
a.href = blobURL
|
||||
a.click()
|
||||
}
|
||||
|
||||
export default alt.createStore(class DownloadStore {
|
||||
export default alt.createStore(
|
||||
class DownloadStore {
|
||||
constructor() {
|
||||
this.bindActions(DownloadActions)
|
||||
|
||||
constructor() {
|
||||
this.bindActions(DownloadActions)
|
||||
this.fileName = "";
|
||||
this.fileSize = 0
|
||||
this.fileType = "";
|
||||
this.infoHash = null
|
||||
this.peers = 0;
|
||||
this.progress = 0;
|
||||
this.speedDown = 0;
|
||||
this.speedUp = 0;
|
||||
this.status = "uninitialized";
|
||||
this.token = null
|
||||
}
|
||||
|
||||
this.fileName = ''
|
||||
this.fileSize = 0
|
||||
this.fileType = ''
|
||||
this.infoHash = null
|
||||
this.peers = 0
|
||||
this.progress = 0
|
||||
this.speedDown = 0
|
||||
this.speedUp = 0
|
||||
this.status = 'uninitialized'
|
||||
this.token = null
|
||||
}
|
||||
onRequestDownload() {
|
||||
if (this.status !== 'ready') {
|
||||
return
|
||||
}
|
||||
this.status = 'requesting';
|
||||
|
||||
onRequestDownload() {
|
||||
if (this.status !== 'ready') return
|
||||
this.status = 'requesting'
|
||||
getClient().then(client => {
|
||||
client.add(
|
||||
this.infoHash,
|
||||
{ announce: client.tracker.announce },
|
||||
(torrent) => {
|
||||
this.setState({ status: 'downloading' })
|
||||
|
||||
getClient().then(client => {
|
||||
client.add(this.infoHash, { announce: client.tracker.announce }, (torrent) => {
|
||||
this.setState({ status: 'downloading' })
|
||||
const updateSpeed = () => {
|
||||
this.setState({
|
||||
speedUp: torrent.uploadSpeed,
|
||||
speedDown: torrent.downloadSpeed,
|
||||
peers: torrent.numPeers,
|
||||
})
|
||||
}
|
||||
torrent.on('upload', updateSpeed)
|
||||
torrent.on("download", updateSpeed);
|
||||
setInterval(updateSpeed, SPEED_REFRESH_TIME);
|
||||
|
||||
const updateSpeed = () => {
|
||||
this.setState({
|
||||
speedUp: torrent.uploadSpeed,
|
||||
speedDown: torrent.downloadSpeed,
|
||||
peers: torrent.numPeers
|
||||
})
|
||||
}
|
||||
const file = torrent.files[0];
|
||||
const stream = file.createReadStream();
|
||||
stream.on("data", (chunk) => {
|
||||
if (this.status !== 'downloading') {
|
||||
return
|
||||
}
|
||||
|
||||
torrent.on('upload', updateSpeed)
|
||||
torrent.on('download', updateSpeed)
|
||||
setInterval(updateSpeed, SPEED_REFRESH_TIME)
|
||||
|
||||
const file = torrent.files[0]
|
||||
const stream = file.createReadStream()
|
||||
stream.on('data', (chunk) => {
|
||||
if (this.status !== 'downloading') return
|
||||
|
||||
if (torrent.progress === 1) {
|
||||
this.setState({ status: 'done', progress: 1 })
|
||||
file.getBlobURL((err, blobURL) => {
|
||||
if (err) throw err
|
||||
downloadBlobURL(this.fileName, blobURL)
|
||||
if (torrent.progress === 1) {
|
||||
this.setState({ status: 'done', progress: 1 })
|
||||
file.getBlobURL((err, blobURL) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
downloadBlobURL(this.fileName, blobURL)
|
||||
});
|
||||
} else {
|
||||
this.setState({ progress: torrent.progress })
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.setState({ progress: torrent.progress })
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}, 'DownloadStore')
|
||||
},
|
||||
)
|
||||
});
|
||||
}
|
||||
},
|
||||
'DownloadStore'
|
||||
)
|
||||
|
||||
@ -1,20 +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 {
|
||||
export default alt.createStore(
|
||||
class ErrorStore {
|
||||
constructor() {
|
||||
this.bindActions(SupportActions)
|
||||
|
||||
constructor() {
|
||||
this.bindActions(SupportActions)
|
||||
this.status = 404;
|
||||
this.message = "Not Found";
|
||||
this.stack = null
|
||||
}
|
||||
|
||||
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.stack = null
|
||||
}
|
||||
|
||||
}, 'ErrorStore')
|
||||
onNoSupport() {
|
||||
this.status = 400
|
||||
this.message = "No WebRTC Support. Please use Chrome or Firefox.";
|
||||
this.stack = null
|
||||
}
|
||||
},
|
||||
'ErrorStore'
|
||||
)
|
||||
|
||||
@ -1,20 +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 SupportStore {
|
||||
export default alt.createStore(
|
||||
class SupportStore {
|
||||
constructor() {
|
||||
this.bindActions(SupportActions)
|
||||
this.isSupported = true;
|
||||
this.isChrome = false;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.bindActions(SupportActions)
|
||||
this.isSupported = true
|
||||
this.isChrome = false
|
||||
}
|
||||
onNoSupport() {
|
||||
this.isSupported = false
|
||||
}
|
||||
|
||||
onNoSupport() {
|
||||
this.isSupported = false
|
||||
}
|
||||
|
||||
onIsChrome() {
|
||||
this.isChrome = true
|
||||
}
|
||||
|
||||
}, 'SupportStore')
|
||||
onIsChrome() {
|
||||
this.isChrome = true
|
||||
}
|
||||
},
|
||||
'SupportStore'
|
||||
)
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
// Taken from StackOverflow
|
||||
// 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'
|
||||
if (bytes === 0) {
|
||||
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]}`;
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import socket from 'filepizza-socket'
|
||||
import socket from 'filepizza-socket';
|
||||
|
||||
export function getClient() {
|
||||
return new Promise((resolve, reject) => {
|
||||
socket.emit('trackerConfig', {}, (trackerConfig) => {
|
||||
const client = new WebTorrent({
|
||||
tracker: trackerConfig
|
||||
tracker: trackerConfig,
|
||||
})
|
||||
resolve(client)
|
||||
})
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue