Skip to content

Commit 686c3e4

Browse files
committed
Use rclone-api for rc calls
Switch to rclone-api
1 parent 7f597a9 commit 686c3e4

File tree

9 files changed

+341
-379
lines changed

9 files changed

+341
-379
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"redux": "^4.0.5",
4747
"redux-thunk": "^2.3.0",
4848
"simple-line-icons": "^2.4.1",
49-
"typescript": "^3.7.5"
49+
"typescript": "^3.7.5",
50+
"rclone-api": "^1.0.0"
5051
},
5152
"devDependencies": {
5253
"check-prop-types": "^1.1.2",

src/actions/configActions.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
import axiosInstance from "../utils/API/API";
21
import {GET_CONFIG_DUMP, GET_PROVIDERS, REQUEST_ERROR, REQUEST_SUCCESS} from "./types";
3-
import urls from "../utils/API/endpoint";
4-
2+
import {getAllConfigDump, getAllProviders} from "rclone-api";
53

64
/**
75
* Gets all Providers from the rclone UI Backend
86
* @returns {Function}
97
*/
108
export const getProviders = () => dispatch => {
11-
axiosInstance.post(urls.getProviders).then(res => dispatch({
9+
getAllProviders().then(data => dispatch({
1210
type: GET_PROVIDERS,
13-
payload: res.data.providers
11+
payload: data.providers
1412
}))
1513
};
1614
/**
1715
* Gets dump of configured remotes from the rclone backend
1816
* @returns {Function}
1917
*/
2018
export const getConfigDump = () => dispatch => {
21-
axiosInstance.post(urls.getConfigDump).then(res => dispatch({
19+
getAllConfigDump().then(res => dispatch({
2220
type: GET_CONFIG_DUMP,
2321
status: REQUEST_SUCCESS,
24-
payload: res.data
22+
payload: res
2523
}), error => dispatch({
2624
type: GET_CONFIG_DUMP,
2725
status: REQUEST_ERROR,
2826
payload: error
2927
}))
30-
};
28+
};

src/actions/explorerActions.js

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,39 @@
1-
import axiosInstance from "../utils/API/API";
21
import {
3-
ADD_LAYOUT_CONTAINER,
4-
CHANGE_ACTIVE_REMOTE_CONTAINER,
5-
CHANGE_DISTRACTION_FREE_MODE,
6-
CHANGE_LAYOUT_COLS,
7-
GET_CONFIG_FOR_REMOTE,
8-
GET_FILES_LIST,
9-
GET_REMOTE_LIST,
10-
REMOVE_LAYOUT_CONTAINER,
11-
REQUEST_ERROR,
12-
REQUEST_SUCCESS
2+
ADD_LAYOUT_CONTAINER,
3+
CHANGE_ACTIVE_REMOTE_CONTAINER,
4+
CHANGE_DISTRACTION_FREE_MODE,
5+
CHANGE_LAYOUT_COLS,
6+
GET_CONFIG_FOR_REMOTE,
7+
GET_FILES_LIST,
8+
GET_REMOTE_LIST,
9+
REMOVE_LAYOUT_CONTAINER,
10+
REQUEST_ERROR,
11+
REQUEST_SUCCESS
1312
} from "./types";
14-
import {addColonAtLast, isLocalRemoteName, makeUniqueID} from "../utils/Tools";
13+
import {makeUniqueID} from "../utils/Tools";
1514
import {createPath, removePath} from "./explorerStateActions";
16-
import urls from "../utils/API/endpoint";
15+
import {getAllRemoteNames, getFilesList, getRemoteInfo} from "rclone-api"
1716

1817
/**
1918
* Gets the information regarding features, hashes from the rclone backend. Stores into redux store.
2019
* @param remoteName {string} The name of the remote
2120
* @returns {Function}
2221
*/
2322
export const getFsInfo = (remoteName) => dispatch => {
24-
25-
let sentRemoteName;
26-
let setRemoteName;
27-
28-
if (isLocalRemoteName(remoteName)) {
29-
sentRemoteName = setRemoteName = "/";
30-
31-
} else {
32-
setRemoteName = remoteName.split(':')[0];
33-
sentRemoteName = addColonAtLast(setRemoteName);
34-
}
3523
// console.log("Actual: ", sentRemoteName);
36-
axiosInstance.post(urls.getFsInfo, {fs: sentRemoteName})
37-
.then((res) => {
38-
dispatch({
39-
type: GET_CONFIG_FOR_REMOTE,
40-
status: REQUEST_SUCCESS,
41-
payload: {[setRemoteName]: res.data},
42-
43-
})
44-
},
45-
error => dispatch({
24+
getRemoteInfo(remoteName).then((res) => {
25+
dispatch({
4626
type: GET_CONFIG_FOR_REMOTE,
47-
status: REQUEST_ERROR,
48-
payload: error
49-
}))
27+
status: REQUEST_SUCCESS,
28+
payload: {[remoteName.split(':')[0]]: res},
29+
30+
})
31+
},
32+
error => dispatch({
33+
type: GET_CONFIG_FOR_REMOTE,
34+
status: REQUEST_ERROR,
35+
payload: error
36+
}))
5037

5138
};
5239

@@ -61,10 +48,10 @@ export const getRemoteNames = () => {
6148
// console.log(state);
6249
if (!state.remote.remotes || state.remote.remotes.length < 1) {
6350

64-
axiosInstance.post(urls.listRemotes).then(res => dispatch({
51+
getAllRemoteNames().then(res => dispatch({
6552
type: GET_REMOTE_LIST,
6653
status: REQUEST_SUCCESS,
67-
payload: res.data.remotes
54+
payload: res.remotes
6855
}), error => dispatch({
6956
type: GET_REMOTE_LIST,
7057
status: REQUEST_ERROR,
@@ -81,25 +68,12 @@ export const getRemoteNames = () => {
8168
* @returns {Function}
8269
*/
8370
export const getFiles = (remoteName, remotePath) => dispatch => {
84-
let newRemoteName = "";
8571
if (remoteName !== "") {
86-
if (remoteName.indexOf('/') !== 0) {/*The name starts with a /: local Name*/
87-
newRemoteName = addColonAtLast(remoteName);
88-
} else {
89-
newRemoteName = remoteName;
90-
}
91-
92-
93-
let data = {
94-
fs: newRemoteName,
95-
remote: remotePath
96-
};
97-
9872
const path = `${remoteName}-${remotePath}`;
99-
axiosInstance.post(urls.getFilesList, data).then(res => dispatch({
73+
getFilesList(remoteName, remotePath).then(res => dispatch({
10074
type: GET_FILES_LIST,
10175
status: REQUEST_SUCCESS,
102-
payload: {path: path, filesList: res.data.list}
76+
payload: {path: path, filesList: res.list}
10377
}),
10478
error => dispatch({
10579
type: GET_FILES_LIST,
@@ -159,7 +133,7 @@ export const addRemoteContainer = (paneID) => (dispatch) => {
159133
* @returns {Function}
160134
*/
161135
export const removeRemoteContainer = (containerID, paneID) => (dispatch) => {
162-
dispatch(removePath(containerID));
136+
dispatch(removePath(containerID));
163137
// console.log("Removing : " + containerID);
164138
dispatch({
165139
type: REMOVE_LAYOUT_CONTAINER,

src/actions/providerStatusActions.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import axiosInstance from "../utils/API/API";
21
import {addColonAtLast, isLocalRemoteName} from "../utils/Tools";
32
import {GET_REMOTE_ABOUT, REQUEST_ERROR, REQUEST_SUCCESS} from "../actions/types";
4-
import urls from "../utils/API/endpoint";
3+
import {getRemoteInfo} from "rclone-api";
54

65
/**
76
* Gets the information of a provider
@@ -29,13 +28,13 @@ export const getAbout = (containerID) => {
2928
payload: {}
3029
});
3130

32-
axiosInstance.post(urls.getAbout, {fs: remoteName})
31+
getRemoteInfo(remoteName)
3332
.then((res) => {
3433
dispatch({
3534
type: GET_REMOTE_ABOUT,
3635
status: REQUEST_SUCCESS,
3736
id: containerID,
38-
payload: res.data
37+
payload: res
3938
})
4039
}, (res) => {
4140
dispatch({
@@ -47,4 +46,4 @@ export const getAbout = (containerID) => {
4746
})
4847
}
4948
}
50-
};
49+
};

src/actions/remoteOpsActions.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import {
55
REQUEST_ERROR,
66
REQUEST_SUCCESS
77
} from './types';
8-
import axiosInstance from "../utils/API/API";
98
import {toast} from "react-toastify";
10-
import urls from "../utils/API/endpoint";
9+
import {createNewPublicLink, getJobStatus} from "rclone-api";
1110

1211
/**
1312
* Create a public link for a supported remote
@@ -17,11 +16,11 @@ import urls from "../utils/API/endpoint";
1716
*/
1817
export const createPublicLink = (remoteName, remotePath) => {
1918
return (dispatch) => {
20-
axiosInstance.post(urls.createPublicLink, {fs: remoteName, remote: remotePath}).then((res) =>
19+
createNewPublicLink(remoteName, remotePath).then((res) =>
2120
dispatch({
2221
type: CREATE_PUBLIC_LINK,
2322
status: REQUEST_SUCCESS,
24-
payload: res.data
23+
payload: res
2524
}),
2625
(error) => {
2726
dispatch({
@@ -42,11 +41,11 @@ export const createPublicLink = (remoteName, remotePath) => {
4241
*/
4342

4443
export const getRunningJobs = () => dispatch => {
45-
axiosInstance.post(urls.getRunningJobs).then((res) => {
44+
getRunningJobs().then((res) => {
4645
dispatch({
4746
type: GET_RUNNING_JOBS,
4847
status: REQUEST_SUCCESS,
49-
payload: res.data
48+
payload: res
5049
})
5150
},
5251
(err) => {
@@ -64,12 +63,12 @@ export const getRunningJobs = () => dispatch => {
6463
* @returns {Function}
6564
*/
6665
export const getStatusForRunningJob = (jobId) => dispatch => {
67-
axiosInstance.post(urls.getStatusForJob, {jobid: jobId}).then((res) => {
66+
getJobStatus(jobId).then((res) => {
6867
dispatch({
6968
type: GET_STATUS_FOR_RUNNING_JOB,
7069
status: REQUEST_SUCCESS,
7170
id: jobId,
72-
payload: res.data
71+
payload: res
7372
})
7473
},
7574
(err) => {
@@ -80,4 +79,4 @@ export const getStatusForRunningJob = (jobId) => dispatch => {
8079
payload: err
8180
});
8281
})
83-
};
82+
};

src/actions/statusActions.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import axiosInstance from "../utils/API/API";
21
import {ENABLE_STATUS_CHECK, FETCH_STATUS, GET_BANDWIDTH, REQUEST_ERROR, REQUEST_SUCCESS, SET_BANDWIDTH} from "./types";
3-
import urls from "../utils/API/endpoint";
2+
import {getCurrentBandwidthSetting, getStats, setCurrentBandwidthSetting} from "rclone-api";
43

54
/**
65
* Gets the current status of the rclone backend.
@@ -11,10 +10,10 @@ export const getStatus = () => async (dispatch, getState) => {
1110
// console.log("get Status");
1211
const {status} = getState();
1312
if (status.checkStatus) {
14-
axiosInstance.post(urls.stats).then(res => dispatch({
13+
getStats().then(res => dispatch({
1514
type: FETCH_STATUS,
1615
status: REQUEST_SUCCESS,
17-
payload: res.data
16+
payload: res
1817
}), error => dispatch({
1918
type: FETCH_STATUS,
2019
status: REQUEST_ERROR,
@@ -43,10 +42,10 @@ export const enableCheckStatus = (shouldEnable) => async dispatch => {
4342
*/
4443
export const getBandwidth = () => async dispatch => {
4544
// console.log("get Status");
46-
axiosInstance.post(urls.bwlimit).then(res => dispatch({
45+
getCurrentBandwidthSetting().then(res => dispatch({
4746
type: GET_BANDWIDTH,
4847
status: REQUEST_SUCCESS,
49-
payload: res.data
48+
payload: res
5049
}), error => dispatch({
5150
type: GET_BANDWIDTH,
5251
status: REQUEST_ERROR,
@@ -61,10 +60,10 @@ export const getBandwidth = () => async dispatch => {
6160
*/
6261
export const setBandwidth = (newRate) => async dispatch => {
6362
// console.log("get Status");
64-
axiosInstance.post(urls.bwlimit, {rate: newRate}).then(res => dispatch({
63+
setCurrentBandwidthSetting(newRate).then(res => dispatch({
6564
type: SET_BANDWIDTH,
6665
status: REQUEST_SUCCESS,
67-
payload: res.data
66+
payload: res
6867
}), error => dispatch({
6968
type: SET_BANDWIDTH,
7069
status: REQUEST_ERROR,

src/actions/versionActions.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
import axiosInstance from '../utils/API/API';
2-
import urls from '../utils/API/endpoint';
3-
import { GET_VERSION, REQUEST_SUCCESS, REQUEST_ERROR } from './types';
1+
import {GET_VERSION, REQUEST_ERROR, REQUEST_SUCCESS} from './types';
2+
import {getRcloneVersion} from "rclone-api";
43

54
export const getVersion = () => {
6-
return dispatch => {
7-
axiosInstance.post(urls.getRcloneVersion).then(
8-
res =>
9-
dispatch({
10-
type: GET_VERSION,
11-
status: REQUEST_SUCCESS,
12-
payload: res.data
13-
}),
14-
error =>
15-
dispatch({
16-
type: GET_VERSION,
17-
status: REQUEST_ERROR,
18-
payload: error
19-
})
20-
);
21-
};
5+
return dispatch => {
6+
getRcloneVersion().then(
7+
res =>
8+
dispatch({
9+
type: GET_VERSION,
10+
status: REQUEST_SUCCESS,
11+
payload: res
12+
}),
13+
error =>
14+
dispatch({
15+
type: GET_VERSION,
16+
status: REQUEST_ERROR,
17+
payload: error
18+
})
19+
);
20+
};
2221
};

0 commit comments

Comments
 (0)