Update download token generation strategy

This commit is contained in:
Luminarys 2019-03-14 21:29:25 -07:00 committed by Drew DeVault
parent f77de0347a
commit 1dc0775625
2 changed files with 6 additions and 1 deletions

View File

@ -44,6 +44,7 @@
"font-awesome-sass-loader": "^2.0.1",
"history": "^4.7.2",
"isomorphic-fetch": "^2.2.1",
"js-sha1": "^0.6.0",
"moment": "^2.20.1",
"node-sass": "^4.7.2",
"numeral": "^2.0.6",

View File

@ -14,6 +14,7 @@ import {
Input,
} from 'reactstrap';
import moment from 'moment';
import sha1 from 'js-sha1';
import TorrentOptions from './torrent_options';
import TorrentProgress from './torrent_progress';
import ws_send from '../socket';
@ -28,7 +29,10 @@ import selectTorrent, {
import { updateResource } from '../actions/resources';
import { formatBitrate } from '../bitrate';
const dlURI = (uri, token, id) => `${uri.replace('ws', 'http')}/dl/${id}?token=${encodeURIComponent(token)}`;
const dlURI = (uri, token, id) => {
const dlToken = encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(sha1.arrayBuffer(id + token)))));
return `${uri.replace('ws', 'http')}/dl/${id}?token=${dlToken}`;
};
function basename(path) {
const parts = path.split("/");