Add download URL to torrent files

This commit is contained in:
Luminarys 2017-10-12 21:34:26 -07:00
parent 93107d7b32
commit 98accb302a
4 changed files with 17 additions and 6 deletions

View File

@ -3,14 +3,15 @@ import { SOCKET_STATE, SOCKET_UPDATE, SOCKET_URI } from '../actions/socket';
export default function socket(_state = { export default function socket(_state = {
state: SOCKET_STATE.DISCONNECTED, state: SOCKET_STATE.DISCONNECTED,
reason: null, reason: null,
uri: null uri: null,
password: null,
}, action) { }, action) {
const { state, reason, uri } = action; const { state, reason, uri } = action;
switch (action.type) { switch (action.type) {
case SOCKET_UPDATE: case SOCKET_UPDATE:
return { ..._state, state, reason }; return { ..._state, state, reason };
case SOCKET_URI: case SOCKET_URI:
return { ..._state, uri }; return { ..._state, ...uri, };
default: default:
return _state; return _state;
} }

View File

@ -7,6 +7,9 @@ let transactions = {};
let connected = false; let connected = false;
let queue = []; let queue = [];
const getURI = ({ uri, password }) => `${uri}${password ?
`?password=${encodeURIComponent(password)}` : ''}`;
export default function ws_send(type, body, callback = null) { export default function ws_send(type, body, callback = null) {
const _serial = serial++; const _serial = serial++;
if (callback) { if (callback) {
@ -43,7 +46,7 @@ function ws_recv(e) {
} }
export function ws_init(uri, open, close) { export function ws_init(uri, open, close) {
ws = new WebSocket(uri); ws = new WebSocket(getURI(uri));
ws.addEventListener("open", () => { ws.addEventListener("open", () => {
connected = true; connected = true;
open.apply(this, arguments); open.apply(this, arguments);

View File

@ -13,8 +13,7 @@ import {
import { initialize } from '..'; import { initialize } from '..';
import { SOCKET_STATE } from '../actions/socket'; import { SOCKET_STATE } from '../actions/socket';
const getURI = (uri, password) => `${uri}${password ? const getURI = (uri, password) => ({ uri, password });
`?password=${encodeURIComponent(password)}` : ''}`;
class ConnectionOverlay extends Component { class ConnectionOverlay extends Component {
constructor() { constructor() {

View File

@ -15,6 +15,7 @@ import moment from 'moment';
import TorrentOptions from './torrent_options'; import TorrentOptions from './torrent_options';
import TorrentProgress from './torrent_progress'; import TorrentProgress from './torrent_progress';
import ws_send from '../socket'; import ws_send from '../socket';
import store from '../store';
import DateDisplay from './date'; import DateDisplay from './date';
import selectTorrent, { import selectTorrent, {
EXCLUSIVE, EXCLUSIVE,
@ -24,12 +25,19 @@ import selectTorrent, {
} from '../actions/selection'; } from '../actions/selection';
import { updateResource } from '../actions/resources'; import { updateResource } from '../actions/resources';
const dlURI = (uri, password, id) => `${uri.replace('ws', 'http')}/dl/${id}?password=${encodeURIComponent(password)}`;
function File({ file }) { function File({ file }) {
// TODO: show progress bar // TODO: show progress bar
// TODO: edit priority // TODO: edit priority
const { uri, password } = store.getState().socket;
return ( return (
<tr> <tr>
<td>{file.path}</td> <td>
<a href={dlURI(uri, password, file.id)} target="_new">
{file.path}
</a>
</td>
<td>{file.priority}</td> <td>{file.priority}</td>
<td>{file.availability}</td> <td>{file.availability}</td>
</tr> </tr>