Skip to content

Commit 839cef6

Browse files
committed
calls: Add original calls from webui.
1 parent 01e354b commit 839cef6

File tree

2 files changed

+190
-2
lines changed

2 files changed

+190
-2
lines changed

Tools.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Checks whether the remoteName is local or not. Returns true if it is a remote local path, false otherwise.
3+
* Behaviour: if the name starts with "/" it is a local name.
4+
* @param remoteName {string} Name of the remote to check for.
5+
* @returns {boolean}
6+
*/
7+
export function isLocalRemoteName(remoteName) {
8+
return (remoteName && remoteName !== "" && remoteName[0] === "/");
9+
}
10+
11+
/**
12+
* addColonAtLast is a helper function to add semicolon to the last.
13+
* Behaviour: if the passed in string does not have a semicolon at last, then insert it.
14+
* If there is a semicolon in the middle, skip insertion.
15+
* @param name
16+
* @returns {string}
17+
*/
18+
export function addColonAtLast(name) {
19+
if (name.indexOf(':') === -1) {
20+
if (name[name.length - 1] !== ":") {
21+
name = name + ":"
22+
}
23+
}
24+
25+
return name;
26+
}

index.js

Lines changed: 164 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,180 @@
11
import {axiosInstance} from "./axiosInstance";
22
import urls from "./endpoint";
3+
import {addColonAtLast, isLocalRemoteName} from "./Tools";
34

45
/**
56
* getStats returns the current rclone stats.
67
* @returns {Promise<unknown>}
78
*/
8-
export function getStats () {
9-
console.log("HI");
9+
export const getStats = () => {
1010
return new Promise((resolve, reject) => {
1111
axiosInstance.post(urls.stats).then(res => {
1212
resolve(res.data);
1313
}, error => {
1414
reject(error);
1515
})
1616
})
17+
}
18+
19+
/**
20+
*
21+
* @returns {Promise<unknown>}
22+
*/
23+
export const getCurrentBandwidthSetting = () => {
24+
return new Promise((resolve, reject) => {
25+
axiosInstance.post(urls.bwlimit).then(res => {
26+
resolve(res.data);
27+
}, error => {
28+
reject(error);
29+
})
30+
})
31+
}
32+
33+
/**
34+
* setCurrentBandwidthSetting changes the current bandwidth limit of the rclone backend.
35+
* @param newRate {string} Human readable format of size eg: 1M|2M|1.2G specifying 1MB, 2MB, 1.2GB respectively.
36+
* @returns {Promise<unknown>}
37+
*/
38+
export const setCurrentBandwidthSetting = (newRate) => {
39+
return new Promise((resolve, reject) => {
40+
axiosInstance.post(urls.bwlimit, {rate: newRate}).then(res => {
41+
resolve(res.data);
42+
}, error => {
43+
reject(error);
44+
})
45+
})
46+
}
47+
48+
/**
49+
* Create a public link for a supported remote
50+
* @param remoteName {string}
51+
* @param remotePath {string}
52+
* @returns {Function}
53+
*/
54+
export const createPublicLink = (remoteName, remotePath) => {
55+
return new Promise((resolve, reject) => {
56+
axiosInstance.post(urls.createPublicLink, {fs: remoteName, remote: remotePath}).then(res => {
57+
resolve(res.data);
58+
}, error => {
59+
reject(error);
60+
})
61+
})
62+
};
1763

64+
/**
65+
* getAllProviders returns all the possible providers supported by the rclone backend
66+
* @returns {Promise<unknown>}
67+
*/
68+
export const getAllProviders = () => {
69+
return new Promise((resolve, reject) => {
70+
axiosInstance.post(urls.getProviders).then(res => {
71+
resolve(res.data.providers);
72+
}, error => {
73+
reject(error);
74+
})
75+
})
1876
}
77+
78+
/**
79+
* getConfigDump return the configured remotes from the rclone backend
80+
* @returns {Promise<unknown>}
81+
*/
82+
export const getConfigDump = () => {
83+
return new Promise((resolve, reject) => {
84+
axiosInstance.post(urls.getConfigDump).then(res => {
85+
resolve(res.data);
86+
}, error => {
87+
reject(error);
88+
})
89+
})
90+
}
91+
/**
92+
* getFsInfo fetches the information regarding features, hashes from the rclone backend. Stores into redux store.
93+
* @param remoteName {string} The name of the remote
94+
* @returns {Function}
95+
*/
96+
export const getFsInfo = (remoteName) => {
97+
let sentRemoteName;
98+
if(!isLocalRemoteName(remoteName)) {
99+
sentRemoteName = addColonAtLast(remoteName.split(':')[0]);
100+
}
101+
return new Promise((resolve, reject) => {
102+
axiosInstance.post(urls.getFsInfo, {
103+
fs: sentRemoteName
104+
}).then(res => {
105+
resolve(res.data);
106+
}, error => {
107+
reject(error);
108+
})
109+
})
110+
}
111+
112+
/**
113+
* getFilesList fetches the files for a specified remote path (remoteName + remotePath). Stores into redux store.
114+
* @param fs {string} Name of the remote config/ ("/" for local path). May contain abc:bucketName for bucket based remotes
115+
* @param remotePath {string} Name of the path in the remote
116+
* @returns {Function}
117+
*/
118+
export const getFilesList = (fs, remotePath) => {
119+
return new Promise((resolve, reject) => {
120+
if(!fs || fs === ""){
121+
reject("Invalid fs specified")
122+
}
123+
124+
// check if it is a local path
125+
fs = fs.indexOf('/') !== 0 ? addColonAtLast(fs) : fs;
126+
127+
axiosInstance.post(urls.getFsInfo, {
128+
fs,
129+
remote: remotePath
130+
}).then(res => {
131+
resolve(res.data);
132+
}, error => {
133+
reject(error);
134+
})
135+
})
136+
}
137+
138+
/**
139+
* getRemoteInfo fetches the information about a provider.
140+
* @param remoteName
141+
* @returns {Promise<unknown>}
142+
*/
143+
export const getRemoteInfo = (remoteName) => {
144+
145+
return new Promise((resolve, reject) => {
146+
147+
if(!remoteName) {
148+
reject("Invalid remote name specified")
149+
return
150+
}
151+
152+
if (!isLocalRemoteName(remoteName)) {
153+
remoteName = addColonAtLast(remoteName);
154+
}
155+
axiosInstance.post(urls.getAbout, {
156+
fs: remoteName
157+
}).then(res => {
158+
resolve(res.data);
159+
}, error => {
160+
reject(error);
161+
})
162+
})
163+
164+
}
165+
166+
/**
167+
* getRemoteInfo fetches the information about a provider.
168+
* @param remoteName
169+
* @returns {Promise<unknown>}
170+
*/
171+
export const getRcloneVersion = () => {
172+
return new Promise((resolve, reject) => {
173+
axiosInstance.post(urls.getRcloneVersion).then(res => {
174+
resolve(res.data);
175+
}, error => {
176+
reject(error);
177+
})
178+
})
179+
}
180+

0 commit comments

Comments
 (0)