mirror of
https://github.com/zoriya/flood.git
synced 2025-12-21 06:35:14 +00:00
115 lines
2.3 KiB
JavaScript
115 lines
2.3 KiB
JavaScript
import axios from 'axios';
|
|
|
|
export function addTorrents(urls, destination) {
|
|
return function(dispatch) {
|
|
return axios.post('/torrents/add', {
|
|
urls,
|
|
destination
|
|
})
|
|
.then((json = {}) => {
|
|
return json.data;
|
|
})
|
|
.then((response) => {
|
|
dispatch({
|
|
type: 'ADD_TORRENT',
|
|
payload: {
|
|
response
|
|
}
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
console.error('error', error);
|
|
});
|
|
}
|
|
};
|
|
|
|
export function fetchTransferData() {
|
|
return function(dispatch) {
|
|
return axios.get('/client/stats')
|
|
.then((json = {}) => {
|
|
return json.data;
|
|
})
|
|
.then(transferData => {
|
|
dispatch({
|
|
type: 'CLIENT_RECEIVE_TRANSFER_DATA',
|
|
payload: transferData
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
console.error('error', error);
|
|
});
|
|
}
|
|
}
|
|
|
|
export function fetchTorrents() {
|
|
return function(dispatch) {
|
|
dispatch({
|
|
type: 'REQUEST_TORRENTS',
|
|
payload: {
|
|
text: 'Begin requesting torrents.'
|
|
}
|
|
});
|
|
return axios.get('/torrents/list')
|
|
.then((json = {}) => {
|
|
return json.data;
|
|
})
|
|
.then(torrents => {
|
|
dispatch({
|
|
type: 'RECEIVE_TORRENTS',
|
|
payload: {
|
|
torrents
|
|
}
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
console.error('error', error);
|
|
});
|
|
}
|
|
}
|
|
|
|
export function startTorrent(hashes) {
|
|
return function(dispatch) {
|
|
return axios.post('/torrents/start', {
|
|
hashes
|
|
})
|
|
.then((json = {}) => {
|
|
return json.data;
|
|
})
|
|
.then((response) => {
|
|
dispatch({
|
|
type: 'START_TORRENT',
|
|
payload: {
|
|
response
|
|
}
|
|
});
|
|
dispatch(fetchTorrents());
|
|
})
|
|
.catch((error) => {
|
|
console.error('error', error);
|
|
});
|
|
}
|
|
}
|
|
|
|
export function stopTorrent(hashes) {
|
|
return function(dispatch) {
|
|
return axios.post('/torrents/stop', {
|
|
hashes
|
|
})
|
|
.then((json = {}) => {
|
|
return json.data;
|
|
})
|
|
.then((response) => {
|
|
dispatch({
|
|
type: 'STOP_TORRENT',
|
|
payload: {
|
|
response
|
|
}
|
|
});
|
|
dispatch(fetchTorrents());
|
|
})
|
|
.catch((error) => {
|
|
console.error('error', error);
|
|
});
|
|
}
|
|
}
|