8000 Add coreCommand and backendCommand · rclone/rclone-js-api@657a883 · GitHub
[go: up one dir, main page]

Skip to content

Commit 657a883

Browse files
committed
Add coreCommand and backendCommand
1 parent fabce02 commit 657a883

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/endpoint.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,14 @@ const urls = {
117117
*/
118118
stopJob: "job/stop",
119119

120+
/**
121+
* Send a command to backend through rc
122+
*/
123+
backendCommand: "backend/command",
124+
125+
/**
126+
* Executes rclone in a seperate process for output
127+
*/
128+
coreCommand: "core/command",
120129
};
121130
export default urls;

src/index.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ export const cleanTrashForRemote = (fs) => {
272272
})
273273
}
274274

275+
/**
276+
* Get a downloadable url for an rclone object
277+
* @param ipAddress {string} IP address of running rclone instance
278+
* @param fsInfo {object} FsInfo of the remote
279+
* @param remoteName {string} name of the remote
280+
* @param remotePath {string} path of the file. Relative to remoteName
281+
* @param item {string} item details
282+
* @returns {string} url which can be used to download the required file.
283+
*/
275284
export const getDownloadURLForFile = (ipAddress, fsInfo, remoteName, remotePath, item) => {
276285
let downloadURL = "";
277286

@@ -285,3 +294,49 @@ export const getDownloadURLForFile = (ipAddress, fsInfo, remoteName, remotePath,
285294
}
286295
return downloadURL;
287296
}
297+
298+
/**
299+
* Send a backend command and return the result.
300+
* @param command {string} string with the command name
301+
* @param arg {array<string>} remote name string eg "drive:"
302+
* @param opt {$ObjMap} list of arguments for the backend command
303+
* @param fs {string} remote name string eg "drive:"
304+
* @returns {Promise<$ObjMap>}
305+
*/
306+
export const backendCommand = (command, arg, opt, fs) => {
307+
if(!fs) fs = ".";
308+
309+
return new Promise((resolve, reject) => {
310+
if(!command || !arg || !opt) throw new Error(`One or more invalid arguments {${command}},{${arg}} {${opt}} {${fs}}`)
311+
axiosInstance.post(urls.backendCommand, {
312+
command,
313+
arg,
314+
opt,
315+
fs
316+
}).then(res => {
317+
resolve(res.data);
318+
}, error => {
319+
reject(error);
320+
})
321+
});
322+
}
323+
324+
/**
325+
* Send a backend command and return the result.
326+
* @param arg {array<string>} remote name string eg "drive:"
327+
* @param opt {$ObjMap} list of arguments for the backend command
328+
* @returns {Promise<$ObjMap>}
329+
*/
330+
export const coreCommand = ( arg, opt) => {
331+
return new Promise((resolve, reject) => {
332+
if(!arg || !opt) throw new Error(`One or more invalid arguments ,{${arg}} {${opt}}`)
333+
axiosInstance.post(urls.coreCommand, {
334+
arg,
335+
opt,
336+
}).then(res => {
337+
resolve(res.data);
338+
}, error => {
339+
reject(error);
340+
})
341+
});
342+
}

0 commit comments

Comments
 (0)
0