From 5eb9f91003c38819379d05ac50d3eb3c27dfc56c Mon Sep 17 00:00:00 2001 From: Alex Kern Date: Mon, 27 Apr 2015 20:41:54 -0700 Subject: [PATCH] Reorganize the JS files. --- .gitignore | 4 +- LICENSE | 24 +++------- README.md | 2 +- client/peer.js | 37 --------------- client/socket.js | 8 ---- {client => lib}/ChunkedBlob.js | 16 +++---- {client => lib}/DownloadFile.js | 0 {client => lib}/UploadFile.js | 0 {client => lib}/actions/DownloadActions.js | 2 +- {client => lib}/actions/UploadActions.js | 2 +- {client => lib}/alt.js | 0 client/index.js => lib/client.js | 0 {client => lib}/components/App.js | 0 {client => lib}/components/Centered.js | 0 {client => lib}/components/DownloadButton.js | 0 {client => lib}/components/DownloadPage.js | 2 +- {client => lib}/components/DropZone.js | 0 {client => lib}/components/ErrorPage.js | 5 +++ {client => lib}/components/ProgressBar.js | 0 {client => lib}/components/Spinner.js | 0 {client => lib}/components/Tempalink.js | 0 {client => lib}/components/UploadPage.js | 2 +- {client => lib}/components/Uploader.js | 4 +- lib/db.js | 45 +++++++++++++++++++ .../routes => lib/middleware}/bootstrap.js | 4 +- {server/routes => lib/middleware}/css.js | 0 {server/routes => lib/middleware}/error.js | 6 ++- .../routes => lib/middleware}/javascript.js | 2 +- {server/routes => lib/middleware}/react.js | 6 +-- {server/routes => lib/middleware}/static.js | 0 {client => lib}/routes.js | 0 server/index.js => lib/server.js | 20 ++++----- {client => lib}/stores/DownloadStore.js | 4 +- {client => lib}/stores/ErrorStore.js | 1 + {client => lib}/stores/UploadStore.js | 4 +- node_modules/filepizza-peer/client.js | 31 +++++++++++++ node_modules/filepizza-peer/package.json | 11 +++++ node_modules/filepizza-peer/server.js | 5 +++ node_modules/filepizza-socket/client.js | 2 + node_modules/filepizza-socket/package.json | 10 +++++ node_modules/filepizza-socket/server.js | 1 + package.json | 13 +++--- server/Upload.js | 42 ----------------- 43 files changed, 167 insertions(+), 148 deletions(-) delete mode 100644 client/peer.js delete mode 100644 client/socket.js rename {client => lib}/ChunkedBlob.js (64%) rename {client => lib}/DownloadFile.js (100%) rename {client => lib}/UploadFile.js (100%) rename {client => lib}/actions/DownloadActions.js (86%) rename {client => lib}/actions/UploadActions.js (87%) rename {client => lib}/alt.js (100%) rename client/index.js => lib/client.js (100%) rename {client => lib}/components/App.js (100%) rename {client => lib}/components/Centered.js (100%) rename {client => lib}/components/DownloadButton.js (100%) rename {client => lib}/components/DownloadPage.js (98%) rename {client => lib}/components/DropZone.js (100%) rename {client => lib}/components/ErrorPage.js (86%) rename {client => lib}/components/ProgressBar.js (100%) rename {client => lib}/components/Spinner.js (100%) rename {client => lib}/components/Tempalink.js (100%) rename {client => lib}/components/UploadPage.js (98%) rename {client => lib}/components/Uploader.js (88%) create mode 100644 lib/db.js rename {server/routes => lib/middleware}/bootstrap.js (83%) rename {server/routes => lib/middleware}/css.js (100%) rename {server/routes => lib/middleware}/error.js (63%) rename {server/routes => lib/middleware}/javascript.js (71%) rename {server/routes => lib/middleware}/react.js (75%) rename {server/routes => lib/middleware}/static.js (100%) rename {client => lib}/routes.js (100%) rename server/index.js => lib/server.js (69%) rename {client => lib}/stores/DownloadStore.js (95%) rename {client => lib}/stores/ErrorStore.js (88%) rename {client => lib}/stores/UploadStore.js (95%) create mode 100644 node_modules/filepizza-peer/client.js create mode 100644 node_modules/filepizza-peer/package.json create mode 100644 node_modules/filepizza-peer/server.js create mode 100644 node_modules/filepizza-socket/client.js create mode 100644 node_modules/filepizza-socket/package.json create mode 100644 node_modules/filepizza-socket/server.js delete mode 100644 server/Upload.js diff --git a/.gitignore b/.gitignore index 820548a..a31eec8 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,9 @@ build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- -node_modules +node_modules/* +!node_modules/filepizza-peer +!node_modules/filepizza-socket # Users Environment Variables .lock-wscript diff --git a/LICENSE b/LICENSE index e0d2e01..a3da806 100644 --- a/LICENSE +++ b/LICENSE @@ -1,22 +1,12 @@ -The MIT License (MIT) +Copyright (c) 2015, Alex Kern +All rights reserved. -Copyright (c) 2015 Alexander Kern +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index 0f2a753..8dd2fb1 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ Peer-to-peer file transfers in your browser ## License -MIT +BSD diff --git a/client/peer.js b/client/peer.js deleted file mode 100644 index 3a75776..0000000 --- a/client/peer.js +++ /dev/null @@ -1,37 +0,0 @@ -import uuid from 'node-uuid' - -const id = uuid.v4() - -if (typeof window === 'undefined') { - var peer = { id: id } -} else { - let Peer = require('peerjs') - var peer = new Peer(id, { - host: window.location.hostname, - port: window.location.port, - path: '/peer', - config: { - iceServers: [{ - 'url': 'stun:stun.l.google.com:19302' - }, { - 'url': 'turn:52.12.205.113:3478?transport=udp', - 'username': 'file', - 'credential': 'pizza' - }, { - 'url': 'turn:52.12.205.113:80?transport=udp', - 'username': 'file', - 'credential': 'pizza' - }, { - 'url': 'turn:52.12.205.113:3478?transport=tcp', - 'username': 'file', - 'credential': 'pizza' - }, { - 'url': 'turn:52.12.205.113:80?transport=tcp', - 'username': 'file', - 'credential': 'pizza' - }] - } - }) -} - -export default peer diff --git a/client/socket.js b/client/socket.js deleted file mode 100644 index a0b6e80..0000000 --- a/client/socket.js +++ /dev/null @@ -1,8 +0,0 @@ -if (typeof window === 'undefined') { - var socket = {}; -} else { - let io = require('socket.io-client'); - var socket = io.connect(); -} - -export default socket; diff --git a/client/ChunkedBlob.js b/lib/ChunkedBlob.js similarity index 64% rename from client/ChunkedBlob.js rename to lib/ChunkedBlob.js index 4f33936..81b28f3 100644 --- a/client/ChunkedBlob.js +++ b/lib/ChunkedBlob.js @@ -1,21 +1,21 @@ -const rankSize = 16; +const rankSize = 16 function blobLength(b) { - if (typeof b.byteLength !== 'undefined') return b.byteLength; - if (typeof b.size !== 'undefined') return b.size; - return b.length; + if (typeof b.byteLength !== 'undefined') return b.byteLength + if (typeof b.size !== 'undefined') return b.size + return b.length } export default class ChunkedBlob { constructor() { - this.size = 0; - this.ranks = [[]]; + this.size = 0 + this.ranks = [[]] } add(b) { - this.size += blobLength(b); - this.ranks[0].push(b); + this.size += blobLength(b) + this.ranks[0].push(b) for (let i = 0; i < this.ranks.length; i++) { let rank = this.ranks[i] diff --git a/client/DownloadFile.js b/lib/DownloadFile.js similarity index 100% rename from client/DownloadFile.js rename to lib/DownloadFile.js diff --git a/client/UploadFile.js b/lib/UploadFile.js similarity index 100% rename from client/UploadFile.js rename to lib/UploadFile.js diff --git a/client/actions/DownloadActions.js b/lib/actions/DownloadActions.js similarity index 86% rename from client/actions/DownloadActions.js rename to lib/actions/DownloadActions.js index 42551f8..9cdfe8e 100644 --- a/client/actions/DownloadActions.js +++ b/lib/actions/DownloadActions.js @@ -1,4 +1,4 @@ -import alt from '../alt'; +import alt from '../alt' export default alt.createActions(class DownloadActions { constructor() { diff --git a/client/actions/UploadActions.js b/lib/actions/UploadActions.js similarity index 87% rename from client/actions/UploadActions.js rename to lib/actions/UploadActions.js index 92a2640..42a3099 100644 --- a/client/actions/UploadActions.js +++ b/lib/actions/UploadActions.js @@ -1,4 +1,4 @@ -import alt from '../alt'; +import alt from '../alt' export default alt.createActions(class UploadActions { constructor() { diff --git a/client/alt.js b/lib/alt.js similarity index 100% rename from client/alt.js rename to lib/alt.js diff --git a/client/index.js b/lib/client.js similarity index 100% rename from client/index.js rename to lib/client.js diff --git a/client/components/App.js b/lib/components/App.js similarity index 100% rename from client/components/App.js rename to lib/components/App.js diff --git a/client/components/Centered.js b/lib/components/Centered.js similarity index 100% rename from client/components/Centered.js rename to lib/components/Centered.js diff --git a/client/components/DownloadButton.js b/lib/components/DownloadButton.js similarity index 100% rename from client/components/DownloadButton.js rename to lib/components/DownloadButton.js diff --git a/client/components/DownloadPage.js b/lib/components/DownloadPage.js similarity index 98% rename from client/components/DownloadPage.js rename to lib/components/DownloadPage.js index 274c0ff..6da838b 100644 --- a/client/components/DownloadPage.js +++ b/lib/components/DownloadPage.js @@ -5,7 +5,7 @@ import DownloadStore from '../stores/DownloadStore' import ProgressBar from './ProgressBar' import React from 'react' import Spinner from './Spinner' -import peer from '../peer' +import peer from 'filepizza-peer' export default class DownloadPage extends React.Component { diff --git a/client/components/DropZone.js b/lib/components/DropZone.js similarity index 100% rename from client/components/DropZone.js rename to lib/components/DropZone.js diff --git a/client/components/ErrorPage.js b/lib/components/ErrorPage.js similarity index 86% rename from client/components/ErrorPage.js rename to lib/components/ErrorPage.js index a4bc4a7..7037427 100644 --- a/client/components/ErrorPage.js +++ b/lib/components/ErrorPage.js @@ -23,6 +23,11 @@ export default class ErrorPage extends React.Component { return

{this.state.status}

{this.state.message}

+ + {this.state.stack + ?
{this.state.stack}
+ : null} +
} diff --git a/client/components/ProgressBar.js b/lib/components/ProgressBar.js similarity index 100% rename from client/components/ProgressBar.js rename to lib/components/ProgressBar.js diff --git a/client/components/Spinner.js b/lib/components/Spinner.js similarity index 100% rename from client/components/Spinner.js rename to lib/components/Spinner.js diff --git a/client/components/Tempalink.js b/lib/components/Tempalink.js similarity index 100% rename from client/components/Tempalink.js rename to lib/components/Tempalink.js diff --git a/client/components/UploadPage.js b/lib/components/UploadPage.js similarity index 98% rename from client/components/UploadPage.js rename to lib/components/UploadPage.js index d20dbb7..c72f17b 100644 --- a/client/components/UploadPage.js +++ b/lib/components/UploadPage.js @@ -6,7 +6,7 @@ import Spinner from './Spinner' import Tempalink from './Tempalink' import UploadActions from '../actions/UploadActions' import UploadStore from '../stores/UploadStore' -import socket from '../socket' +import socket from 'filepizza-socket' export default class UploadPage extends React.Component { diff --git a/client/components/Uploader.js b/lib/components/Uploader.js similarity index 88% rename from client/components/Uploader.js rename to lib/components/Uploader.js index 92cba63..449ec25 100644 --- a/client/components/Uploader.js +++ b/lib/components/Uploader.js @@ -1,6 +1,6 @@ -import Arrow from './Arrow'; +import Arrow from '@app/components/Arrow'; import React from 'react'; -import UploadActions from '../actions/UploadActions'; +import UploadActions from '@app/actions/UploadActions'; export default class UploadPage extends React.Component { diff --git a/lib/db.js b/lib/db.js new file mode 100644 index 0000000..d5e695c --- /dev/null +++ b/lib/db.js @@ -0,0 +1,45 @@ +import bases from 'bases' +import crypto from 'crypto' + +var tokenLength = 8 +var tokens = {} + +exports.create = function (socket) { + + var maxNum = Math.pow(62, tokenLength) + var numBytes = Math.ceil(Math.log(maxNum) / Math.log(256)) + + var token = '' + do { + do { + var bytes = crypto.randomBytes(numBytes) + var num = 0 + for (var i = 0; i < bytes.length; i++) { + num += Math.pow(256, i) * bytes[i] + } + } while (num >= maxNum) + + token = bases.toBase62(num) + } while (token in tokens) + + const result = { + token: token, + socket: socket + } + + tokens[token] = result + return result + +} + +exports.exists = function (token) { + return token in tokens +} + +exports.find = function (token) { + return tokens[token] +} + +exports.remove = function (client) { + delete tokens[client.token] +} diff --git a/server/routes/bootstrap.js b/lib/middleware/bootstrap.js similarity index 83% rename from server/routes/bootstrap.js rename to lib/middleware/bootstrap.js index 13a19b9..f10d888 100644 --- a/server/routes/bootstrap.js +++ b/lib/middleware/bootstrap.js @@ -1,11 +1,11 @@ -var Upload = require('../Upload') +var db = require('../db') var express = require('express') var routes = module.exports = new express.Router() routes.get('/d/:token', function (req, res, next) { - var uploader = Upload.find(req.params.token) + var uploader = db.find(req.params.token) if (uploader) { res.locals.data = { DownloadStore: { diff --git a/server/routes/css.js b/lib/middleware/css.js similarity index 100% rename from server/routes/css.js rename to lib/middleware/css.js diff --git a/server/routes/error.js b/lib/middleware/error.js similarity index 63% rename from server/routes/error.js rename to lib/middleware/error.js index 0e08d4f..c02ab0e 100644 --- a/server/routes/error.js +++ b/lib/middleware/error.js @@ -2,13 +2,17 @@ module.exports = function (err, req, res, next) { var status = err.status || 500 var message = err.message || '' + var stack = process.env.NODE_ENV === 'production' ? null : err.stack || null + + console.log(err) req.url = '/error' res.status(status) res.locals.data = { ErrorStore: { status: status, - message: message + message: message, + stack: stack } } diff --git a/server/routes/javascript.js b/lib/middleware/javascript.js similarity index 71% rename from server/routes/javascript.js rename to lib/middleware/javascript.js index 38fdc0c..831047d 100644 --- a/server/routes/javascript.js +++ b/lib/middleware/javascript.js @@ -2,7 +2,7 @@ var browserify = require('browserify-middleware') var express = require('express') var path = require('path') -var CLIENT_MODULE_PATH = path.resolve(__dirname, '../../client/index.js') +var CLIENT_MODULE_PATH = path.resolve(__dirname, '../client.js') module.exports = browserify(CLIENT_MODULE_PATH, { transform: 'babelify' diff --git a/server/routes/react.js b/lib/middleware/react.js similarity index 75% rename from server/routes/react.js rename to lib/middleware/react.js index 6144597..eefaea9 100644 --- a/server/routes/react.js +++ b/lib/middleware/react.js @@ -1,7 +1,7 @@ var React = require('react') var ReactRouter = require('react-router') -var alt = require('../../client/alt') -var clientRoutes = require('../../client/routes') +var alt = require('../alt') +var routes = require('../routes') function isNotFound(state) { for (var r of state.routes) { @@ -15,7 +15,7 @@ module.exports = function (req, res) { alt.bootstrap(JSON.stringify(res.locals.data || {})) - ReactRouter.run(clientRoutes, req.url, function (Handler, state) { + ReactRouter.run(routes, req.url, function (Handler, state) { var html = React.renderToString() alt.flush() diff --git a/server/routes/static.js b/lib/middleware/static.js similarity index 100% rename from server/routes/static.js rename to lib/middleware/static.js diff --git a/client/routes.js b/lib/routes.js similarity index 100% rename from client/routes.js rename to lib/routes.js diff --git a/server/index.js b/lib/server.js similarity index 69% rename from server/index.js rename to lib/server.js index a648e9f..3af60cb 100644 --- a/server/index.js +++ b/lib/server.js @@ -1,4 +1,4 @@ -var Upload = require('./Upload') +var db = require('./db') var express = require('express') var http = require('http') var path = require('path') @@ -19,14 +19,14 @@ server.listen(process.env.PORT || 3000, function () { app.use('/peer', peer.ExpressPeerServer(server)) app.use(morgan('dev')) -app.get('/js', require('./routes/javascript')) -app.get('/css', require('./routes/css')) -app.use(require('./routes/static')) +app.get('/js', require('./middleware/javascript')) +app.get('/css', require('./middleware/css')) +app.use(require('./middleware/static')) app.use([ - require('./routes/bootstrap'), - require('./routes/error'), - require('./routes/react') + require('./middleware/bootstrap'), + require('./middleware/error'), + require('./middleware/react') ]) io.on('connection', function (socket) { @@ -34,19 +34,19 @@ io.on('connection', function (socket) { var upload = null socket.on('upload', function (metadata, res) { - if (!upload) upload = new Upload(socket) + if (!upload) upload = db.create(socket) upload.metadata = metadata res(upload.token) }) socket.on('download', function (data) { - var uploader = Upload.find(data.token) + var uploader = db.find(data.token) if (!uploader) return uploader.socket.emit('download', data.peerID) }) socket.on('disconnect', function () { - if (upload) Upload.remove(upload) + if (upload) db.remove(upload) }) }) diff --git a/client/stores/DownloadStore.js b/lib/stores/DownloadStore.js similarity index 95% rename from client/stores/DownloadStore.js rename to lib/stores/DownloadStore.js index da35881..786dde6 100644 --- a/client/stores/DownloadStore.js +++ b/lib/stores/DownloadStore.js @@ -1,8 +1,8 @@ import DownloadActions from '../actions/DownloadActions' import DownloadFile from '../DownloadFile' -import peer from '../peer' +import peer from 'filepizza-peer' import alt from '../alt' -import socket from '../socket' +import socket from 'filepizza-socket' export default alt.createStore(class DownloadStore { diff --git a/client/stores/ErrorStore.js b/lib/stores/ErrorStore.js similarity index 88% rename from client/stores/ErrorStore.js rename to lib/stores/ErrorStore.js index 22194ff..f10a684 100644 --- a/client/stores/ErrorStore.js +++ b/lib/stores/ErrorStore.js @@ -5,6 +5,7 @@ export default alt.createStore(class ErrorStore { constructor() { this.status = 404 this.message = 'Not Found' + this.stack = null } }, 'ErrorStore') diff --git a/client/stores/UploadStore.js b/lib/stores/UploadStore.js similarity index 95% rename from client/stores/UploadStore.js rename to lib/stores/UploadStore.js index 07f2198..79a179a 100644 --- a/client/stores/UploadStore.js +++ b/lib/stores/UploadStore.js @@ -1,8 +1,8 @@ import UploadActions from '../actions/UploadActions' import UploadFile from '../UploadFile' import alt from '../alt' -import peer from '../peer' -import socket from '../socket' +import peer from 'filepizza-peer' +import socket from 'filepizza-socket' export default alt.createStore(class UploadStore { diff --git a/node_modules/filepizza-peer/client.js b/node_modules/filepizza-peer/client.js new file mode 100644 index 0000000..8850238 --- /dev/null +++ b/node_modules/filepizza-peer/client.js @@ -0,0 +1,31 @@ +var Peer = require('peerjs') +var uuid = require('node-uuid') + +var id = uuid.v4() + +module.exports = new Peer(id, { + host: window.location.hostname, + port: window.location.port, + path: '/peer', + config: { + iceServers: [{ + 'url': 'stun:stun.l.google.com:19302' + }, { + 'url': 'turn:52.12.205.113:3478?transport=udp', + 'username': 'file', + 'credential': 'pizza' + }, { + 'url': 'turn:52.12.205.113:80?transport=udp', + 'username': 'file', + 'credential': 'pizza' + }, { + 'url': 'turn:52.12.205.113:3478?transport=tcp', + 'username': 'file', + 'credential': 'pizza' + }, { + 'url': 'turn:52.12.205.113:80?transport=tcp', + 'username': 'file', + 'credential': 'pizza' + }] + } +}) diff --git a/node_modules/filepizza-peer/package.json b/node_modules/filepizza-peer/package.json new file mode 100644 index 0000000..5233088 --- /dev/null +++ b/node_modules/filepizza-peer/package.json @@ -0,0 +1,11 @@ +{ + "name": "filepizza-peer", + "version": "0.0.0", + "main": "server.js", + "browser": "client.js", + "author": "Alex Kern ", + "dependencies": { + "peerjs": "^0.3.14", + "node-uuid": "^1.4.3" + } +} diff --git a/node_modules/filepizza-peer/server.js b/node_modules/filepizza-peer/server.js new file mode 100644 index 0000000..f0f8e47 --- /dev/null +++ b/node_modules/filepizza-peer/server.js @@ -0,0 +1,5 @@ +var uuid = require('node-uuid') + +var id = uuid.v4() + +module.exports = { id: id } diff --git a/node_modules/filepizza-socket/client.js b/node_modules/filepizza-socket/client.js new file mode 100644 index 0000000..029ec6b --- /dev/null +++ b/node_modules/filepizza-socket/client.js @@ -0,0 +1,2 @@ +var io = require('socket.io-client') +module.exports = io.connect() diff --git a/node_modules/filepizza-socket/package.json b/node_modules/filepizza-socket/package.json new file mode 100644 index 0000000..59ad8e0 --- /dev/null +++ b/node_modules/filepizza-socket/package.json @@ -0,0 +1,10 @@ +{ + "name": "filepizza-socket", + "version": "0.0.0", + "main": "server.js", + "browser": "client.js", + "author": "Alex Kern ", + "dependencies": { + "socket.io-client": "^1.3.5" + } +} diff --git a/node_modules/filepizza-socket/server.js b/node_modules/filepizza-socket/server.js new file mode 100644 index 0000000..4ba52ba --- /dev/null +++ b/node_modules/filepizza-socket/server.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/package.json b/package.json index 17b946b..6ba2c8d 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,16 @@ "name": "filepizza", "version": "0.0.0", "description": "Peer-to-peer file transfers in your browser", - "main": "server/index.js", + "main": "lib/server.js", "scripts": { - "start": "./node_modules/.bin/babel-node server/index.js" + "start": "./node_modules/.bin/babel-node lib/server.js" }, "repository": { "type": "git", "url": "git@github.com:kern/filepizza.git" }, "author": "Alex Kern ", - "license": "MIT", + "license": "BSD", "bugs": { "url": "https://github.com/kern/filepizza/issues" }, @@ -27,15 +27,14 @@ "express": "^4.12.0", "morgan": "^1.5.2", "nib": "^1.1.0", - "node-uuid": "^1.4.3", "peer": "^0.2.8", - "peerjs": "^0.3.14", "react": "^0.13.0", "react-frozenhead": "^0.3.0", "react-router": "^0.13.1", "socket.io": "^1.3.5", - "socket.io-client": "^1.3.5", - "stylus": "^0.50.0" + "stylus": "^0.50.0", + "filepizza-socket": "./node_modules/filepizza-socket", + "filepizza-peer": "./node_modules/filepizza-peer" }, "engines": { "node": "0.10.x" diff --git a/server/Upload.js b/server/Upload.js deleted file mode 100644 index a9f30c9..0000000 --- a/server/Upload.js +++ /dev/null @@ -1,42 +0,0 @@ -var bases = require('bases'); -var crypto = require('crypto'); - -var tokenLength = 8; -var tokens = {}; - -var Upload = module.exports = function (socket) { - - var maxNum = Math.pow(62, tokenLength); - var numBytes = Math.ceil(Math.log(maxNum) / Math.log(256)); - - var token = ''; - do { - do { - var bytes = crypto.randomBytes(numBytes); - var num = 0 - for (var i = 0; i < bytes.length; i++) { - num += Math.pow(256, i) * bytes[i]; - } - } while (num >= maxNum); - - token = bases.toBase62(num); - } while (token in tokens); - - this.token = token; - this.socket = socket; - - tokens[this.token] = this; - -}; - -Upload.exists = function (token) { - return token in tokens; -}; - -Upload.find = function (token) { - return tokens[token]; -}; - -Upload.remove = function (client) { - delete tokens[client.token]; -};