Upload torrents based on socket URI
This commit is contained in:
parent
f566414259
commit
716bffa3e6
|
@ -5,6 +5,9 @@ export const SOCKET_STATE = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SOCKET_UPDATE = "SOCKET_UPDATE";
|
export const SOCKET_UPDATE = "SOCKET_UPDATE";
|
||||||
|
export const SOCKET_URI = "SOCKET_URI";
|
||||||
|
|
||||||
export const socket_update = (state, reason=null) =>
|
export const socket_update = (state, reason=null) =>
|
||||||
({ type: SOCKET_UPDATE, state, reason });
|
({ type: SOCKET_UPDATE, state, reason });
|
||||||
|
|
||||||
|
export const socket_uri = uri => ({ type: SOCKET_URI, uri });
|
||||||
|
|
|
@ -10,13 +10,14 @@ import store, { create, history } from './store';
|
||||||
import scss from '../scss/main.scss';
|
import scss from '../scss/main.scss';
|
||||||
import { ws_init } from './socket';
|
import { ws_init } from './socket';
|
||||||
import { filter_subscribe } from './actions/filter_subscribe';
|
import { filter_subscribe } from './actions/filter_subscribe';
|
||||||
import { socket_update, SOCKET_STATE } from './actions/socket';
|
import { socket_uri, socket_update, SOCKET_STATE } from './actions/socket';
|
||||||
|
|
||||||
import Nav from './ui/navigation';
|
import Nav from './ui/navigation';
|
||||||
import Main from './ui/main';
|
import Main from './ui/main';
|
||||||
import Connection from './ui/connection';
|
import Connection from './ui/connection';
|
||||||
|
|
||||||
export function initialize(uri) {
|
export function initialize(uri) {
|
||||||
|
store.dispatch(socket_uri(uri));
|
||||||
store.dispatch(socket_update(SOCKET_STATE.CONNECTING));
|
store.dispatch(socket_update(SOCKET_STATE.CONNECTING));
|
||||||
ws_init(uri, () => {
|
ws_init(uri, () => {
|
||||||
store.dispatch(socket_update(SOCKET_STATE.CONNECTED));
|
store.dispatch(socket_update(SOCKET_STATE.CONNECTED));
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
import { SOCKET_STATE, SOCKET_UPDATE } from '../actions/socket';
|
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
|
||||||
}, action) {
|
}, action) {
|
||||||
const { state, reason } = 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:
|
||||||
|
return { ..._state, uri };
|
||||||
default:
|
default:
|
||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,12 +168,19 @@ class AddTorrent extends Component {
|
||||||
async handleTransferOffer(offer, file) {
|
async handleTransferOffer(offer, file) {
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
headers.append("Authorization", "Bearer " + offer.token);
|
headers.append("Authorization", "Bearer " + offer.token);
|
||||||
|
const { socket } = this.props;
|
||||||
|
console.log(socket);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = socket.uri;
|
||||||
|
const url = (a.protocol === "ws:" ? "http://" : "https://") + a.host;
|
||||||
try {
|
try {
|
||||||
const resp = await fetch('http://localhost:8412/', {
|
const resp = await fetch(url,
|
||||||
method: 'POST',
|
{
|
||||||
body: file,
|
method: 'POST',
|
||||||
headers: headers
|
body: file,
|
||||||
});
|
headers: headers
|
||||||
|
}
|
||||||
|
);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// TODO: something more useful
|
// TODO: something more useful
|
||||||
console.log(ex);
|
console.log(ex);
|
||||||
|
@ -457,4 +464,4 @@ class AddTorrent extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect()(AddTorrent);
|
export default connect(s => ({ socket: s.socket }))(AddTorrent);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user