mirror of
https://github.com/zoriya/flood.git
synced 2025-12-21 06:35:14 +00:00
Add torrent details data
This commit is contained in:
@@ -2,7 +2,7 @@ import axios from 'axios';
|
|||||||
|
|
||||||
export function addTorrents(urls, destination) {
|
export function addTorrents(urls, destination) {
|
||||||
return function(dispatch) {
|
return function(dispatch) {
|
||||||
return axios.post('/torrents/add', {
|
return axios.post('/client/add', {
|
||||||
urls,
|
urls,
|
||||||
destination
|
destination
|
||||||
})
|
})
|
||||||
@@ -23,7 +23,7 @@ export function addTorrents(urls, destination) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function fetchTransferData() {
|
export function getTransferData() {
|
||||||
return function(dispatch) {
|
return function(dispatch) {
|
||||||
return axios.get('/client/stats')
|
return axios.get('/client/stats')
|
||||||
.then((json = {}) => {
|
.then((json = {}) => {
|
||||||
@@ -41,7 +41,7 @@ export function fetchTransferData() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchTorrents() {
|
export function getTorrents() {
|
||||||
return function(dispatch) {
|
return function(dispatch) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'REQUEST_TORRENTS',
|
type: 'REQUEST_TORRENTS',
|
||||||
@@ -49,7 +49,7 @@ export function fetchTorrents() {
|
|||||||
text: 'Begin requesting torrents.'
|
text: 'Begin requesting torrents.'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return axios.get('/torrents/list')
|
return axios.get('/client/list')
|
||||||
.then((json = {}) => {
|
.then((json = {}) => {
|
||||||
return json.data;
|
return json.data;
|
||||||
})
|
})
|
||||||
@@ -67,9 +67,32 @@ export function fetchTorrents() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getTorrentDetails(hash) {
|
||||||
|
return function(dispatch) {
|
||||||
|
return axios.post('/client/torrent-details', {
|
||||||
|
hash
|
||||||
|
})
|
||||||
|
.then((json = {}) => {
|
||||||
|
return json.data;
|
||||||
|
})
|
||||||
|
.then(torrentDetails => {
|
||||||
|
dispatch({
|
||||||
|
type: 'RECEIVE_TORRENT_DETAILS',
|
||||||
|
payload: {
|
||||||
|
hash,
|
||||||
|
torrentDetails
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function startTorrent(hashes) {
|
export function startTorrent(hashes) {
|
||||||
return function(dispatch) {
|
return function(dispatch) {
|
||||||
return axios.post('/torrents/start', {
|
return axios.post('/client/start', {
|
||||||
hashes
|
hashes
|
||||||
})
|
})
|
||||||
.then((json = {}) => {
|
.then((json = {}) => {
|
||||||
@@ -82,7 +105,7 @@ export function startTorrent(hashes) {
|
|||||||
response
|
response
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dispatch(fetchTorrents());
|
dispatch(getTorrents());
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -92,7 +115,7 @@ export function startTorrent(hashes) {
|
|||||||
|
|
||||||
export function stopTorrent(hashes) {
|
export function stopTorrent(hashes) {
|
||||||
return function(dispatch) {
|
return function(dispatch) {
|
||||||
return axios.post('/torrents/stop', {
|
return axios.post('/client/stop', {
|
||||||
hashes
|
hashes
|
||||||
})
|
})
|
||||||
.then((json = {}) => {
|
.then((json = {}) => {
|
||||||
@@ -105,7 +128,7 @@ export function stopTorrent(hashes) {
|
|||||||
response
|
response
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dispatch(fetchTorrents());
|
dispatch(getTorrents());
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const initialState = {
|
const initialState = {
|
||||||
|
torrentDetails: {},
|
||||||
transfers: {
|
transfers: {
|
||||||
updatedAt: 0,
|
updatedAt: 0,
|
||||||
download: {
|
download: {
|
||||||
@@ -15,6 +16,19 @@ const initialState = {
|
|||||||
export default function clientReducer(state = initialState, action) {
|
export default function clientReducer(state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
|
||||||
|
case 'RECEIVE_TORRENT_DETAILS':
|
||||||
|
let torrentDetails = {};
|
||||||
|
torrentDetails[action.payload.hash] = action.payload.torrentDetails;
|
||||||
|
|
||||||
|
return Object.assign(
|
||||||
|
{},
|
||||||
|
state,
|
||||||
|
{
|
||||||
|
...state,
|
||||||
|
torrentDetails
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
case 'CLIENT_RECEIVE_TRANSFER_DATA':
|
case 'CLIENT_RECEIVE_TRANSFER_DATA':
|
||||||
return Object.assign(
|
return Object.assign(
|
||||||
{},
|
{},
|
||||||
|
|||||||
Reference in New Issue
Block a user