forked from PrivateCoffee/transfer.coffee
Kumi
a53fabdec1
- Initialize new Express application for file transfer using WebTorrent. - Set up routes for generating and retrieving mnemonics and info hashes. - Implement custom BitTorrent tracker server with WebSockets. - Add `.gitignore` to exclude `node_modules/`. - Create `index.ejs` for front-end with file upload and download functionalities. - Initialize `package.json` and `package-lock.json` with necessary dependencies.
34 lines
No EOL
964 B
JavaScript
34 lines
No EOL
964 B
JavaScript
import express from 'express';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import bip39 from 'bip39';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const app = express();
|
|
const trackerUrl = process.env.TRACKER_URL || 'ws://localhost:8106';
|
|
|
|
app.set('view engine', 'ejs');
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
app.get('/', (req, res) => {
|
|
res.render('index', { trackerUrl });
|
|
});
|
|
|
|
app.get('/generate-mnemonic/:infoHash', (req, res) => {
|
|
const infoHash = req.params.infoHash;
|
|
const mnemonic = bip39.entropyToMnemonic(infoHash);
|
|
res.json({ mnemonic });
|
|
});
|
|
|
|
app.get('/get-infohash/:mnemonic', (req, res) => {
|
|
const mnemonic = req.params.mnemonic;
|
|
const infoHash = bip39.mnemonicToEntropy(mnemonic);
|
|
res.json({ infoHash });
|
|
});
|
|
|
|
const PORT = process.env.PORT || 8105;
|
|
app.listen(PORT, () => {
|
|
console.log(`Server is running on port ${PORT}`);
|
|
}); |