mirror of
https://github.com/zoriya/flood.git
synced 2025-12-21 06:35:14 +00:00
Rearrange app directory structure
This commit is contained in:
115
client/source/scripts/actions/ClientActions.js
Normal file
115
client/source/scripts/actions/ClientActions.js
Normal file
@@ -0,0 +1,115 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export function addTorrent(hashes) {
|
||||
return function(dispatch) {
|
||||
return axios.post('/torrents/add', {
|
||||
hashes
|
||||
})
|
||||
.then((json = {}) => {
|
||||
return json.data;
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: 'ADD_TORRENT',
|
||||
payload: {
|
||||
response
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('error', error);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// CLIENT_RECEIVE_TRANSFER_DATA
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user