Skip to content

Commit a75aa7e

Browse files
committed
calls: Add docs and minor corrections
1 parent 839cef6 commit a75aa7e

File tree

4 files changed

+177
-14
lines changed

4 files changed

+177
-14
lines changed

Readme.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# JavaScript api for rclone rc
2+
3+
This is a javascript api to access the [rclone rc](https://rclone.org/rc) api.
4+
5+
# How to install
6+
7+
If you are using <b>npm</b>,
8+
```
9+
npm install rclone-api --save
10+
```
11+
or using <b>yarn</b>,
12+
```shell script
13+
yarn install rclone-api
14+
```
15+
16+
## Usage
17+
18+
Import the required function
19+
20+
```js
21+
import {getAllProviders} from "rclone-api";
22+
```
23+
24+
And then,
25+
26+
```js
27+
getAllProviders().then(res => {
28+
//... do something with the data
29+
}, error => {
30+
//... do something with the error
31+
//eg: alert(error)
32+
});
33+
```
34+
35+
OR
36+
37+
```js
38+
getAllProviders().then(res => {
39+
//... do something with the data
40+
}).catch( error => {
41+
//... do something with the error
42+
//eg: alert(error)
43+
});
44+
```
45+
46+
## Supported calls
47+
48+
1. ```getStats()```: returns the current rclone stats.
49+
1. ```getCurrentBandwidthSetting()```: fetches the current limit that is max which the rclone can send request at.
50+
1. ```setCurrentBandwidthSetting(newRate)```: changes the current bandwidth limit of the rclone backend.
51+
@param newRate {string} Human readable format of size eg: 1M|2M|1.2G specifying 1MB, 2MB, 1.2GB respectively.
52+
1. ```createPublicLink(remoteName, remotePath)``` creates a public link for a supported remote
53+
1. ```getAllProviders()``` returns all the possible providers supported by the rclone backend
54+
1. ```getAllConfigDump()``` return the configured remotes from the rclone backend
55+
1. ```getFsInfo(remoteName)``` fetches the information regarding features, hashes from the rclone backend.
56+
1. ```getFilesList(remoteName, remotePath)``` fetches the files for a specified remote path (remoteName + remotePath).
57+
1. ```getRemoteInfo(remoteName)``` fetches the information about a provider.
58+
1. ```getRcloneVersion()``` fetches the version and details about the running rclone version.
59+
1. ```getAllRemoteNames()``` fetches all the remotes in the config.
60+
1.

index.js

Lines changed: 111 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const getStats = () => {
1717
}
1818

1919
/**
20-
*
20+
* getCurrentBandwidthSetting fetches the current limit that is max which the rclone can send request at.
2121
* @returns {Promise<unknown>}
2222
*/
2323
export const getCurrentBandwidthSetting = () => {
@@ -46,12 +46,13 @@ export const setCurrentBandwidthSetting = (newRate) => {
4646
}
4747

4848
/**
49-
* Create a public link for a supported remote
49+
* createPublicLink creates a public link for a supported remote
5050
* @param remoteName {string}
5151
* @param remotePath {string}
5252
* @returns {Function}
5353
*/
54-
export const createPublicLink = (remoteName, remotePath) => {
54+
export const createNewPublicLink = (remoteName, remotePath) => {
55+
remoteName = addColonAtLast(remoteName);
5556
return new Promise((resolve, reject) => {
5657
axiosInstance.post(urls.createPublicLink, {fs: remoteName, remote: remotePath}).then(res => {
5758
resolve(res.data);
@@ -68,7 +69,7 @@ export const createPublicLink = (remoteName, remotePath) => {
6869
export const getAllProviders = () => {
6970
return new Promise((resolve, reject) => {
7071
axiosInstance.post(urls.getProviders).then(res => {
71-
resolve(res.data.providers);
72+
resolve(res.data);
7273
}, error => {
7374
reject(error);
7475
})
@@ -79,7 +80,7 @@ export const getAllProviders = () => {
7980
* getConfigDump return the configured remotes from the rclone backend
8081
* @returns {Promise<unknown>}
8182
*/
82-
export const getConfigDump = () => {
83+
export const getAllConfigDump = () => {
8384
return new Promise((resolve, reject) => {
8485
axiosInstance.post(urls.getConfigDump).then(res => {
8586
resolve(res.data);
@@ -89,7 +90,7 @@ export const getConfigDump = () => {
8990
})
9091
}
9192
/**
92-
* getFsInfo fetches the information regarding features, hashes from the rclone backend. Stores into redux store.
93+
* getFsInfo fetches the information regarding features, hashes from the rclone backend.
9394
* @param remoteName {string} The name of the remote
9495
* @returns {Function}
9596
*/
@@ -110,7 +111,7 @@ export const getFsInfo = (remoteName) => {
110111
}
111112

112113
/**
113-
* getFilesList fetches the files for a specified remote path (remoteName + remotePath). Stores into redux store.
114+
* getFilesList fetches the files for a specified remote path (remoteName + remotePath).
114115
* @param fs {string} Name of the remote config/ ("/" for local path). May contain abc:bucketName for bucket based remotes
115116
* @param remotePath {string} Name of the path in the remote
116117
* @returns {Function}
@@ -124,7 +125,7 @@ export const getFilesList = (fs, remotePath) => {
124125
// check if it is a local path
125126
fs = fs.indexOf('/') !== 0 ? addColonAtLast(fs) : fs;
126127

127-
axiosInstance.post(urls.getFsInfo, {
128+
axiosInstance.post(urls.getFilesList, {
128129
fs,
129130
remote: remotePath
130131
}).then(res => {
@@ -152,8 +153,8 @@ export const getRemoteInfo = (remoteName) => {
152153
if (!isLocalRemoteName(remoteName)) {
153154
remoteName = addColonAtLast(remoteName);
154155
}
155-
axiosInstance.post(urls.getAbout, {
156-
fs: remoteName
156+
axiosInstance.post(urls.getFsInfo, {
157+
fs: remoteName
157158
}).then(res => {
158159
resolve(res.data);
159160
}, error => {
@@ -164,8 +165,7 @@ export const getRemoteInfo = (remoteName) => {
164165
}
165166

166167
/**
167-
* getRemoteInfo fetches the information about a provider.
168-
* @param remoteName
168+
* getRcloneVersion fetches the version and details about the running rclone version.
169169
* @returns {Promise<unknown>}
170170
*/
171171
export const getRcloneVersion = () => {
@@ -178,3 +178,102 @@ export const getRcloneVersion = () => {
178178
})
179179
}
180180

181+
182+
/**
183+
* getAllRemoteNames fetches all the remotes in the config.
184+
* @returns {Promise<unknown>}
185+
*/
186+
export const getAllRemoteNames = () => {
187+
return new Promise((resolve, reject) => {
188+
axiosInstance.post(urls.listRemotes).then(res => {
189+
resolve(res.data);
190+
}, error => {
191+
reject(error);
192+
})
193+
})
194+
}
195+
196+
/**
197+
* getJobStatus returns the status of a job with jobId
198+
* @param jobId {number} Valid job id
199+
* @return {Promise<unknown>}
200+
*/
201+
export const getJobStatus = (jobId) => {
202+
return new Promise((resolve, reject) => {
203+
axiosInstance.post(urls.getStatusForJob, {jobId}).then(res => {
204+
resolve(res.data);
205+
}, error => {
206+
reject(error);
207+
})
208+
})
209+
}
210+
211+
/**
212+
* purgeDir returns the status of a job with jobId
213+
* @param jobId {number} Valid job id
214+
* @return {Promise<unknown>}
215+
*/
216+
export const purgeDir = (fs , remote) => {
217+
return new Promise((resolve, reject) => {
218+
axiosInstance.post(urls.purge).then(res => {
219+
resolve(res.data);
220+
}, error => {
221+
reject(error);
222+
})
223+
})
224+
}
225+
226+
227+
/**
228+
* deleteFile returns the status of a job with jobId
229+
* @param fs {string} Remote Name
230+
* @param remote {string} Remote Path
231+
* @return {Promise<unknown>}
232+
*/
233+
export const deleteFile = (fs , remote) => {
234+
fs = addColonAtLast(fs)
235+
return new Promise((resolve, reject) => {
236+
axiosInstance.post(urls.deleteFile, {
237+
fs,
238+
remote
239+
}).then(res => {
240+
resolve(res.data);
241+
}, error => {
242+
reject(error);
243+
})
244+
})
245+
}
246+
247+
/**
248+
* cleanTrashForRemote returns the status of a job with jobId
249+
* @param fs {string} Remote Name
250+
* @return {Promise<unknown>}
251+
*/
252+
export const cleanTrashForRemote = (fs) => {
253+
if (!isLocalRemoteName(fs)) {
254+
fs = addColonAtLast(fs);
255+
}
256+
return new Promise((resolve, reject) => {
257+
axiosInstance.post(urls.cleanUpRemote, {
258+
fs,
259+
}).then(res => {
260+
resolve(res.data);
261+
}, error => {
262+
reject(error);
263+
})
264+
})
265+
}
266+
267+
export const getDownloadURLForFile = (ipAddress, fsInfo, remoteName, remotePath, item) => {
268+
let downloadURL = "";
269+
270+
if (fsInfo.Features.BucketBased) {
271+
downloadURL = ipAddress + `[${remoteName}]/${remotePath}/${item.Name}`;
272+
273+
} else {
274+
275+
downloadURL = ipAddress + `[${remoteName}:${remotePath}]/${item.Name}`;
276+
277+
}
278+
return downloadURL;
279+
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
22
"name": "rclone-api",
3-
"version": "1.0.0",
3+
"version": "1.0.2",
44
"description": "Java Script bindings for rclone rc api",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
9+
"repository": {
10+
"type": "git",
11+
"url": "[email protected]:rclone/rclone-js-api.git"
12+
},
913
"keywords": [],
1014
"author": "rclone",
1115
"license": "ISC",

0 commit comments

Comments
 (0)